Skip to content

Commit b95bc51

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

File tree

16 files changed

+198
-9
lines changed

16 files changed

+198
-9
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ jobs:
77
contents: read # for actions/checkout
88
security-events: write # for codeql-action
99
uses: ./.github/workflows/ci.yml
10+
secrets:
11+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
1012

1113
dependency-review:
1214
name: Security check of added dependencies

.github/workflows/push.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ jobs:
77
contents: read # for actions/checkout
88
security-events: write
99
uses: ./.github/workflows/ci.yml
10+
secrets:
11+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
1012
deploy-to-npm-branch:
1113
name: Deploy to `npm` branch
1214
needs: ci

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/execution/__tests__/variables-test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const TestFaultyScalarGraphQLError = new GraphQLError(
3232
'FaultyScalarErrorMessage',
3333
{
3434
extensions: {
35-
code: 'FaultyScalarErrorExtensionCode',
35+
code: 'FaultyScalarErrorMessageExtensionCode',
3636
},
3737
},
3838
);
@@ -271,6 +271,27 @@ describe('Execute: Handles inputs', () => {
271271
});
272272
});
273273

274+
it('errors on faulty scalar type input', () => {
275+
const result = executeQuery(`
276+
{
277+
fieldWithObjectInput(input: {c: "foo", e: "bar"})
278+
}
279+
`);
280+
281+
expectJSON(result).toDeepEqual({
282+
data: {
283+
fieldWithObjectInput: null,
284+
},
285+
errors: [
286+
{
287+
message: 'Argument "input" has invalid value {c: "foo", e: "bar"}.',
288+
path: ['fieldWithObjectInput'],
289+
locations: [{ line: 3, column: 39 }],
290+
},
291+
],
292+
});
293+
});
294+
274295
describe('using variables', () => {
275296
const doc = `
276297
query ($input: TestInputObject) {

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 &&
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: 1 addition & 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',

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/parser.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ export interface ParseOptions {
9191
*/
9292
maxTokens?: number | undefined;
9393

94+
/**
95+
* Parser CPU and memory usage is linear to the number of tokens in a document
96+
* however in extreme cases it becomes quadratic due to memory exhaustion.
97+
* Parsing happens before validation so even invalid queries can burn lots of
98+
* CPU time and memory.
99+
* To prevent this you can set a maximum number of tokens allowed within a document.
100+
*/
101+
maxTokens?: number | undefined;
102+
94103
/**
95104
* @deprecated will be removed in the v17.0.0
96105
*

src/language/tokenKind.ts

Lines changed: 1 addition & 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 = '!',

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;

src/validation/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export { VariablesInAllowedPositionRule } from './rules/VariablesInAllowedPositi
9898

9999
export { MaxIntrospectionDepthRule } from './rules/MaxIntrospectionDepthRule.js';
100100

101+
export { MaxIntrospectionDepthRule } from './rules/MaxIntrospectionDepthRule';
102+
101103
// SDL-specific validation rules
102104
export { LoneSchemaDefinitionRule } from './rules/LoneSchemaDefinitionRule.js';
103105
export { UniqueOperationTypesRule } from './rules/UniqueOperationTypesRule.js';
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)