forked from hygraph/hygraph-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (31 loc) · 734 Bytes
/
index.js
File metadata and controls
36 lines (31 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { ApolloServer, gql } = require('apollo-server');
const GraphCMSAPI = require('./datasources/graphcms');
const typeDefs = gql`
type Product {
id: ID!
description: String
name: String!
price: Int!
slug: String!
}
type Query {
products: [Product!]
}
`;
const resolvers = {
Query: {
products: async (parent, args, context) => {
return await context.dataSources.GraphCMS.getProducts();
},
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({ GraphCMS: new GraphCMSAPI() }),
introspection: true,
playground: true,
});
server.listen({ port: process.env.PORT || 4000 }).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});