Skip to content

Commit 58aca55

Browse files
committed
Merge remote-tracking branch 'origin/16.x.x' into backport-16.x.x
2 parents 5c7d4d1 + 9a91e33 commit 58aca55

File tree

11 files changed

+165
-8
lines changed

11 files changed

+165
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![GraphQLConf 2024 Banner: September 10-12, San Francisco. Hosted by the GraphQL Foundation](https://github.com/user-attachments/assets/2d048502-e5b2-4e9d-a02a-50b841824de6)](https://graphql.org/conf/2024/?utm_source=github&utm_medium=graphql_js&utm_campaign=readme)
2+
13
# GraphQL.js
24

35
The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.

cspell.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ overrides:
2020
words:
2121
- clsx
2222
- infima
23+
- noopener
24+
- Vite
25+
- craco
26+
- esbuild
27+
- swcrc
28+
- noreferrer
29+
- xlink
2330

2431
validateDirectives: true
2532
ignoreRegExpList:

src/jsutils/instanceOf.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { inspect } from './inspect.js';
22

3+
/* c8 ignore next 3 */
4+
const isProduction =
5+
globalThis.process != null &&
6+
// eslint-disable-next-line no-undef
7+
process.env.NODE_ENV === 'production';
8+
39
/**
410
* A replacement for instanceof which includes an error warning when multi-realm
511
* constructors are detected.
@@ -9,7 +15,7 @@ import { inspect } from './inspect.js';
915
export const instanceOf: (value: unknown, constructor: Constructor) => boolean =
1016
/* c8 ignore next 6 */
1117
// FIXME: https://github.com/graphql/graphql-js/issues/2317
12-
globalThis.process != null && globalThis.process.env.NODE_ENV === 'production'
18+
isProduction
1319
? function instanceOf(value: unknown, constructor: Constructor): boolean {
1420
return value instanceof constructor;
1521
}

src/language/ast.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,12 @@ export interface OperationDefinitionNode {
343343
readonly selectionSet: SelectionSetNode;
344344
}
345345

346-
export enum OperationTypeNode {
346+
enum OperationTypeNode {
347347
QUERY = 'query',
348348
MUTATION = 'mutation',
349349
SUBSCRIPTION = 'subscription',
350350
}
351+
export { OperationTypeNode };
351352

352353
export interface VariableDefinitionNode {
353354
readonly kind: Kind.VARIABLE_DEFINITION;

src/language/directiveLocation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The set of allowed directive location values.
33
*/
4-
export enum DirectiveLocation {
4+
enum DirectiveLocation {
55
/** Request Definitions */
66
QUERY = 'QUERY',
77
MUTATION = 'MUTATION',
@@ -24,3 +24,5 @@ export enum DirectiveLocation {
2424
INPUT_OBJECT = 'INPUT_OBJECT',
2525
INPUT_FIELD_DEFINITION = 'INPUT_FIELD_DEFINITION',
2626
}
27+
28+
export { DirectiveLocation };

src/language/kinds.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The set of allowed kind values for AST nodes.
33
*/
4-
export enum Kind {
4+
enum Kind {
55
/** Name */
66
NAME = 'Name',
77

@@ -72,3 +72,5 @@ export enum Kind {
7272
ENUM_TYPE_EXTENSION = 'EnumTypeExtension',
7373
INPUT_OBJECT_TYPE_EXTENSION = 'InputObjectTypeExtension',
7474
}
75+
76+
export { Kind };

src/language/tokenKind.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* An exported enum describing the different kinds of tokens that the
33
* lexer emits.
44
*/
5-
export enum TokenKind {
5+
enum TokenKind {
66
SOF = '<SOF>',
77
EOF = '<EOF>',
88
BANG = '!',
@@ -27,3 +27,5 @@ export enum TokenKind {
2727
BLOCK_STRING = 'BlockString',
2828
COMMENT = 'Comment',
2929
}
30+
31+
export { TokenKind };

src/type/introspection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export const __EnumValue: GraphQLObjectType = new GraphQLObjectType({
443443
} as GraphQLFieldConfigMap<GraphQLEnumValue, unknown>),
444444
});
445445

446-
export enum TypeKind {
446+
enum TypeKind {
447447
SCALAR = 'SCALAR',
448448
OBJECT = 'OBJECT',
449449
INTERFACE = 'INTERFACE',
@@ -453,6 +453,7 @@ export enum TypeKind {
453453
LIST = 'LIST',
454454
NON_NULL = 'NON_NULL',
455455
}
456+
export { TypeKind };
456457

457458
export const __TypeKind: GraphQLEnumType = new GraphQLEnumType({
458459
name: '__TypeKind',

src/utilities/findBreakingChanges.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type { GraphQLSchema } from '../type/schema.js';
3434
import { astFromValue } from './astFromValue.js';
3535
import { sortValueNode } from './sortValueNode.js';
3636

37-
export enum BreakingChangeType {
37+
enum BreakingChangeType {
3838
TYPE_REMOVED = 'TYPE_REMOVED',
3939
TYPE_CHANGED_KIND = 'TYPE_CHANGED_KIND',
4040
TYPE_REMOVED_FROM_UNION = 'TYPE_REMOVED_FROM_UNION',
@@ -52,15 +52,17 @@ export enum BreakingChangeType {
5252
DIRECTIVE_REPEATABLE_REMOVED = 'DIRECTIVE_REPEATABLE_REMOVED',
5353
DIRECTIVE_LOCATION_REMOVED = 'DIRECTIVE_LOCATION_REMOVED',
5454
}
55+
export { BreakingChangeType };
5556

56-
export enum DangerousChangeType {
57+
enum DangerousChangeType {
5758
VALUE_ADDED_TO_ENUM = 'VALUE_ADDED_TO_ENUM',
5859
TYPE_ADDED_TO_UNION = 'TYPE_ADDED_TO_UNION',
5960
OPTIONAL_INPUT_FIELD_ADDED = 'OPTIONAL_INPUT_FIELD_ADDED',
6061
OPTIONAL_ARG_ADDED = 'OPTIONAL_ARG_ADDED',
6162
IMPLEMENTED_INTERFACE_ADDED = 'IMPLEMENTED_INTERFACE_ADDED',
6263
ARG_DEFAULT_VALUE_CHANGE = 'ARG_DEFAULT_VALUE_CHANGE',
6364
}
65+
export { DangerousChangeType };
6466

6567
export interface BreakingChange {
6668
type: BreakingChangeType;
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: Going to production
3+
category: FAQ
4+
---
5+
6+
GraphQL.JS contains a few development checks which in production will cause slower performance and
7+
an increase in bundle-size. Every bundler goes about these changes different, in here we'll list
8+
out the most popular ones.
9+
10+
## Bundler-specific configuration
11+
12+
Here are some bundler-specific suggestions for configuring your bundler to remove `globalThis.process` and `process.env.NODE_ENV` on build time.
13+
14+
### Vite
15+
16+
```js
17+
export default defineConfig({
18+
// ...
19+
define: {
20+
'globalThis.process': JSON.stringify(true),
21+
'process.env.NODE_ENV': JSON.stringify('production'),
22+
},
23+
});
24+
```
25+
26+
### Next.js
27+
28+
```js
29+
// ...
30+
/** @type {import('next').NextConfig} */
31+
const nextConfig = {
32+
webpack(config, { webpack }) {
33+
config.plugins.push(
34+
new webpack.DefinePlugin({
35+
'globalThis.process': JSON.stringify(true),
36+
'process.env.NODE_ENV': JSON.stringify('production'),
37+
}),
38+
);
39+
return config;
40+
},
41+
};
42+
43+
module.exports = nextConfig;
44+
```
45+
46+
### create-react-app
47+
48+
With `create-react-app`, you need to use a third-party package like [`craco`](https://craco.js.org/) to modify the bundler configuration.
49+
50+
```js
51+
const webpack = require('webpack');
52+
module.exports = {
53+
webpack: {
54+
plugins: [
55+
new webpack.DefinePlugin({
56+
'globalThis.process': JSON.stringify(true),
57+
'process.env.NODE_ENV': JSON.stringify('production'),
58+
}),
59+
],
60+
},
61+
};
62+
```
63+
64+
### esbuild
65+
66+
```json
67+
{
68+
"define": {
69+
"globalThis.process": true,
70+
"process.env.NODE_ENV": "production"
71+
}
72+
}
73+
```
74+
75+
### Webpack
76+
77+
```js
78+
config.plugins.push(
79+
new webpack.DefinePlugin({
80+
'globalThis.process': JSON.stringify(true),
81+
'process.env.NODE_ENV': JSON.stringify('production'),
82+
}),
83+
);
84+
```
85+
86+
### Rollup
87+
88+
```js
89+
export default [
90+
{
91+
// ... input, output, etc.
92+
plugins: [
93+
minify({
94+
mangle: {
95+
toplevel: true,
96+
},
97+
compress: {
98+
toplevel: true,
99+
global_defs: {
100+
'@globalThis.process': JSON.stringify(true),
101+
'@process.env.NODE_ENV': JSON.stringify('production'),
102+
},
103+
},
104+
}),
105+
],
106+
},
107+
];
108+
```
109+
110+
### SWC
111+
112+
```json title=".swcrc"
113+
{
114+
"jsc": {
115+
"transform": {
116+
"optimizer": {
117+
"globals": {
118+
"vars": {
119+
"globalThis.process": true,
120+
"process.env.NODE_ENV": "production"
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
127+
```

website/sidebars.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ module.exports = {
1515
label: 'Advanced',
1616
items: ['tutorials/constructing-types'],
1717
},
18+
{
19+
type: 'category',
20+
label: 'FAQ',
21+
items: ['tutorials/going-to-production'],
22+
},
1823
'tutorials/express-graphql',
1924
'tutorials/defer-stream',
2025
],

0 commit comments

Comments
 (0)