Skip to content

Fix invalid sample code #3951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions website/docs/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ npm install graphql --save
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`:

```js
var { graphql, buildSchema } = require('graphql');
let { graphql, buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
let schema = buildSchema(`
type Query {
hello: String
}
`);

// The root provides a resolver function for each API endpoint
var root = {
let root = {
hello: () => {
return 'Hello world!';
},
};

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

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

```js
{
data: {
hello: 'Hello world!';
"data": {
"hello": "Hello world!"
}
}
```
Expand Down