728x90
apollo graphql server
mkdir graphql-server-example
cd graphql-server-example
npm init --yes
npm install apollo-server graphql
touch index.js
const { ApolloServer, gql } = require('apollo-server');
// A schema is a collection of type definitions (hence "typeDefs")
// that together define the "shape" of queries that are executed against
// your data.
const typeDefs = gql`
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol.
# This "Book" type defines the queryable fields for every book in our data source.
type Book {
title: String
author: String
}
# The "Query" type is special: it lists all of the available queries that
# clients can execute, along with the return type for each. In this
# case, the "books" query returns an array of zero or more Books (defined above).
type Query {
books: [Book]
}
`;
const books = [
{
title: 'The Awakening',
author: 'Kate Chopin',
},
{
title: 'City of Glass',
author: 'Paul Auster',
},
];
// Resolvers define the technique for fetching the types defined in the
// schema. This resolver retrieves books from the "books" array above.
const resolvers = {
Query: {
books: () => books,
},
};
// The ApolloServer constructor requires two parameters: your schema
// definition and your set of resolvers.
const server = new ApolloServer({ typeDefs, resolvers });
// The `listen` method launches a web server.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
node index.js
🚀 Server ready at http://localhost:4000/
https://www.apollographql.com/docs/apollo-server/getting-started
728x90
'푸닥거리' 카테고리의 다른 글
selectSingleNode is not a function (0) | 2022.05.02 |
---|---|
FortiOS - REST API Reference (0) | 2022.04.30 |
Postman Tests documentation (0) | 2022.04.23 |
postman 에서 oauth2인증 후 json 데이타 보내기 (0) | 2022.04.22 |
PBL에서의 기업현장교사 4대 역할 (0) | 2022.04.21 |
댓글