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

Upgrade GraphQL to 16.9.0 #2142

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion grafast/bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"grafast": "workspace:^",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"tslib": "^2.6.2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion grafast/dataplan-pg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"glob": "^10.3.4",
"grafserv": "workspace:*",
"graphile-export": "workspace:*",
"graphql": "16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"iterall": "^1.3.0",
"jest": "^29.6.4",
"jest-serializer-simple": "workspace:^",
Expand Down
1 change: 1 addition & 0 deletions grafast/dataplan-pg/src/examples/exampleSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5262,6 +5262,7 @@ export function makeExampleSchema(
],
},
},
// @ts-ignore
enableDeferStream: true,
});
}
Expand Down
6 changes: 3 additions & 3 deletions grafast/grafast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@
"chalk": "^4.1.2",
"debug": "^4.3.4",
"eventemitter3": "^5.0.1",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"iterall": "^1.3.0",
"tamedevil": "workspace:^",
"tslib": "^2.6.2"
},
"peerDependencies": {
"@envelop/core": "^5.0.0",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"tamedevil": "workspace:^"
},
"peerDependenciesMeta": {
Expand All @@ -99,7 +99,7 @@
"@types/node": "^20.5.7",
"@types/nodemon": "1.19.2",
"chai": "^4.3.8",
"graphql": "16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"jest": "^29.6.4",
"lodash": "^4.17.21",
"mermaid": "^9.4.3",
Expand Down
83 changes: 83 additions & 0 deletions grafast/grafast/src/incremental.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
DirectiveLocation,
GraphQLBoolean,
GraphQLDirective,
GraphQLInt,
GraphQLString,
} from "graphql";

// This file contains the Stream/Defer directives, to be used when GraphQL itself doesn't provide them.

// Taken from https://github.com/graphql/graphql-js/blob/bc6b2e47512ee11c01eb5185d184990e743df736/src/type/directives.ts

/*
MIT License

Copyright (c) GraphQL Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/**
* Used to conditionally defer fragments.
*/
export const GraphQLDeferDirective = new GraphQLDirective({
name: "defer",
description:
"Directs the executor to defer this fragment when the `if` argument is true or undefined.",
locations: [
DirectiveLocation.FRAGMENT_SPREAD,
DirectiveLocation.INLINE_FRAGMENT,
],
args: {
if: {
type: GraphQLBoolean,
description: "Deferred when true or undefined.",
},
label: {
type: GraphQLString,
description: "Unique name",
},
},
});

/**
* Used to conditionally stream list fields.
*/
export const GraphQLStreamDirective = new GraphQLDirective({
name: "stream",
description:
"Directs the executor to stream plural fields when the `if` argument is true or undefined.",
locations: [DirectiveLocation.FIELD],
args: {
if: {
type: GraphQLBoolean,
description: "Stream when true or undefined.",
},
label: {
type: GraphQLString,
description: "Unique name",
},
initialCount: {
defaultValue: 0,
type: GraphQLInt,
description: "Number of items to return immediately",
},
},
});
32 changes: 32 additions & 0 deletions grafast/grafast/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import debugFactory from "debug";
import type { CallbackOrDescriptor, MiddlewareNext } from "graphile-config";
import type {
DocumentNode,
ExecutionResult,
GraphQLError,
OperationDefinitionNode,
} from "graphql";
import type { ObjMap } from "graphql/jsutils/ObjMap";

import type { __InputDynamicScalarStep } from "./steps/__inputDynamicScalar.js";
import type { DataFromObjectSteps } from "./steps/object.js";
Expand Down Expand Up @@ -833,3 +835,33 @@ declare module "graphql" {
grafast?: Grafast.SchemaExtensions;
}
}

declare module "graphql/execution/execute" {
interface ExecutionPatchResult<
TData = ObjMap<unknown> | unknown,
TExtensions = ObjMap<unknown>,
> {
errors?: ReadonlyArray<GraphQLError>;
data?: TData | null;
path?: ReadonlyArray<string | number>;
label?: string;
hasNext: boolean;
extensions?: TExtensions;
}
type AsyncExecutionResult = ExecutionResult | ExecutionPatchResult;
}

declare module "graphql" {
interface ExecutionPatchResult<
TData = ObjMap<unknown> | unknown,
TExtensions = ObjMap<unknown>,
> {
errors?: ReadonlyArray<GraphQLError>;
data?: TData | null;
path?: ReadonlyArray<string | number>;
label?: string;
hasNext: boolean;
extensions?: TExtensions;
}
type AsyncExecutionResult = ExecutionResult | ExecutionPatchResult;
}
1 change: 1 addition & 0 deletions grafast/grafast/src/makeGrafastSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function makeGrafastSchema(details: {
const { typeDefs, plans, enableDeferStream = false } = details;

const astSchema = buildASTSchema(parse(typeDefs), {
// @ts-ignore
enableDeferStream,
});
const schemaConfig = astSchema.toConfig() as graphql.GraphQLSchemaConfig & {
Expand Down
2 changes: 1 addition & 1 deletion grafast/grafserv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@envelop/core": "^5.0.0",
"grafast": "workspace:^",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"h3": "^1.7.1",
"ws": "^8.12.1"
},
Expand Down
4 changes: 2 additions & 2 deletions grafast/ruru-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"node": ">=16"
},
"peerDependencies": {
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"tamedevil": "workspace:^"
},
"peerDependenciesMeta": {
Expand All @@ -73,7 +73,7 @@
"@types/nodemon": "1.19.2",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"graphql": "16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"jest": "^29.6.4",
"nodemon": "^3.0.1",
"typescript": "^5.2.2"
Expand Down
6 changes: 3 additions & 3 deletions grafast/ruru/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"dependencies": {
"@emotion/is-prop-valid": "^1.2.1",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"http-proxy": "^1.18.1",
"tslib": "^2.6.2",
"yargs": "^17.7.2"
Expand All @@ -56,7 +56,7 @@
},
"peerDependencies": {
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6"
"graphql": "^16.9.0"
},
"files": [
"dist",
Expand All @@ -69,7 +69,7 @@
"@types/yargs": "^17.0.24",
"css-loader": "^6.8.1",
"file-loader": "^6.2.0",
"graphql": "16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"ruru-components": "workspace:^",
"style-loader": "^3.3.3",
"svg-inline-loader": "^0.8.2",
Expand Down
4 changes: 2 additions & 2 deletions graphile-build/graphile-build-pg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"grafast": "workspace:^",
"graphile-build": "workspace:*",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"pg": "^8.7.1",
"pg-sql2": "workspace:^",
"tamedevil": "workspace:^"
Expand Down Expand Up @@ -89,7 +89,7 @@
"fastify": "^4.22.1",
"fastify-static": "^4.7.0",
"graphile-export": "workspace:^",
"graphql": "16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"graphql-helix": "^1.13.0",
"graphql-ws": "^5.14.0",
"jest": "^29.6.4",
Expand Down
6 changes: 3 additions & 3 deletions graphile-build/graphile-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"chalk": "^4.1.2",
"debug": "^4.3.4",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"lodash": "^4.17.21",
"pluralize": "^7.0.0",
"semver": "^7.5.4",
Expand All @@ -55,7 +55,7 @@
"peerDependencies": {
"grafast": "workspace:^",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6"
"graphql": "^16.9.0"
},
"files": [
"dist",
Expand All @@ -65,7 +65,7 @@
"@types/debug": "^4.1.8",
"@types/jest": "^29.5.4",
"graphile-export": "workspace:^",
"graphql": "16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"jest": "^29.6.4",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
Expand Down
54 changes: 34 additions & 20 deletions graphile-build/graphile-build/src/newWithHooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
import { inputObjectFieldSpec, objectSpec } from "grafast";
import type {
GraphQLEnumTypeConfig,
GraphQLEnumValueConfigMap,
GraphQLFieldConfig,
GraphQLInputFieldConfig,
GraphQLInputFieldConfigMap,
Expand Down Expand Up @@ -730,38 +731,51 @@ export function makeNewWithHooks({ builder }: MakeNewWithHooksOptions): {
scope,
};

const finalSpec = builder.applyHooks(
const baseSpec = builder.applyHooks(
"GraphQLEnumType",
rawSpec,
build,
enumContext,
`|${rawSpec.name}`,
);

finalSpec.values = builder.applyHooks(
"GraphQLEnumType_values",
finalSpec.values,
build,
enumContext,
`|${finalSpec.name}`,
);

const values = finalSpec.values;
finalSpec.values = Object.entries(values).reduce(
(memo, [valueKey, value]) => {
const newValue = builder.applyHooks(
"GraphQLEnumType_values_value",
value,
const finalSpec = {
...baseSpec,
values() {
const rawValues =
typeof rawSpec.values === "function"
? rawSpec.values()
: rawSpec.values;
const valuesList: typeof rawValues = build.extend(
Object.create(null),
rawValues,
`Default field included in newWithHooks call for '${
rawSpec.name
}'. ${inScope.__origin || ""}`,
);
const valuesSpec: GraphQLEnumValueConfigMap = builder.applyHooks(
"GraphQLEnumType_values",
valuesList,
build,
enumContext,
`|${finalSpec.name}|${valueKey}`,
`|${Self.name}`,
);

memo[valueKey] = newValue;
return memo;
for (const [valueKey, value] of Object.entries(valuesSpec)) {
const newValue = builder.applyHooks(
"GraphQLEnumType_values_value",
value,
build,
enumContext,
`|${finalSpec.name}|${valueKey}`,
);

valuesSpec[valueKey] = newValue;
}

return valuesSpec;
},
Object.create(null),
);
};

const Self = new GraphQLEnumType(finalSpec);
return Self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const StreamDeferPlugin: GraphileConfig.Plugin = {
hooks: {
GraphQLSchema: {
callback: (schema) => {
// @ts-ignore
schema.enableDeferStream = true;
return schema;
},
Expand Down
2 changes: 1 addition & 1 deletion graphile-build/graphile-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"graphile-build": "workspace:^",
"graphile-build-pg": "workspace:^",
"graphile-config": "workspace:^",
"graphql": "^16.1.0-experimental-stream-defer.6",
"graphql": "^16.9.0",
"tamedevil": "workspace:^"
},
"peerDependenciesMeta": {
Expand Down
Loading
Loading