food-graphql-server/src/index.js

47 lines
1.2 KiB
JavaScript

const { ApolloServer, gql } = require('apollo-server');
const stores = [
{
name: 'Den Olijfboom',
},
{
name: 'Pizza Talia'
}
];
// Type definitions define the "shape" of your data and specify
// which ways the data can be fetched from the GraphQL server.
const typeDefs = gql`
# Comments in GraphQL are defined with the hash (#) symbol.
# This "Store" type can be used in other type declarations.
type Store {
name: String
}
# The "Query" type is the root of all GraphQL queries.
# (A "Mutation" type will be covered later on.)
type Query {
stores: [Store]
}
`;
// Resolvers define the technique for fetching the types in the
// schema. We'll retrieve books from the "books" array above.
const resolvers = {
Query: {
stores: () => stores,
},
};
// In the most basic sense, the ApolloServer can be started
// by passing type definitions (typeDefs) and the resolvers
// responsible for fetching the data for those types.
const server = new ApolloServer({ typeDefs, resolvers });
// This `listen` method launches a web-server. Existing apps
// can utilize middleware options, which we'll discuss later.
server.listen().then(({ url }) => {
console.log(`🚀 Food GraphQL Server ready at ${url}`);
});