diff --git a/examples/production-app/package.json b/examples/production-app/package.json index 9aedf230..f753300d 100644 --- a/examples/production-app/package.json +++ b/examples/production-app/package.json @@ -34,7 +34,7 @@ "@graphql-tools/utils": "^9.2.1", "@graphql-yoga/plugin-defer-stream": "^3.1.1", "dataloader": "^2.2.2", - "graphql": "16.11.0", + "graphql": "17.0.0-alpha.11", "graphql-relay": "^0.10.0", "graphql-yoga": "^5.16.0", "typescript": "^5.5.4" diff --git a/package.json b/package.json index 5f639e60..30315542 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "dependencies": { "commander": "^14.0.1", - "graphql": "^16.11.0", + "graphql": "17.0.0-alpha.11", "semver": "^7.7.2", "typescript": "5.9.2" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab4196b0..8b29cc52 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^14.0.1 version: 14.0.1 graphql: - specifier: ^16.11.0 - version: 16.11.0 + specifier: 17.0.0-alpha.11 + version: 17.0.0-alpha.11 semver: specifier: ^7.7.2 version: 7.7.2 @@ -140,10 +140,10 @@ importers: dependencies: graphql: specifier: ^16.8.1 - version: 16.8.1 + version: 16.11.0 graphql-yoga: specifier: ^5.0.0 - version: 5.0.0(graphql@16.8.1) + version: 5.0.0(graphql@16.11.0) next: specifier: 14.0.3 version: 14.0.3(@opentelemetry/api@1.6.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0) @@ -174,22 +174,22 @@ importers: dependencies: '@graphql-tools/utils': specifier: ^9.2.1 - version: 9.2.1(graphql@16.11.0) + version: 9.2.1(graphql@17.0.0-alpha.11) '@graphql-yoga/plugin-defer-stream': specifier: ^3.1.1 - version: 3.1.1(graphql-yoga@5.16.0(graphql@16.11.0))(graphql@16.11.0) + version: 3.1.1(graphql-yoga@5.16.0(graphql@17.0.0-alpha.11))(graphql@17.0.0-alpha.11) dataloader: specifier: ^2.2.2 version: 2.2.2 graphql: - specifier: 16.11.0 - version: 16.11.0 + specifier: 17.0.0-alpha.11 + version: 17.0.0-alpha.11 graphql-relay: specifier: ^0.10.0 - version: 0.10.0(graphql@16.11.0) + version: 0.10.0(graphql@17.0.0-alpha.11) graphql-yoga: specifier: ^5.16.0 - version: 5.16.0(graphql@16.11.0) + version: 5.16.0(graphql@17.0.0-alpha.11) typescript: specifier: ^5.5.4 version: 5.5.4 @@ -270,7 +270,7 @@ importers: version: 3.7.0(react-dom@18.2.0(react@18.2.0))(react@18.2.0) '@graphql-tools/utils': specifier: ^9.2.1 - version: 9.2.1(graphql@16.11.0) + version: 9.2.1(graphql@17.0.0-alpha.11) '@mdx-js/react': specifier: ^3.0.0 version: 3.0.1(@types/react@18.0.33)(react@18.2.0) @@ -290,8 +290,8 @@ importers: specifier: ^9.3.4 version: 9.3.4 graphql: - specifier: ^16.11.0 - version: 16.11.0 + specifier: 17.0.0-alpha.11 + version: 17.0.0-alpha.11 grats: specifier: workspace:* version: link:.. @@ -346,7 +346,7 @@ importers: version: 1.2.0 graphql-relay: specifier: ^0.10.0 - version: 0.10.0(graphql@16.11.0) + version: 0.10.0(graphql@17.0.0-alpha.11) monaco-editor-webpack-plugin: specifier: ^7.1.0 version: 7.1.0(monaco-editor@0.52.2)(webpack@5.78.0) @@ -4818,6 +4818,10 @@ packages: resolution: {integrity: sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==} engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0} + graphql@17.0.0-alpha.11: + resolution: {integrity: sha512-28FSpHCjJZP9nxBmLYREbIkq5llRTfqaEPpnphQ05Q6rUME6bN3J2IppNY1blO5TZwiQruhu379A4BX4XlLTRQ==} + engines: {node: ^20.0.0 || ^22.0.0 || ^24.0.0 || >=25.0.0} + grats@0.0.26: resolution: {integrity: sha512-9JVF3kvOB42+PDZhmxcbv5Co7vMUSfdUN417mubFleALZ9tTBlzlKQ2HkkkUghZp1/OE2VHk1cT3QyjvQzyE+w==} engines: {node: '>=16 <=21', pnpm: ^8} @@ -10653,6 +10657,15 @@ snapshots: '@fastify/busboy@3.2.0': {} + '@graphql-tools/executor@1.2.0(graphql@16.11.0)': + dependencies: + '@graphql-tools/utils': 10.6.2(graphql@16.11.0) + '@graphql-typed-document-node/core': 3.2.0(graphql@16.11.0) + '@repeaterjs/repeater': 3.0.5 + graphql: 16.11.0 + tslib: 2.6.2 + value-or-promise: 1.0.12 + '@graphql-tools/executor@1.2.0(graphql@16.8.1)': dependencies: '@graphql-tools/utils': 10.6.2(graphql@16.8.1) @@ -10662,14 +10675,14 @@ snapshots: tslib: 2.6.2 value-or-promise: 1.0.12 - '@graphql-tools/executor@1.4.9(graphql@16.11.0)': + '@graphql-tools/executor@1.4.9(graphql@17.0.0-alpha.11)': dependencies: - '@graphql-tools/utils': 10.9.1(graphql@16.11.0) - '@graphql-typed-document-node/core': 3.2.0(graphql@16.11.0) + '@graphql-tools/utils': 10.9.1(graphql@17.0.0-alpha.11) + '@graphql-typed-document-node/core': 3.2.0(graphql@17.0.0-alpha.11) '@repeaterjs/repeater': 3.0.5 '@whatwg-node/disposablestack': 0.0.6 '@whatwg-node/promise-helpers': 1.3.2 - graphql: 16.11.0 + graphql: 17.0.0-alpha.11 tslib: 2.8.1 '@graphql-tools/merge@9.0.12(graphql@16.11.0)': @@ -10684,6 +10697,12 @@ snapshots: graphql: 16.8.1 tslib: 2.8.1 + '@graphql-tools/merge@9.0.12(graphql@17.0.0-alpha.11)': + dependencies: + '@graphql-tools/utils': 10.6.2(graphql@17.0.0-alpha.11) + graphql: 17.0.0-alpha.11 + tslib: 2.8.1 + '@graphql-tools/merge@9.0.4(graphql@16.8.1)': dependencies: '@graphql-tools/utils': 10.6.2(graphql@16.8.1) @@ -10706,6 +10725,14 @@ snapshots: tslib: 2.8.1 value-or-promise: 1.0.12 + '@graphql-tools/schema@10.0.11(graphql@17.0.0-alpha.11)': + dependencies: + '@graphql-tools/merge': 9.0.12(graphql@17.0.0-alpha.11) + '@graphql-tools/utils': 10.6.2(graphql@17.0.0-alpha.11) + graphql: 17.0.0-alpha.11 + tslib: 2.8.1 + value-or-promise: 1.0.12 + '@graphql-tools/schema@10.0.3(graphql@16.8.1)': dependencies: '@graphql-tools/merge': 9.0.4(graphql@16.8.1) @@ -10730,24 +10757,32 @@ snapshots: graphql: 16.8.1 tslib: 2.8.1 - '@graphql-tools/utils@10.9.1(graphql@16.11.0)': + '@graphql-tools/utils@10.6.2(graphql@17.0.0-alpha.11)': dependencies: - '@graphql-typed-document-node/core': 3.2.0(graphql@16.11.0) + '@graphql-typed-document-node/core': 3.2.0(graphql@17.0.0-alpha.11) + cross-inspect: 1.0.1 + dset: 3.1.4 + graphql: 17.0.0-alpha.11 + tslib: 2.8.1 + + '@graphql-tools/utils@10.9.1(graphql@17.0.0-alpha.11)': + dependencies: + '@graphql-typed-document-node/core': 3.2.0(graphql@17.0.0-alpha.11) '@whatwg-node/promise-helpers': 1.3.2 cross-inspect: 1.0.1 dset: 3.1.4 - graphql: 16.11.0 + graphql: 17.0.0-alpha.11 tslib: 2.8.1 - '@graphql-tools/utils@9.2.1(graphql@16.11.0)': + '@graphql-tools/utils@9.2.1(graphql@17.0.0-alpha.11)': dependencies: - '@graphql-typed-document-node/core': 3.1.2(graphql@16.11.0) - graphql: 16.11.0 + '@graphql-typed-document-node/core': 3.1.2(graphql@17.0.0-alpha.11) + graphql: 17.0.0-alpha.11 tslib: 2.5.0 - '@graphql-typed-document-node/core@3.1.2(graphql@16.11.0)': + '@graphql-typed-document-node/core@3.1.2(graphql@17.0.0-alpha.11)': dependencies: - graphql: 16.11.0 + graphql: 17.0.0-alpha.11 '@graphql-typed-document-node/core@3.2.0(graphql@16.11.0)': dependencies: @@ -10757,6 +10792,10 @@ snapshots: dependencies: graphql: 16.8.1 + '@graphql-typed-document-node/core@3.2.0(graphql@17.0.0-alpha.11)': + dependencies: + graphql: 17.0.0-alpha.11 + '@graphql-yoga/logger@2.0.0': dependencies: tslib: 2.6.2 @@ -10765,11 +10804,11 @@ snapshots: dependencies: tslib: 2.8.1 - '@graphql-yoga/plugin-defer-stream@3.1.1(graphql-yoga@5.16.0(graphql@16.11.0))(graphql@16.11.0)': + '@graphql-yoga/plugin-defer-stream@3.1.1(graphql-yoga@5.16.0(graphql@17.0.0-alpha.11))(graphql@17.0.0-alpha.11)': dependencies: - '@graphql-tools/utils': 10.6.2(graphql@16.11.0) - graphql: 16.11.0 - graphql-yoga: 5.16.0(graphql@16.11.0) + '@graphql-tools/utils': 10.6.2(graphql@17.0.0-alpha.11) + graphql: 17.0.0-alpha.11 + graphql-yoga: 5.16.0(graphql@17.0.0-alpha.11) '@graphql-yoga/subscription@5.0.0': dependencies: @@ -13444,9 +13483,24 @@ snapshots: dependencies: graphql: 16.8.1 - graphql-relay@0.10.0(graphql@16.11.0): + graphql-relay@0.10.0(graphql@17.0.0-alpha.11): dependencies: + graphql: 17.0.0-alpha.11 + + graphql-yoga@5.0.0(graphql@16.11.0): + dependencies: + '@envelop/core': 5.0.0 + '@graphql-tools/executor': 1.2.0(graphql@16.11.0) + '@graphql-tools/schema': 10.0.11(graphql@16.11.0) + '@graphql-tools/utils': 10.6.2(graphql@16.11.0) + '@graphql-yoga/logger': 2.0.0 + '@graphql-yoga/subscription': 5.0.0 + '@whatwg-node/fetch': 0.9.14 + '@whatwg-node/server': 0.9.16 + dset: 3.1.3 graphql: 16.11.0 + lru-cache: 10.0.2 + tslib: 2.6.2 graphql-yoga@5.0.0(graphql@16.8.1): dependencies: @@ -13463,20 +13517,20 @@ snapshots: lru-cache: 10.0.2 tslib: 2.6.2 - graphql-yoga@5.16.0(graphql@16.11.0): + graphql-yoga@5.16.0(graphql@17.0.0-alpha.11): dependencies: '@envelop/core': 5.3.2 '@envelop/instrumentation': 1.0.0 - '@graphql-tools/executor': 1.4.9(graphql@16.11.0) - '@graphql-tools/schema': 10.0.11(graphql@16.11.0) - '@graphql-tools/utils': 10.6.2(graphql@16.11.0) + '@graphql-tools/executor': 1.4.9(graphql@17.0.0-alpha.11) + '@graphql-tools/schema': 10.0.11(graphql@17.0.0-alpha.11) + '@graphql-tools/utils': 10.6.2(graphql@17.0.0-alpha.11) '@graphql-yoga/logger': 2.0.1 '@graphql-yoga/subscription': 5.0.5 '@whatwg-node/fetch': 0.10.11 '@whatwg-node/promise-helpers': 1.3.2 '@whatwg-node/server': 0.10.12 dset: 3.1.4 - graphql: 16.11.0 + graphql: 17.0.0-alpha.11 lru-cache: 10.0.2 tslib: 2.8.1 @@ -13484,6 +13538,8 @@ snapshots: graphql@16.8.1: {} + graphql@17.0.0-alpha.11: {} + grats@0.0.26: dependencies: commander: 10.0.1 diff --git a/src/Locate.ts b/src/Locate.ts index aa584066..92c97f46 100644 --- a/src/Locate.ts +++ b/src/Locate.ts @@ -1,9 +1,9 @@ import { - GraphQLInputObjectType, - GraphQLInterfaceType, - GraphQLObjectType, GraphQLSchema, Location, + isObjectType, + isInterfaceType, + isInputObjectType, } from "graphql"; import { Result, err, ok } from "./utils/Result.js"; import { nullThrows } from "./utils/helpers.js"; @@ -40,11 +40,7 @@ export function locate( } if ( - !( - type instanceof GraphQLObjectType || - type instanceof GraphQLInterfaceType || - type instanceof GraphQLInputObjectType - ) + !(isObjectType(type) || isInterfaceType(type) || isInputObjectType(type)) ) { return err( `Cannot locate field \`${entity.field}\` on type \`${entity.parent}\`. Only object types, interfaces, and input objects have fields.`, diff --git a/src/codegen/resolverMapCodegen.ts b/src/codegen/resolverMapCodegen.ts index c30c95b3..a32b133b 100644 --- a/src/codegen/resolverMapCodegen.ts +++ b/src/codegen/resolverMapCodegen.ts @@ -3,7 +3,7 @@ import { GratsConfig } from "../gratsConfig.js"; import TSAstBuilder from "./TSAstBuilder.js"; import ResolverCodegen from "./resolverCodegen.js"; import { Metadata, FieldDefinition } from "../metadata.js"; -import { GraphQLObjectType, GraphQLSchema } from "graphql"; +import { GraphQLSchema, isObjectType } from "graphql"; import { nullThrows } from "../utils/helpers.js"; const F = ts.factory; @@ -89,7 +89,7 @@ class Codegen { fieldDefinitions: Record, ): ts.ObjectLiteralElementLike[] { const graphQLType = this._schema.getType(typeName); - if (!(graphQLType instanceof GraphQLObjectType)) { + if (!isObjectType(graphQLType)) { throw new Error(`Type ${typeName} is not an object type`); } const fields: ts.ObjectLiteralElementLike[] = []; diff --git a/src/codegen/schemaCodegen.ts b/src/codegen/schemaCodegen.ts index ffb9f3bd..189b1b46 100644 --- a/src/codegen/schemaCodegen.ts +++ b/src/codegen/schemaCodegen.ts @@ -1,4 +1,5 @@ import { + ConstDirectiveNode, GraphQLAbstractType, GraphQLArgument, GraphQLDirective, @@ -33,7 +34,6 @@ import { naturalCompare } from "../utils/naturalCompare.js"; import TSAstBuilder, { JsonValue } from "./TSAstBuilder.js"; import ResolverCodegen from "./resolverCodegen.js"; import { Metadata } from "../metadata.js"; -import { ConstDirectiveNode } from "graphql/language/index.js"; import { ExportDefinition } from "../GraphQLAstExtensions.js"; // These directives will be added to the schema by default, so we don't need to @@ -95,7 +95,7 @@ class Codegen { schemaDeclarationExport(): void { const scalars = Object.values(this._schema.getTypeMap()) .filter((type) => { - return type instanceof GraphQLScalarType; + return isScalarType(type); }) .filter((type) => !BUILT_IN_SCALARS.has(type.name)) .map((type) => { @@ -691,15 +691,20 @@ class Codegen { } argConfig(arg: GraphQLArgument): ts.Expression { + // In graphql-js v17, defaultValue is deprecated in favor of `default`. + const argDefault = arg.default; return this.ts.objectLiteral([ this.description(arg.description), this.deprecated(arg), F.createPropertyAssignment("type", this.typeReference(arg.type)), - // TODO: arg.defaultValue seems to be missing for complex objects - arg.defaultValue !== undefined + argDefault !== undefined ? F.createPropertyAssignment( "defaultValue", - this.defaultValue(arg.defaultValue), + this.defaultValue( + argDefault.value !== undefined + ? argDefault.value + : valueFromASTUntyped(argDefault.literal!), + ), ) : null, this.extensions(arg.astNode?.directives), diff --git a/src/tests/fixtures/arguments/PositionalArgDeprecatedWithDefault.ts.expected.md b/src/tests/fixtures/arguments/PositionalArgDeprecatedWithDefault.ts.expected.md index 16e6bdd2..d6f432f4 100644 --- a/src/tests/fixtures/arguments/PositionalArgDeprecatedWithDefault.ts.expected.md +++ b/src/tests/fixtures/arguments/PositionalArgDeprecatedWithDefault.ts.expected.md @@ -32,7 +32,7 @@ input Greeting { } type SomeType { - hello(greeting: Greeting! = {name: "Alice", salutation: "Hullo"} @deprecated(reason: "Unused!")): String + hello(greeting: Greeting! = { name: "Alice", salutation: "Hullo" } @deprecated(reason: "Unused!")): String } ``` diff --git a/src/tests/fixtures/custom_scalars/SpecifiedByMissingUrlinvalid.invalid.ts.expected.md b/src/tests/fixtures/custom_scalars/SpecifiedByMissingUrlinvalid.invalid.ts.expected.md index 5bdd2838..80eafb76 100644 --- a/src/tests/fixtures/custom_scalars/SpecifiedByMissingUrlinvalid.invalid.ts.expected.md +++ b/src/tests/fixtures/custom_scalars/SpecifiedByMissingUrlinvalid.invalid.ts.expected.md @@ -15,7 +15,7 @@ export type UUID = string; ### Error Report ```text -src/tests/fixtures/custom_scalars/SpecifiedByMissingUrlinvalid.invalid.ts:3:4 - error: Directive "@specifiedBy" argument "url" of type "String!" is required, but it was not provided. +src/tests/fixtures/custom_scalars/SpecifiedByMissingUrlinvalid.invalid.ts:3:4 - error: Argument "@specifiedBy(url:)" of type "String!" is required, but it was not provided. 3 * @gqlAnnotate specifiedBy ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/tests/fixtures/default_values/DefaultArgumentObjectLiteral.ts.expected.md b/src/tests/fixtures/default_values/DefaultArgumentObjectLiteral.ts.expected.md index c41ab0ae..1ca1d03a 100644 --- a/src/tests/fixtures/default_values/DefaultArgumentObjectLiteral.ts.expected.md +++ b/src/tests/fixtures/default_values/DefaultArgumentObjectLiteral.ts.expected.md @@ -35,7 +35,7 @@ input ConnectionInput { } type SomeType { - someField1(input: ConnectionInput = {first: 10, offset: 100}): String + someField1(input: ConnectionInput = { first: 10, offset: 100 }): String } ``` diff --git a/src/tests/fixtures/directives/directiveArgFieldInvalid.invalid.ts.expected.md b/src/tests/fixtures/directives/directiveArgFieldInvalid.invalid.ts.expected.md index 3107dd1c..be425b57 100644 --- a/src/tests/fixtures/directives/directiveArgFieldInvalid.invalid.ts.expected.md +++ b/src/tests/fixtures/directives/directiveArgFieldInvalid.invalid.ts.expected.md @@ -35,5 +35,5 @@ GraphQL request:1:27 - error: String cannot represent a non string value: 10 src/tests/fixtures/directives/directiveArgFieldInvalid.invalid.ts:4:1 4 type MyInput = { a: string }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Parent input type defined here + Input type defined here ``` \ No newline at end of file diff --git a/src/tests/fixtures/enums/NonNullEnumDefaultInInputObject.ts.expected.md b/src/tests/fixtures/enums/NonNullEnumDefaultInInputObject.ts.expected.md index 9bc14ca2..05de79b4 100644 --- a/src/tests/fixtures/enums/NonNullEnumDefaultInInputObject.ts.expected.md +++ b/src/tests/fixtures/enums/NonNullEnumDefaultInInputObject.ts.expected.md @@ -37,7 +37,7 @@ input GreetingInput { } type Query { - hello(input: GreetingInput! = {greeting: Greetings}): String + hello(input: GreetingInput! = { greeting: Greetings }): String } ``` diff --git a/src/validations/validateTypenames.ts b/src/validations/validateTypenames.ts index 586fee32..3955b0a5 100644 --- a/src/validations/validateTypenames.ts +++ b/src/validations/validateTypenames.ts @@ -1,9 +1,9 @@ import * as ts from "typescript"; import { - GraphQLInterfaceType, GraphQLSchema, Kind, isAbstractType, + isInterfaceType, isType, } from "graphql"; import { @@ -34,22 +34,20 @@ export function validateTypenames( // Synthesized type cannot guarantee that they have the correct __typename field, so we // prevent their use in interfaces and unions. if (ast.kind === Kind.OBJECT_TYPE_DEFINITION && ast.wasSynthesized) { - const message = - type instanceof GraphQLInterfaceType - ? E.genericTypeImplementsInterface() - : E.genericTypeUsedAsUnionMember(); + const message = isInterfaceType(type) + ? E.genericTypeImplementsInterface() + : E.genericTypeUsedAsUnionMember(); errors.push(gqlErr(ast.name, message)); } else if (!hasTypename.has(implementor.name) && ast.exported == null) { - const message = - type instanceof GraphQLInterfaceType - ? E.concreteTypenameImplementingInterfaceCannotBeResolved( - implementor.name, - type.name, - ) - : E.concreteTypenameInUnionCannotBeResolved( - implementor.name, - type.name, - ); + const message = isInterfaceType(type) + ? E.concreteTypenameImplementingInterfaceCannotBeResolved( + implementor.name, + type.name, + ) + : E.concreteTypenameInUnionCannotBeResolved( + implementor.name, + type.name, + ); const err = gqlErr(ast.name, message, [ gqlRelated( diff --git a/website/package.json b/website/package.json index 4a813f71..0381a6ea 100644 --- a/website/package.json +++ b/website/package.json @@ -30,7 +30,7 @@ "@typescript/vfs": "1.6.0", "clsx": "^1.2.1", "glob": "^9.3.4", - "graphql": "^16.11.0", + "graphql": "17.0.0-alpha.11", "grats": "workspace:*", "lz-string": "^1.5.0", "monaco-editor": "^0.52.2",