You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/pages/docs/getting-started.mdx
+9-16Lines changed: 9 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ npm install graphql --save
28
28
29
29
## Writing Code
30
30
31
-
To handle GraphQL queries, we need a schema that defines the `Query` type, and we need an API root with a function called a “resolver” for each API endpoint. For an API that just returns “Hello world!”, we can put this code in a file named `server.js`:
31
+
To handle GraphQL queries, we need a schema that defines the `Query` type, and we need an API root with a function called a "resolver" for each API endpoint. For an API that just returns "Hello world!", we can put this code in a file named `server.js`:
32
32
33
33
<Tabsitems={['SDL', 'Code']}>
34
34
<Tabs.Tab>
@@ -54,7 +54,7 @@ graphql({
54
54
console.log(response);
55
55
});
56
56
57
-
````
57
+
```
58
58
</Tabs.Tab>
59
59
<Tabs.Tab>
60
60
```javascript
@@ -65,29 +65,22 @@ const schema = new GraphQLSchema({
65
65
query:newGraphQLObjectType({
66
66
name:'Query',
67
67
fields: {
68
-
hello: { type: GraphQLString },
68
+
hello: {
69
+
type: GraphQLString,
70
+
resolve: () =>'Hello world!'
71
+
},
69
72
},
70
73
}),
71
74
});
72
75
73
-
// The rootValue provides a resolver function for each API endpoint
74
-
const rootValue = {
75
-
hello() {
76
-
return 'Hello world!';
77
-
},
78
-
};
79
-
80
-
// Run the GraphQL query '{ hello }' and print out the response
81
76
graphql({
82
77
schema,
83
78
source:'{ hello }',
84
-
rootValue,
85
79
}).then((response) => {
86
80
console.log(JSON.stringify(response, null, 2));
87
81
});
88
-
````
89
-
90
-
</Tabs.Tab>
82
+
```
83
+
</Tabs.Tab>
91
84
</Tabs>
92
85
93
86
If you run this with:
@@ -108,4 +101,4 @@ You should see the GraphQL response printed out:
108
101
109
102
Congratulations - you just executed a GraphQL query!
110
103
111
-
For practical applications, you'll probably want to run GraphQL queries from an API server, rather than executing GraphQL with a command line tool. To use GraphQL for an API server over HTTP, check out [Running an Express GraphQL Server](./running-an-express-graphql-server).
104
+
For practical applications, you'll probably want to run GraphQL queries from an API server, rather than executing GraphQL with a command line tool. To use GraphQL for an API server over HTTP, check out [Running an Express GraphQL Server](./running-an-express-graphql-server).
0 commit comments