Commit bcb3775 1 parent 111abb4 commit bcb3775 Copy full SHA for bcb3775
File tree 3 files changed +1982
-0
lines changed
3 files changed +1982
-0
lines changed Original file line number Diff line number Diff line change
1
+ const { ApolloServer, gql } = require ( 'apollo-server' ) ;
2
+
3
+ // A schema is a collection of type definitions (hence "typeDefs")
4
+ // that together define the "shape" of queries that are executed against
5
+ // your data.
6
+ const typeDefs = gql `
7
+ # Comments in GraphQL strings (such as this one) start with the hash (#) symbol.
8
+
9
+ # This "Book" type defines the queryable fields for every book in our data source.
10
+ type Book {
11
+ title: String
12
+ author: String
13
+ }
14
+
15
+ # The "Query" type is special: it lists all of the available queries that
16
+ # clients can execute, along with the return type for each. In this
17
+ # case, the "books" query returns an array of zero or more Books (defined above).
18
+ type Query {
19
+ books: [Book]
20
+ }
21
+ ` ;
22
+
23
+ const books = [
24
+ {
25
+ title : 'The Awakening' ,
26
+ author : 'Kate Chopin' ,
27
+ } ,
28
+ {
29
+ title : 'City of Glass' ,
30
+ author : 'Paul Auster' ,
31
+ } ,
32
+ ] ;
33
+
34
+ // Resolvers define the technique for fetching the types defined in the
35
+ // schema. This resolver retrieves books from the "books" array above.
36
+ const resolvers = {
37
+ Query : {
38
+ books : ( ) => books ,
39
+ } ,
40
+ } ;
41
+
42
+ // The ApolloServer constructor requires two parameters: your schema
43
+ // definition and your set of resolvers.
44
+ const server = new ApolloServer ( { typeDefs, resolvers } ) ;
45
+
46
+ // The `listen` method launches a web server.
47
+ server . listen ( ) . then ( ( { url } ) => {
48
+ console . log ( `🚀 Server ready at ${ url } ` ) ;
49
+ } ) ;
You can’t perform that action at this time.
0 commit comments