Skip to content

Commit aa6736a

Browse files
authored
Fix invalid sample code (#3951)
1 parent 826ae7f commit aa6736a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

website/docs/tutorials/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ npm install graphql --save
1818
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`:
1919

2020
```js
21-
var { graphql, buildSchema } = require('graphql');
21+
let { graphql, buildSchema } = require('graphql');
2222

2323
// Construct a schema, using GraphQL schema language
24-
var schema = buildSchema(`
24+
let schema = buildSchema(`
2525
type Query {
2626
hello: String
2727
}
2828
`);
2929

3030
// The root provides a resolver function for each API endpoint
31-
var root = {
31+
let root = {
3232
hello: () => {
3333
return 'Hello world!';
3434
},
3535
};
3636

3737
// Run the GraphQL query '{ hello }' and print out the response
38-
graphql(schema, '{ hello }', root).then((response) => {
39-
console.log(response);
38+
graphql({ schema, source: '{ hello }', rootValue: root }).then((response) => {
39+
console.log(JSON.stringify(response, null, 2));
4040
});
4141
```
4242

@@ -50,8 +50,8 @@ You should see the GraphQL response printed out:
5050

5151
```js
5252
{
53-
data: {
54-
hello: 'Hello world!';
53+
"data": {
54+
"hello": "Hello world!"
5555
}
5656
}
5757
```

0 commit comments

Comments
 (0)