Skip to content
Open
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 examples/production-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
128 changes: 92 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions src/Locate.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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.`,
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/resolverMapCodegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +89,7 @@ class Codegen {
fieldDefinitions: Record<string, FieldDefinition>,
): 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[] = [];
Expand Down
15 changes: 10 additions & 5 deletions src/codegen/schemaCodegen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ConstDirectiveNode,
GraphQLAbstractType,
GraphQLArgument,
GraphQLDirective,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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),
Expand Down
Loading