Skip to content
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

Various fixes to docs #4256

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion website/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AppProps } from 'next/app';
import { Roboto_Flex, Roboto_Mono } from 'next/font/google';

import '../css/globals.css';
console.log('hi');

const robotoFlex = Roboto_Flex({
subsets: ['latin'],
Expand Down
12 changes: 6 additions & 6 deletions website/pages/authentication-and-express-middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ To use middleware with a GraphQL resolver, just use the middleware like you woul
For example, let's say we wanted our server to log the IP address of every request, and we also want to write an API that returns the IP address of the caller. We can do the former with middleware, and the latter by accessing the `request` object in a resolver. Here's server code that implements this:

```js
var express = require('express');
var { createHandler } = require('graphql-http/lib/use/express');
var { buildSchema } = require('graphql');
const express = require('express');
const { createHandler } = require('graphql-http/lib/use/express');
const { buildSchema } = require('graphql');

var schema = buildSchema(`
const schema = buildSchema(`
type Query {
ip: String
}
Expand All @@ -25,13 +25,13 @@ function loggingMiddleware(req, res, next) {
next();
}

var root = {
const root = {
ip(args, context) {
return context.ip;
},
};

var app = express();
const app = express();
app.use(loggingMiddleware);
app.all(
'/graphql',
Expand Down
12 changes: 6 additions & 6 deletions website/pages/basic-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ To use a list type, surround the type in square brackets, so `[Int]` is a list o
Each of these types maps straightforwardly to JavaScript, so you can just return plain old JavaScript objects in APIs that return these types. Here's an example that shows how to use some of these basic types:

```js
var express = require('express');
var { createHandler } = require('graphql-http/lib/use/express');
var { buildSchema } = require('graphql');
const express = require('express');
const { createHandler } = require('graphql-http/lib/use/express');
const { buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
const schema = buildSchema(`
type Query {
quoteOfTheDay: String
random: Float!
Expand All @@ -27,7 +27,7 @@ var schema = buildSchema(`
`);

// The root provides a resolver function for each API endpoint
var root = {
const root = {
quoteOfTheDay() {
return Math.random() < 0.5 ? 'Take it easy' : 'Salvation lies within';
},
Expand All @@ -39,7 +39,7 @@ var root = {
},
};

var app = express();
const app = express();
app.all(
'/graphql',
createHandler({
Expand Down
30 changes: 15 additions & 15 deletions website/pages/constructing-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ When you are using the `GraphQLSchema` constructor to create a schema, instead o
For example, let's say we are building a simple API that lets you fetch user data for a few hardcoded users based on an id. Using `buildSchema` we could write a server with:

```js
var express = require('express');
var { createHandler } = require('graphql-http/lib/use/express');
var { buildSchema } = require('graphql');
const express = require('express');
const { createHandler } = require('graphql-http/lib/use/express');
const { buildSchema } = require('graphql');

var schema = buildSchema(`
const schema = buildSchema(`
type User {
id: String
name: String
Expand All @@ -25,7 +25,7 @@ var schema = buildSchema(`
`);

// Maps id to User object
var fakeDatabase = {
const fakeDatabase = {
a: {
id: 'a',
name: 'alice',
Expand All @@ -36,13 +36,13 @@ var fakeDatabase = {
},
};

var root = {
const root = {
user({ id }) {
return fakeDatabase[id];
},
};

var app = express();
const app = express();
app.all(
'/graphql',
createHandler({
Expand All @@ -57,12 +57,12 @@ console.log('Running a GraphQL API server at localhost:4000/graphql');
We can implement this same API without using GraphQL schema language:

```js
var express = require('express');
var { createHandler } = require('graphql-http/lib/use/express');
var graphql = require('graphql');
const express = require('express');
const { createHandler } = require('graphql-http/lib/use/express');
const graphql = require('graphql');

// Maps id to User object
var fakeDatabase = {
const fakeDatabase = {
a: {
id: 'a',
name: 'alice',
Expand All @@ -74,7 +74,7 @@ var fakeDatabase = {
};

// Define the User type
var userType = new graphql.GraphQLObjectType({
const userType = new graphql.GraphQLObjectType({
name: 'User',
fields: {
id: { type: graphql.GraphQLString },
Expand All @@ -83,7 +83,7 @@ var userType = new graphql.GraphQLObjectType({
});

// Define the Query type
var queryType = new graphql.GraphQLObjectType({
const queryType = new graphql.GraphQLObjectType({
name: 'Query',
fields: {
user: {
Expand All @@ -99,9 +99,9 @@ var queryType = new graphql.GraphQLObjectType({
},
});

var schema = new graphql.GraphQLSchema({ query: queryType });
const schema = new graphql.GraphQLSchema({ query: queryType });

var app = express();
const app = express();
app.all(
'/graphql',
createHandler({
Expand Down
2 changes: 1 addition & 1 deletion website/pages/error.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GraphQL errors. You can import either from the `graphql/error` module, or from t

```js
import { GraphQLError } from 'graphql'; // ES6
var { GraphQLError } = require('graphql'); // CommonJS
const { GraphQLError } = require('graphql'); // CommonJS
```

## Overview
Expand Down
2 changes: 1 addition & 1 deletion website/pages/execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fulfilling a GraphQL request. You can import either from the `graphql/execution`

```js
import { execute } from 'graphql'; // ES6
var { execute } = require('graphql'); // CommonJS
const { execute } = require('graphql'); // CommonJS
```

## Overview
Expand Down
2 changes: 1 addition & 1 deletion website/pages/going-to-production.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Enabling Defer & Stream
title: Going to Production
---

The `@defer` and `@stream` directives are not enabled by default. In order to use these directives, you must add them to your GraphQL Schema and use the `experimentalExecuteIncrementally` function instead of `execute`.
Expand Down
12 changes: 6 additions & 6 deletions website/pages/graphql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ of GraphQL type systems and servers.

```js
import { graphql } from 'graphql'; // ES6
var { graphql } = require('graphql'); // CommonJS
const { graphql } = require('graphql'); // CommonJS
```

## Overview
Expand Down Expand Up @@ -95,27 +95,27 @@ var { graphql } = require('graphql'); // CommonJS
<ul className="apiIndex">
<li>
<a href="../type/#graphqlint">
`var GraphQLInt` A scalar type representing integers.
`const GraphQLInt` A scalar type representing integers.
</a>
</li>
<li>
<a href="../type/#graphqlfloat">
`var GraphQLFloat` A scalar type representing floats.
`const GraphQLFloat` A scalar type representing floats.
</a>
</li>
<li>
<a href="../type/#graphqlstring">
`var GraphQLString` A scalar type representing strings.
`const GraphQLString` A scalar type representing strings.
</a>
</li>
<li>
<a href="../type/#graphqlboolean">
`var GraphQLBoolean` A scalar type representing booleans.
`const GraphQLBoolean` A scalar type representing booleans.
</a>
</li>
<li>
<a href="../type/#graphqlid">
`var GraphQLID` A scalar type representing IDs.
`const GraphQLID` A scalar type representing IDs.
</a>
</li>
</ul>
Expand Down
8 changes: 4 additions & 4 deletions website/pages/language.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `graphql/language` module is responsible for parsing and operating on the Gr

```js
import { Source } from 'graphql'; // ES6
var { Source } = require('graphql'); // CommonJS
const { Source } = require('graphql'); // CommonJS
```

## Overview
Expand Down Expand Up @@ -56,7 +56,7 @@ var { Source } = require('graphql'); // CommonJS
</li>
<li>
<a href="#kind">
`var Kind` Represents the various kinds of parsed AST nodes.
`const Kind` Represents the various kinds of parsed AST nodes.
</a>
</li>
</ul>
Expand All @@ -72,7 +72,7 @@ var { Source } = require('graphql'); // CommonJS
</li>
<li>
<a href="#break">
`var BREAK` A token to allow breaking out of the visitor.
`const BREAK` A token to allow breaking out of the visitor.
</a>
</li>
</ul>
Expand Down Expand Up @@ -198,7 +198,7 @@ a new version of the AST with the changes applied will be returned from the
visit function.

```js
var editedAST = visit(ast, {
const editedAST = visit(ast, {
enter(node, key, parent, path, ancestors) {
// @return
// undefined: no action
Expand Down
26 changes: 13 additions & 13 deletions website/pages/mutations-and-input-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ It's often convenient to have a mutation that maps to a database create or updat
Both mutations and queries can be handled by root resolvers, so the root that implements this schema can simply be:

```js
var fakeDatabase = {};
var root = {
const fakeDatabase = {};
const root = {
setMessage({ message }) {
fakeDatabase.message = message;
return message;
Expand Down Expand Up @@ -68,12 +68,12 @@ Naming input types with `Input` on the end is a useful convention, because you w
Here's some runnable code that implements this schema, keeping the data in memory:

```js
var express = require('express');
var { createHandler } = require('graphql-http/lib/use/express');
var { buildSchema } = require('graphql');
const express = require('express');
const { createHandler } = require('graphql-http/lib/use/express');
const { buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(/* GraphQL */ `
const schema = buildSchema(/* GraphQL */ `
input MessageInput {
content: String
author: String
Expand Down Expand Up @@ -105,9 +105,9 @@ class Message {
}

// Maps username to content
var fakeDatabase = {};
const fakeDatabase = {};

var root = {
const root = {
getMessage({ id }) {
if (!fakeDatabase[id]) {
throw new Error('no message exists with id ' + id);
Expand All @@ -116,7 +116,7 @@ var root = {
},
createMessage({ input }) {
// Create a random id for our "database".
var id = require('crypto').randomBytes(10).toString('hex');
const id = require('crypto').randomBytes(10).toString('hex');

fakeDatabase[id] = input;
return new Message(id, input);
Expand All @@ -131,7 +131,7 @@ var root = {
},
};

var app = express();
const app = express();
app.all(
'/graphql',
createHandler({
Expand All @@ -157,9 +157,9 @@ mutation {
You can use variables to simplify mutation client logic just like you can with queries. For example, some JavaScript code that calls the server to execute this mutation is:

```js
var author = 'andy';
var content = 'hope is a good thing';
var query = /* GraphQL */ `
const author = 'andy';
const content = 'hope is a good thing';
const query = /* GraphQL */ `
mutation CreateMessage($input: MessageInput) {
createMessage(input: $input) {
id
Expand Down
22 changes: 11 additions & 11 deletions website/pages/object-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class RandomDie {
}

roll({ numRolls }) {
var output = [];
for (var i = 0; i < numRolls; i++) {
const output = [];
for (const i = 0; i < numRolls; i++) {
output.push(this.rollOnce());
}
return output;
}
}

var root = {
const root = {
getDie({ numSides }) {
return new RandomDie(numSides || 6);
},
Expand All @@ -69,12 +69,12 @@ type Query {
Putting this all together, here is some sample code that runs a server with this GraphQL API:

```js
var express = require('express');
var { createHandler } = require('graphql-http/lib/use/express');
var { buildSchema } = require('graphql');
const express = require('express');
const { createHandler } = require('graphql-http/lib/use/express');
const { buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(/* GraphQL */ `
const schema = buildSchema(/* GraphQL */ `
type RandomDie {
numSides: Int!
rollOnce: Int!
Expand All @@ -97,22 +97,22 @@ class RandomDie {
}

roll({ numRolls }) {
var output = [];
for (var i = 0; i < numRolls; i++) {
const output = [];
for (const i = 0; i < numRolls; i++) {
output.push(this.rollOnce());
}
return output;
}
}

// The root provides the top-level API endpoints
var root = {
const root = {
getDie({ numSides }) {
return new RandomDie(numSides || 6);
},
};

var app = express();
const app = express();
app.all(
'/graphql',
createHandler({
Expand Down
Loading
Loading