Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/16.x.x' into backport-16.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Aug 15, 2024
2 parents 5c7d4d1 + 9a91e33 commit b95bc51
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
contents: read # for actions/checkout
security-events: write # for codeql-action
uses: ./.github/workflows/ci.yml
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}

dependency-review:
name: Security check of added dependencies
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
contents: read # for actions/checkout
security-events: write
uses: ./.github/workflows/ci.yml
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
deploy-to-npm-branch:
name: Deploy to `npm` branch
needs: ci
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![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)

# GraphQL.js

The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.
Expand Down
7 changes: 7 additions & 0 deletions cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ overrides:
words:
- clsx
- infima
- noopener
- Vite
- craco
- esbuild
- swcrc
- noreferrer
- xlink

validateDirectives: true
ignoreRegExpList:
Expand Down
23 changes: 22 additions & 1 deletion src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TestFaultyScalarGraphQLError = new GraphQLError(
'FaultyScalarErrorMessage',
{
extensions: {
code: 'FaultyScalarErrorExtensionCode',
code: 'FaultyScalarErrorMessageExtensionCode',
},
},
);
Expand Down Expand Up @@ -271,6 +271,27 @@ describe('Execute: Handles inputs', () => {
});
});

it('errors on faulty scalar type input', () => {
const result = executeQuery(`
{
fieldWithObjectInput(input: {c: "foo", e: "bar"})
}
`);

expectJSON(result).toDeepEqual({
data: {
fieldWithObjectInput: null,
},
errors: [
{
message: 'Argument "input" has invalid value {c: "foo", e: "bar"}.',
path: ['fieldWithObjectInput'],
locations: [{ line: 3, column: 39 }],
},
],
});
});

describe('using variables', () => {
const doc = `
query ($input: TestInputObject) {
Expand Down
8 changes: 7 additions & 1 deletion src/jsutils/instanceOf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { inspect } from './inspect.js';

/* c8 ignore next 3 */
const isProduction =
globalThis.process &&
// eslint-disable-next-line no-undef
process.env.NODE_ENV === 'production';

/**
* A replacement for instanceof which includes an error warning when multi-realm
* constructors are detected.
Expand All @@ -9,7 +15,7 @@ import { inspect } from './inspect.js';
export const instanceOf: (value: unknown, constructor: Constructor) => boolean =
/* c8 ignore next 6 */
// FIXME: https://github.com/graphql/graphql-js/issues/2317
globalThis.process != null && globalThis.process.env.NODE_ENV === 'production'
isProduction
? function instanceOf(value: unknown, constructor: Constructor): boolean {
return value instanceof constructor;
}
Expand Down
3 changes: 2 additions & 1 deletion src/language/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,12 @@ export interface OperationDefinitionNode {
readonly selectionSet: SelectionSetNode;
}

export enum OperationTypeNode {
enum OperationTypeNode {
QUERY = 'query',
MUTATION = 'mutation',
SUBSCRIPTION = 'subscription',
}
export { OperationTypeNode };

export interface VariableDefinitionNode {
readonly kind: Kind.VARIABLE_DEFINITION;
Expand Down
2 changes: 1 addition & 1 deletion src/language/directiveLocation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* The set of allowed directive location values.
*/
export enum DirectiveLocation {
enum DirectiveLocation {
/** Request Definitions */
QUERY = 'QUERY',
MUTATION = 'MUTATION',
Expand Down
4 changes: 3 additions & 1 deletion src/language/kinds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* The set of allowed kind values for AST nodes.
*/
export enum Kind {
enum Kind {
/** Name */
NAME = 'Name',

Expand Down Expand Up @@ -72,3 +72,5 @@ export enum Kind {
ENUM_TYPE_EXTENSION = 'EnumTypeExtension',
INPUT_OBJECT_TYPE_EXTENSION = 'InputObjectTypeExtension',
}

export { Kind };
9 changes: 9 additions & 0 deletions src/language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ export interface ParseOptions {
*/
maxTokens?: number | undefined;

/**
* Parser CPU and memory usage is linear to the number of tokens in a document
* however in extreme cases it becomes quadratic due to memory exhaustion.
* Parsing happens before validation so even invalid queries can burn lots of
* CPU time and memory.
* To prevent this you can set a maximum number of tokens allowed within a document.
*/
maxTokens?: number | undefined;

/**
* @deprecated will be removed in the v17.0.0
*
Expand Down
2 changes: 1 addition & 1 deletion src/language/tokenKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* An exported enum describing the different kinds of tokens that the
* lexer emits.
*/
export enum TokenKind {
enum TokenKind {
SOF = '<SOF>',
EOF = '<EOF>',
BANG = '!',
Expand Down
3 changes: 2 additions & 1 deletion src/type/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export const __EnumValue: GraphQLObjectType = new GraphQLObjectType({
} as GraphQLFieldConfigMap<GraphQLEnumValue, unknown>),
});

export enum TypeKind {
enum TypeKind {
SCALAR = 'SCALAR',
OBJECT = 'OBJECT',
INTERFACE = 'INTERFACE',
Expand All @@ -453,6 +453,7 @@ export enum TypeKind {
LIST = 'LIST',
NON_NULL = 'NON_NULL',
}
export { TypeKind };

export const __TypeKind: GraphQLEnumType = new GraphQLEnumType({
name: '__TypeKind',
Expand Down
6 changes: 4 additions & 2 deletions src/utilities/findBreakingChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type { GraphQLSchema } from '../type/schema.js';
import { astFromValue } from './astFromValue.js';
import { sortValueNode } from './sortValueNode.js';

export enum BreakingChangeType {
enum BreakingChangeType {
TYPE_REMOVED = 'TYPE_REMOVED',
TYPE_CHANGED_KIND = 'TYPE_CHANGED_KIND',
TYPE_REMOVED_FROM_UNION = 'TYPE_REMOVED_FROM_UNION',
Expand All @@ -52,15 +52,17 @@ export enum BreakingChangeType {
DIRECTIVE_REPEATABLE_REMOVED = 'DIRECTIVE_REPEATABLE_REMOVED',
DIRECTIVE_LOCATION_REMOVED = 'DIRECTIVE_LOCATION_REMOVED',
}
export { BreakingChangeType };

export enum DangerousChangeType {
enum DangerousChangeType {
VALUE_ADDED_TO_ENUM = 'VALUE_ADDED_TO_ENUM',
TYPE_ADDED_TO_UNION = 'TYPE_ADDED_TO_UNION',
OPTIONAL_INPUT_FIELD_ADDED = 'OPTIONAL_INPUT_FIELD_ADDED',
OPTIONAL_ARG_ADDED = 'OPTIONAL_ARG_ADDED',
IMPLEMENTED_INTERFACE_ADDED = 'IMPLEMENTED_INTERFACE_ADDED',
ARG_DEFAULT_VALUE_CHANGE = 'ARG_DEFAULT_VALUE_CHANGE',
}
export { DangerousChangeType };

export interface BreakingChange {
type: BreakingChangeType;
Expand Down
2 changes: 2 additions & 0 deletions src/validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export { VariablesInAllowedPositionRule } from './rules/VariablesInAllowedPositi

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

export { MaxIntrospectionDepthRule } from './rules/MaxIntrospectionDepthRule';

// SDL-specific validation rules
export { LoneSchemaDefinitionRule } from './rules/LoneSchemaDefinitionRule.js';
export { UniqueOperationTypesRule } from './rules/UniqueOperationTypesRule.js';
Expand Down
127 changes: 127 additions & 0 deletions website/docs/tutorials/going-to-production.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
title: Going to production
category: FAQ
---

GraphQL.JS contains a few development checks which in production will cause slower performance and
an increase in bundle-size. Every bundler goes about these changes different, in here we'll list
out the most popular ones.

## Bundler-specific configuration

Here are some bundler-specific suggestions for configuring your bundler to remove `globalThis.process` and `process.env.NODE_ENV` on build time.

### Vite

```js
export default defineConfig({
// ...
define: {
'globalThis.process': JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify('production'),
},
});
```

### Next.js

```js
// ...
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack(config, { webpack }) {
config.plugins.push(
new webpack.DefinePlugin({
'globalThis.process': JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify('production'),
}),
);
return config;
},
};

module.exports = nextConfig;
```

### create-react-app

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

```js
const webpack = require('webpack');
module.exports = {
webpack: {
plugins: [
new webpack.DefinePlugin({
'globalThis.process': JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
},
};
```

### esbuild

```json
{
"define": {
"globalThis.process": true,
"process.env.NODE_ENV": "production"
}
}
```

### Webpack

```js
config.plugins.push(
new webpack.DefinePlugin({
'globalThis.process': JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify('production'),
}),
);
```

### Rollup

```js
export default [
{
// ... input, output, etc.
plugins: [
minify({
mangle: {
toplevel: true,
},
compress: {
toplevel: true,
global_defs: {
'@globalThis.process': JSON.stringify(true),
'@process.env.NODE_ENV': JSON.stringify('production'),
},
},
}),
],
},
];
```

### SWC

```json title=".swcrc"
{
"jsc": {
"transform": {
"optimizer": {
"globals": {
"vars": {
"globalThis.process": true,
"process.env.NODE_ENV": "production"
}
}
}
}
}
}
```
5 changes: 5 additions & 0 deletions website/sidebars.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ module.exports = {
label: 'Advanced',
items: ['tutorials/constructing-types'],
},
{
type: 'category',
label: 'FAQ',
items: ['tutorials/going-to-production'],
},
'tutorials/express-graphql',
'tutorials/defer-stream',
],
Expand Down

0 comments on commit b95bc51

Please sign in to comment.