Skip to content

Commit dd53d99

Browse files
authored
Remove CJS from docs (#4400)
1 parent 3f5858b commit dd53d99

21 files changed

+107
-115
lines changed

website/pages/api-v16/error.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ The `graphql/error` module is responsible for creating and formatting
1010
GraphQL errors. You can import either from the `graphql/error` module, or from the root `graphql` module. For example:
1111

1212
```js
13-
import { GraphQLError } from 'graphql'; // ES6
14-
const { GraphQLError } = require('graphql'); // CommonJS
13+
import { GraphQLError } from 'graphql';
1514
```
1615

1716
## Overview

website/pages/api-v16/execution.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ The `graphql/execution` module is responsible for the execution phase of
1010
fulfilling a GraphQL request. You can import either from the `graphql/execution` module, or from the root `graphql` module. For example:
1111

1212
```js
13-
import { execute } from 'graphql'; // ES6
14-
const { execute } = require('graphql'); // CommonJS
13+
import { execute } from 'graphql';
1514
```
1615

1716
## Overview

website/pages/api-v16/graphql-http.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ The [official `graphql-http` package](https://github.com/graphql/graphql-http) p
1111
## Express
1212

1313
```js
14-
import { createHandler } from 'graphql-http/lib/use/express'; // ES6
15-
const { createHandler } = require('graphql-http/lib/use/express'); // CommonJS
14+
import { createHandler } from 'graphql-http/lib/use/express';
1615
```
1716

1817
### createHandler

website/pages/api-v16/graphql.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ The `graphql` module exports a core subset of GraphQL functionality for creation
1010
of GraphQL type systems and servers.
1111

1212
```js
13-
import { graphql } from 'graphql'; // ES6
14-
const { graphql } = require('graphql'); // CommonJS
13+
import { graphql } from 'graphql';
1514
```
1615

1716
## Overview

website/pages/api-v16/language.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ title: graphql/language
99
The `graphql/language` module is responsible for parsing and operating on the GraphQL language. You can import either from the `graphql/language` module, or from the root `graphql` module. For example:
1010

1111
```js
12-
import { Source } from 'graphql'; // ES6
13-
const { Source } = require('graphql'); // CommonJS
12+
import { Source } from 'graphql';
1413
```
1514

1615
## Overview

website/pages/api-v16/type.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ title: graphql/type
99
The `graphql/type` module is responsible for defining GraphQL types and schema. You can import either from the `graphql/type` module, or from the root `graphql` module. For example:
1010

1111
```js
12-
import { GraphQLSchema } from 'graphql'; // ES6
13-
const { GraphQLSchema } = require('graphql'); // CommonJS
12+
import { GraphQLSchema } from 'graphql';
1413
```
1514

1615
## Overview

website/pages/api-v16/utilities.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ The `graphql/utilities` module contains common useful computations to use with
1010
the GraphQL language and type objects. You can import either from the `graphql/utilities` module, or from the root `graphql` module. For example:
1111

1212
```js
13-
import { introspectionQuery } from 'graphql'; // ES6
14-
const { introspectionQuery } = require('graphql'); // CommonJS
13+
import { introspectionQuery } from 'graphql';
1514
```
1615

1716
## Overview

website/pages/api-v16/validation.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ The `graphql/validation` module fulfills the Validation phase of fulfilling a
1010
GraphQL result. You can import either from the `graphql/validation` module, or from the root `graphql` module. For example:
1111

1212
```js
13-
import { validate } from 'graphql/validation'; // ES6
14-
const { validate } = require('graphql/validation'); // CommonJS
13+
import { validate } from 'graphql/validation';
1514
```
1615

1716
## Overview

website/pages/docs/abstract-types.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ concrete type a given value corresponds to.
3636
The following example defines a `ContentItem` interface for a publishing platform:
3737

3838
```js
39-
const { GraphQLInterfaceType, GraphQLString, GraphQLNonNull } = require('graphql');
39+
import { GraphQLInterfaceType, GraphQLString, GraphQLNonNull } from 'graphql';
4040

4141
const ContentItemInterface = new GraphQLInterfaceType({
4242
name: 'ContentItem',
@@ -69,7 +69,7 @@ The following example implements the `Article` and `PodcastEpisode` types that
6969
conform to the `ContentItem` interface:
7070

7171
```js
72-
const { GraphQLObjectType, GraphQLString, GraphQLNonNull } = require('graphql');
72+
import { GraphQLObjectType, GraphQLString, GraphQLNonNull } from 'graphql';
7373

7474
const ArticleType = new GraphQLObjectType({
7575
name: 'Article',
@@ -114,7 +114,7 @@ A union requires:
114114
The following example defines a `SearchResult` union:
115115

116116
```js
117-
const { GraphQLUnionType } = require('graphql');
117+
import { GraphQLUnionType } from 'graphql';
118118

119119
const SearchResultType = new GraphQLUnionType({
120120
name: 'SearchResult',
@@ -134,7 +134,7 @@ const SearchResultType = new GraphQLUnionType({
134134
});
135135
```
136136

137-
Unlike interfaces, unions dont declare any fields of their own. Clients use inline fragments
137+
Unlike interfaces, unions don't declare any fields of their own. Clients use inline fragments
138138
to query fields from the concrete types.
139139

140140
## Resolving abstract types at runtime

website/pages/docs/advanced-custom-scalars.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ schema, follow these best practices.
99

1010
### Document expected formats and validation
1111

12-
Provide a clear description of the scalars accepted input and output formats. For example, a
12+
Provide a clear description of the scalar's accepted input and output formats. For example, a
1313
`DateTime` scalar should explain that it expects [ISO-8601](https://www.iso.org/iso-8601-date-and-time-format.html) strings ending with `Z`.
1414

1515
Clear descriptions help clients understand valid input and reduce mistakes.
@@ -100,8 +100,8 @@ describe('DateTime scalar', () => {
100100
Integrate the scalar into a schema and run real GraphQL queries to validate end-to-end behavior.
101101

102102
```js
103-
const { graphql, GraphQLSchema, GraphQLObjectType } = require('graphql');
104-
const { DateTimeResolver as DateTime } = require('graphql-scalars');
103+
import { graphql, GraphQLSchema, GraphQLObjectType } from 'graphql';
104+
import { DateTimeResolver as DateTime } from 'graphql-scalars';
105105

106106
const Query = new GraphQLObjectType({
107107
name: 'Query',
@@ -184,13 +184,13 @@ scalars for DateTime, EmailAddress, URL, UUID, and many others.
184184
### Example: Handling email validation
185185

186186
Handling email validation correctly requires dealing with Unicode, quoted local parts, and
187-
domain validation. Rather than writing your own regex, its better to use a library scalar
187+
domain validation. Rather than writing your own regex, it's better to use a library scalar
188188
that's already validated against standards.
189189

190190
If you need domain-specific behavior, you can wrap an existing scalar with custom rules:
191191

192192
```js
193-
const { EmailAddressResolver } = require('graphql-scalars');
193+
import { EmailAddressResolver } from 'graphql-scalars';
194194

195195
const StrictEmailAddress = new GraphQLScalarType({
196196
...EmailAddressResolver,

website/pages/docs/authentication-and-express-middleware.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ For example, let's say we wanted our server to log the IP address of every reque
1414
<Tabs items={['SDL', 'Code']}>
1515
<Tabs.Tab>
1616
```js
17-
const express = require('express');
18-
const { createHandler } = require('graphql-http/lib/use/express');
19-
const { buildSchema } = require('graphql');
17+
import express from 'express';
18+
import { createHandler } from 'graphql-http/lib/use/express';
19+
import { buildSchema } from 'graphql';
2020

2121
const schema = buildSchema(`type Query { ip: String }`);
2222

@@ -46,17 +46,17 @@ app.all(
4646
app.listen(4000);
4747
console.log('Running a GraphQL API server at localhost:4000/graphql');
4848

49-
````
49+
```
5050
</Tabs.Tab>
5151
<Tabs.Tab>
5252
```js
53-
const express = require('express');
54-
const { createHandler } = require('graphql-http/lib/use/express');
55-
const {
53+
import express from 'express';
54+
import { createHandler } from 'graphql-http/lib/use/express';
55+
import {
5656
GraphQLObjectType,
5757
GraphQLSchema,
5858
GraphQLString,
59-
} = require('graphql');
59+
} from 'graphql';
6060

6161
const schema = new GraphQLSchema({
6262
query: new GraphQLObjectType({

website/pages/docs/basic-types.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Each of these types maps straightforwardly to JavaScript, so you can just return
1717
<Tabs items={['SDL', 'Code']}>
1818
<Tabs.Tab>
1919
```js
20-
const express = require('express');
21-
const { createHandler } = require('graphql-http/lib/use/express');
22-
const { buildSchema } = require('graphql');
20+
import express from 'express';
21+
import { createHandler } from 'graphql-http/lib/use/express';
22+
import { buildSchema } from 'graphql';
2323

2424
// Construct a schema, using GraphQL schema language
2525
const schema = buildSchema(`
@@ -54,19 +54,19 @@ app.all(
5454
app.listen(4000);
5555
console.log('Running a GraphQL API server at localhost:4000/graphql');
5656

57-
````
57+
```
5858
</Tabs.Tab>
5959
<Tabs.Tab>
6060
```js
61-
const express = require('express');
62-
const { createHandler } = require('graphql-http/lib/use/express');
63-
const {
61+
import express from 'express';
62+
import { createHandler } from 'graphql-http/lib/use/express';
63+
import {
6464
GraphQLObjectType,
6565
GraphQLSchema,
6666
GraphQLString,
6767
GraphQLFloat,
6868
GraphQLList,
69-
} = require('graphql');
69+
} from 'graphql';
7070

7171
// Construct a schema
7272
const schema = new GraphQLSchema({
@@ -99,8 +99,8 @@ app.all(
9999

100100
app.listen(4000);
101101
console.log('Running a GraphQL API server at localhost:4000/graphql');
102-
````
103102

103+
```
104104
</Tabs.Tab>
105105
</Tabs>
106106

website/pages/docs/constructing-types.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ For example, let's say we are building a simple API that lets you fetch user dat
1313
<Tabs items={['SDL', 'Code']}>
1414
<Tabs.Tab>
1515
```js
16-
const express = require('express');
17-
const { createHandler } = require('graphql-http/lib/use/express');
18-
const { buildSchema } = require('graphql');
16+
import express from 'express';
17+
import { createHandler } from 'graphql-http/lib/use/express';
18+
import { buildSchema } from 'graphql';
1919

2020
const schema = buildSchema(`
2121
type User {
@@ -61,9 +61,9 @@ console.log('Running a GraphQL API server at localhost:4000/graphql');
6161
</Tabs.Tab>
6262
<Tabs.Tab>
6363
```js
64-
const express = require('express');
65-
const { createHandler } = require('graphql-http/lib/use/express');
66-
const graphql = require('graphql');
64+
import express from 'express';
65+
import { createHandler } from 'graphql-http/lib/use/express';
66+
import * as graphql from 'graphql';
6767
6868
// Maps id to User object
6969
const fakeDatabase = {

website/pages/docs/cursor-based-pagination.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ The following example shows how to paginate a list of users using PostgreSQL and
237237
client like `pg`:
238238

239239
```js
240-
const db = require('./db');
240+
import db from './db';
241241

242242
async function resolveUsers(_, args) {
243243
const limit = args.first ?? 10;

website/pages/docs/custom-scalars.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ full control over how values are serialized, parsed, and validated.
1919
Here’s a simple example of a custom scalar that handles date-time strings:
2020

2121
```js
22-
const { GraphQLScalarType, Kind } = require('graphql');
22+
import { GraphQLScalarType, Kind } from 'graphql';
2323

2424
const DateTime = new GraphQLScalarType({
2525
name: 'DateTime',
@@ -89,7 +89,7 @@ The following example is a custom `DateTime` scalar that handles ISO-8601 encode
8989
date strings:
9090

9191
```js
92-
const { GraphQLScalarType, Kind } = require('graphql');
92+
import { GraphQLScalarType, Kind } from 'graphql';
9393

9494
const DateTime = new GraphQLScalarType({
9595
name: 'DateTime',

website/pages/docs/getting-started.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { Tabs } from 'nextra/components';
1111

1212
## Prerequisites
1313

14-
Before getting started, you should have Node v6 installed, although the examples should mostly work in previous versions of Node as well.
14+
Before getting started, you should have at least Node 20 installed, the examples can be tweaked to work with Node versions
15+
before that by switching to require syntax.
1516
For this guide, we won't use any language features that require transpilation, but we will use some ES6 features like
1617
[Promises](http://web.dev/articles/promises/), classes,
1718
and arrow functions, so if you aren't familiar with them you might want to read up on them first.
@@ -33,7 +34,7 @@ To handle GraphQL queries, we need a schema that defines the `Query` type, and w
3334
<Tabs items={['SDL', 'Code']}>
3435
<Tabs.Tab>
3536
```javascript
36-
const { graphql, buildSchema } = require('graphql');
37+
import { graphql, buildSchema } from 'graphql';
3738

3839
// Construct a schema, using GraphQL schema language
3940
const schema = buildSchema(`type Query { hello: String } `);
@@ -58,7 +59,7 @@ graphql({
5859
</Tabs.Tab>
5960
<Tabs.Tab>
6061
```javascript
61-
const { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');
62+
import { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql';
6263

6364
// Construct a schema
6465
const schema = new GraphQLSchema({

website/pages/docs/going-to-production.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default defineConfig({
2525
### Next.js
2626

2727
```js
28-
// ...
2928
/** @type {import('next').NextConfig} */
3029
const nextConfig = {
3130
webpack(config, { webpack }) {
@@ -39,16 +38,16 @@ const nextConfig = {
3938
},
4039
};
4140

42-
module.exports = nextConfig;
41+
export default nextConfig;
4342
```
4443

4544
### create-react-app
4645

4746
With `create-react-app`, you need to use a third-party package like [`craco`](https://craco.js.org/) to modify the bundler configuration.
4847

4948
```js
50-
const webpack = require('webpack');
51-
module.exports = {
49+
import webpack from 'webpack';
50+
export default {
5251
webpack: {
5352
plugins: [
5453
new webpack.DefinePlugin({

0 commit comments

Comments
 (0)