From 14129ccf323b63466e8d2da1aa569204f815c469 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Tue, 6 Aug 2024 15:15:50 +0100 Subject: [PATCH 1/3] Upgrade GraphQL everywhere --- grafast/bench/package.json | 2 +- grafast/dataplan-pg/package.json | 2 +- grafast/grafast/package.json | 6 +-- grafast/grafserv/package.json | 2 +- grafast/ruru-components/package.json | 4 +- grafast/ruru/package.json | 6 +-- graphile-build/graphile-build-pg/package.json | 4 +- graphile-build/graphile-build/package.json | 6 +-- graphile-build/graphile-utils/package.json | 2 +- package.json | 4 +- postgraphile/pgl/package.json | 2 +- postgraphile/postgraphile/package.json | 4 +- .../package.json | 2 +- yarn.lock | 46 +++++++++---------- 14 files changed, 46 insertions(+), 46 deletions(-) diff --git a/grafast/bench/package.json b/grafast/bench/package.json index 25de1b1971..f056379806 100644 --- a/grafast/bench/package.json +++ b/grafast/bench/package.json @@ -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": { diff --git a/grafast/dataplan-pg/package.json b/grafast/dataplan-pg/package.json index cb1e86fe8f..63213e00b2 100644 --- a/grafast/dataplan-pg/package.json +++ b/grafast/dataplan-pg/package.json @@ -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:^", diff --git a/grafast/grafast/package.json b/grafast/grafast/package.json index 112ee94631..66ce6dba2a 100644 --- a/grafast/grafast/package.json +++ b/grafast/grafast/package.json @@ -66,7 +66,7 @@ "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" @@ -74,7 +74,7 @@ "peerDependencies": { "@envelop/core": "^5.0.0", "graphile-config": "workspace:^", - "graphql": "^16.1.0-experimental-stream-defer.6", + "graphql": "^16.9.0", "tamedevil": "workspace:^" }, "peerDependenciesMeta": { @@ -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", diff --git a/grafast/grafserv/package.json b/grafast/grafserv/package.json index 6beb9c474b..9676fba8e3 100644 --- a/grafast/grafserv/package.json +++ b/grafast/grafserv/package.json @@ -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" }, diff --git a/grafast/ruru-components/package.json b/grafast/ruru-components/package.json index 177768d17d..91c5193694 100644 --- a/grafast/ruru-components/package.json +++ b/grafast/ruru-components/package.json @@ -53,7 +53,7 @@ "node": ">=16" }, "peerDependencies": { - "graphql": "^16.1.0-experimental-stream-defer.6", + "graphql": "^16.9.0", "tamedevil": "workspace:^" }, "peerDependenciesMeta": { @@ -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" diff --git a/grafast/ruru/package.json b/grafast/ruru/package.json index c04971d047..8c45b98258 100644 --- a/grafast/ruru/package.json +++ b/grafast/ruru/package.json @@ -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" @@ -56,7 +56,7 @@ }, "peerDependencies": { "graphile-config": "workspace:^", - "graphql": "^16.1.0-experimental-stream-defer.6" + "graphql": "^16.9.0" }, "files": [ "dist", @@ -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", diff --git a/graphile-build/graphile-build-pg/package.json b/graphile-build/graphile-build-pg/package.json index d1724467eb..301ef9b974 100644 --- a/graphile-build/graphile-build-pg/package.json +++ b/graphile-build/graphile-build-pg/package.json @@ -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:^" @@ -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", diff --git a/graphile-build/graphile-build/package.json b/graphile-build/graphile-build/package.json index 6bfe17e58e..2f625f8d19 100644 --- a/graphile-build/graphile-build/package.json +++ b/graphile-build/graphile-build/package.json @@ -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", @@ -55,7 +55,7 @@ "peerDependencies": { "grafast": "workspace:^", "graphile-config": "workspace:^", - "graphql": "^16.1.0-experimental-stream-defer.6" + "graphql": "^16.9.0" }, "files": [ "dist", @@ -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" diff --git a/graphile-build/graphile-utils/package.json b/graphile-build/graphile-utils/package.json index 12da1f9a8b..f77b4972b8 100644 --- a/graphile-build/graphile-utils/package.json +++ b/graphile-build/graphile-utils/package.json @@ -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": { diff --git a/package.json b/package.json index 9694103506..b894c1a513 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "eslint-plugin-tsdoc": "^0.2.17", "eslint_d": "^12.2.1", "glob": "^10.3.4", - "graphql": "16.1.0-experimental-stream-defer.6", + "graphql": "^16.9.0", "jest": "^29.6.4", "mock-fs": "^5.2.0", "pg": "^8.11.3", @@ -87,7 +87,7 @@ }, "packageManager": "yarn@4.0.0-rc.33", "resolutions": { - "graphql": "16.1.0-experimental-stream-defer.6" + "graphql": "^16.9.0" }, "dependencies": { "@changesets/changelog-github": "^0.4.8", diff --git a/postgraphile/pgl/package.json b/postgraphile/pgl/package.json index 4c24f37cb1..bf3cf2f1a1 100644 --- a/postgraphile/pgl/package.json +++ b/postgraphile/pgl/package.json @@ -196,7 +196,7 @@ "graphile-build": "workspace:*", "graphile-build-pg": "workspace:*", "graphile-config": "workspace:^", - "graphql": "16.1.0-experimental-stream-defer.6", + "graphql": "^16.9.0", "iterall": "^1.3.0", "jsonwebtoken": "^9.0.2", "pg": "^8.11.3", diff --git a/postgraphile/postgraphile/package.json b/postgraphile/postgraphile/package.json index d228a546a3..f78c96bb9c 100644 --- a/postgraphile/postgraphile/package.json +++ b/postgraphile/postgraphile/package.json @@ -216,7 +216,7 @@ "graphile-build-pg": "workspace:*", "graphile-config": "workspace:^", "graphile-utils": "workspace:^", - "graphql": "^16.1.0-experimental-stream-defer.6", + "graphql": "^16.9.0", "iterall": "^1.3.0", "jsonwebtoken": "^9.0.2", "pg": "^8.11.3", @@ -234,7 +234,7 @@ "graphile-build": "workspace:*", "graphile-build-pg": "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:^" diff --git a/utils/jest-serializer-graphql-schema/package.json b/utils/jest-serializer-graphql-schema/package.json index eefefd90f3..bf01d6378b 100644 --- a/utils/jest-serializer-graphql-schema/package.json +++ b/utils/jest-serializer-graphql-schema/package.json @@ -31,7 +31,7 @@ }, "devDependencies": { "@types/jest": "^29.5.4", - "graphql": "16.1.0-experimental-stream-defer.6", + "graphql": "^16.9.0", "jest": "^29.6.4", "pretty-format": "^29.6.3", "ts-node": "^10.9.1", diff --git a/yarn.lock b/yarn.lock index d8328c0d4a..5be2b84c67 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2264,7 +2264,7 @@ __metadata: glob: "npm:^10.3.4" grafserv: "workspace:*" graphile-export: "workspace:*" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" iterall: "npm:^1.3.0" jest: "npm:^29.6.4" jest-serializer-simple: "workspace:^" @@ -4004,7 +4004,7 @@ __metadata: glob: "npm:^10.3.4" grafast: "workspace:^" graphile-config: "workspace:^" - graphql: "npm:^16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" nodemon: "npm:^3.0.1" ts-node: "npm:^10.9.1" tslib: "npm:^2.6.2" @@ -12043,7 +12043,7 @@ __metadata: chalk: "npm:^4.1.2" debug: "npm:^4.3.4" eventemitter3: "npm:^5.0.1" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" iterall: "npm:^1.3.0" jest: "npm:^29.6.4" lodash: "npm:^4.17.21" @@ -12062,7 +12062,7 @@ __metadata: peerDependencies: "@envelop/core": ^5.0.0 graphile-config: "workspace:^" - graphql: ^16.1.0-experimental-stream-defer.6 + graphql: ^16.9.0 tamedevil: "workspace:^" peerDependenciesMeta: "@envelop/core": @@ -12106,7 +12106,7 @@ __metadata: "@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 peerDependenciesMeta: @@ -12153,7 +12153,7 @@ __metadata: fastify-static: "npm:^4.7.0" graphile-config: "workspace:^" graphile-export: "workspace:^" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" graphql-helix: "npm:^1.13.0" graphql-ws: "npm:^5.14.0" jest: "npm:^29.6.4" @@ -12170,7 +12170,7 @@ __metadata: 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:^" @@ -12193,7 +12193,7 @@ __metadata: debug: "npm:^4.3.4" graphile-config: "workspace:^" graphile-export: "workspace:^" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" jest: "npm:^29.6.4" lodash: "npm:^4.17.21" pluralize: "npm:^7.0.0" @@ -12205,7 +12205,7 @@ __metadata: peerDependencies: grafast: "workspace:^" graphile-config: "workspace:^" - graphql: ^16.1.0-experimental-stream-defer.6 + graphql: ^16.9.0 languageName: unknown linkType: soft @@ -12283,7 +12283,7 @@ __metadata: 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: "@dataplan/pg": @@ -12418,10 +12418,10 @@ __metadata: languageName: node linkType: hard -"graphql@npm:16.1.0-experimental-stream-defer.6": - version: 16.1.0-experimental-stream-defer.6 - resolution: "graphql@npm:16.1.0-experimental-stream-defer.6" - checksum: 8e280798cf5738f2013c30891fd4f720d5e0fa1b074061176597af95db7779bc435d981fd7da31b89c10c84b35ce9b3377e2f7891be62d63386bebcf45f3c2d9 +"graphql@npm:^16.9.0": + version: 16.9.0 + resolution: "graphql@npm:16.9.0" + checksum: 09feee5ee3b791c396d73d2c49fb7bdcd09b8b0c42816f78d4bd2aa5ee356dd234c859d15be4df696b2404bc0dcaa25e5a9776034f33b6ecddc7b83f7213cc48 languageName: node linkType: hard @@ -14203,7 +14203,7 @@ __metadata: resolution: "jest-serializer-graphql-schema@workspace:utils/jest-serializer-graphql-schema" dependencies: "@types/jest": "npm:^29.5.4" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" jest: "npm:^29.6.4" pretty-format: "npm:^29.6.3" ts-node: "npm:^10.9.1" @@ -17215,7 +17215,7 @@ __metadata: graphile-build: "workspace:*" graphile-build-pg: "workspace:*" graphile-config: "workspace:^" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" iterall: "npm:^1.3.0" jest: "npm:^29.6.4" jsonwebtoken: "npm:^9.0.2" @@ -17835,7 +17835,7 @@ __metadata: graphile-config: "workspace:^" graphile-export: "workspace:^" graphile-utils: "workspace:^" - graphql: "npm:^16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" iterall: "npm:^1.3.0" jest: "npm:^29.6.4" jsonwebtoken: "npm:^9.0.2" @@ -17856,7 +17856,7 @@ __metadata: graphile-build: "workspace:*" graphile-build-pg: "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:^" @@ -19231,7 +19231,7 @@ __metadata: eslint-plugin-tsdoc: "npm:^0.2.17" eslint_d: "npm:^12.2.1" glob: "npm:^10.3.4" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" jest: "npm:^29.6.4" mock-fs: "npm:^5.2.0" pg: "npm:^8.11.3" @@ -19291,7 +19291,7 @@ __metadata: "@types/react-dom": "npm:^18.2.7" grafast: "workspace:^" graphiql: "npm:^3.1.1-canary-64994e0e.0" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" graphql-ws: "npm:^5.14.0" jest: "npm:^29.6.4" nodemon: "npm:^3.0.1" @@ -19300,7 +19300,7 @@ __metadata: tslib: "npm:^2.6.2" typescript: "npm:^5.2.2" peerDependencies: - graphql: ^16.1.0-experimental-stream-defer.6 + graphql: ^16.9.0 tamedevil: "workspace:^" peerDependenciesMeta: tamedevil: @@ -19319,7 +19319,7 @@ __metadata: css-loader: "npm:^6.8.1" file-loader: "npm:^6.2.0" graphile-config: "workspace:^" - graphql: "npm:16.1.0-experimental-stream-defer.6" + graphql: "npm:^16.9.0" http-proxy: "npm:^1.18.1" ruru-components: "workspace:^" style-loader: "npm:^3.3.3" @@ -19333,7 +19333,7 @@ __metadata: yargs: "npm:^17.7.2" peerDependencies: graphile-config: "workspace:^" - graphql: ^16.1.0-experimental-stream-defer.6 + graphql: ^16.9.0 bin: ruru: ./dist/cli-run.js languageName: unknown From 8791b2ddb4871c181e3e954d6a1c53e0b676f8a8 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Tue, 6 Aug 2024 15:16:13 +0100 Subject: [PATCH 2/3] Changes required to support new GraphQL --- .../dataplan-pg/src/examples/exampleSchema.ts | 1 + grafast/grafast/src/index.ts | 32 +++++++++++ grafast/grafast/src/makeGrafastSchema.ts | 1 + .../graphile-build/src/newWithHooks/index.ts | 54 ++++++++++++------- .../src/plugins/StreamDeferPlugin.ts | 1 + utils/graphile-export/src/exportSchema.ts | 9 +++- 6 files changed, 77 insertions(+), 21 deletions(-) diff --git a/grafast/dataplan-pg/src/examples/exampleSchema.ts b/grafast/dataplan-pg/src/examples/exampleSchema.ts index e642d59aa6..d05c666275 100644 --- a/grafast/dataplan-pg/src/examples/exampleSchema.ts +++ b/grafast/dataplan-pg/src/examples/exampleSchema.ts @@ -5262,6 +5262,7 @@ export function makeExampleSchema( ], }, }, + // @ts-ignore enableDeferStream: true, }); } diff --git a/grafast/grafast/src/index.ts b/grafast/grafast/src/index.ts index fbfd7263b5..3398572aa8 100644 --- a/grafast/grafast/src/index.ts +++ b/grafast/grafast/src/index.ts @@ -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"; @@ -833,3 +835,33 @@ declare module "graphql" { grafast?: Grafast.SchemaExtensions; } } + +declare module "graphql/execution/execute" { + interface ExecutionPatchResult< + TData = ObjMap | unknown, + TExtensions = ObjMap, + > { + errors?: ReadonlyArray; + data?: TData | null; + path?: ReadonlyArray; + label?: string; + hasNext: boolean; + extensions?: TExtensions; + } + type AsyncExecutionResult = ExecutionResult | ExecutionPatchResult; +} + +declare module "graphql" { + interface ExecutionPatchResult< + TData = ObjMap | unknown, + TExtensions = ObjMap, + > { + errors?: ReadonlyArray; + data?: TData | null; + path?: ReadonlyArray; + label?: string; + hasNext: boolean; + extensions?: TExtensions; + } + type AsyncExecutionResult = ExecutionResult | ExecutionPatchResult; +} diff --git a/grafast/grafast/src/makeGrafastSchema.ts b/grafast/grafast/src/makeGrafastSchema.ts index e99beb192e..782f30315e 100644 --- a/grafast/grafast/src/makeGrafastSchema.ts +++ b/grafast/grafast/src/makeGrafastSchema.ts @@ -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 & { diff --git a/graphile-build/graphile-build/src/newWithHooks/index.ts b/graphile-build/graphile-build/src/newWithHooks/index.ts index e0c76436c7..b25e9aef3e 100644 --- a/graphile-build/graphile-build/src/newWithHooks/index.ts +++ b/graphile-build/graphile-build/src/newWithHooks/index.ts @@ -7,6 +7,7 @@ import type { import { inputObjectFieldSpec, objectSpec } from "grafast"; import type { GraphQLEnumTypeConfig, + GraphQLEnumValueConfigMap, GraphQLFieldConfig, GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, @@ -730,7 +731,7 @@ export function makeNewWithHooks({ builder }: MakeNewWithHooksOptions): { scope, }; - const finalSpec = builder.applyHooks( + const baseSpec = builder.applyHooks( "GraphQLEnumType", rawSpec, build, @@ -738,30 +739,43 @@ export function makeNewWithHooks({ builder }: MakeNewWithHooksOptions): { `|${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; diff --git a/graphile-build/graphile-build/src/plugins/StreamDeferPlugin.ts b/graphile-build/graphile-build/src/plugins/StreamDeferPlugin.ts index f3545456d3..ac1d6edf6a 100644 --- a/graphile-build/graphile-build/src/plugins/StreamDeferPlugin.ts +++ b/graphile-build/graphile-build/src/plugins/StreamDeferPlugin.ts @@ -14,6 +14,7 @@ export const StreamDeferPlugin: GraphileConfig.Plugin = { hooks: { GraphQLSchema: { callback: (schema) => { + // @ts-ignore schema.enableDeferStream = true; return schema; }, diff --git a/utils/graphile-export/src/exportSchema.ts b/utils/graphile-export/src/exportSchema.ts index 1d43a628d2..53abc20fc6 100644 --- a/utils/graphile-export/src/exportSchema.ts +++ b/utils/graphile-export/src/exportSchema.ts @@ -757,6 +757,9 @@ class CodegenFile { `${config.name}.extensions`, `${config.name}.extensions`, ), + isOneOf: config.isOneOf + ? t.booleanLiteral(true) + : t.identifier("undefined"), fields: t.arrowFunctionExpression( [], this.makeInputObjectFields(config.fields, config.name), @@ -1560,9 +1563,12 @@ function exportSchemaGraphQLJS({ "schema.extensions", "schema.extensions", ), + // @ts-ignore enableDeferStream: + // @ts-ignore config.enableDeferStream != null - ? t.booleanLiteral(config.enableDeferStream) + ? // @ts-ignore + t.booleanLiteral(config.enableDeferStream) : null, assumeValid: null, // TODO: t.booleanLiteral(true), }), @@ -1928,6 +1934,7 @@ export async function exportSchemaAsString( config.directives.some((d) => d.name === "defer" || d.name === "skip") ) { // Ref: https://github.com/graphql/graphql-js/pull/3450 + // @ts-ignore config.enableDeferStream = true; } From 7d77692f6283e8002cf9b63a8951a020030c3945 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Tue, 6 Aug 2024 16:12:13 +0100 Subject: [PATCH 3/3] Copy across directives --- grafast/grafast/src/incremental.ts | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 grafast/grafast/src/incremental.ts diff --git a/grafast/grafast/src/incremental.ts b/grafast/grafast/src/incremental.ts new file mode 100644 index 0000000000..5cfce840c4 --- /dev/null +++ b/grafast/grafast/src/incremental.ts @@ -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", + }, + }, +});