diff --git a/.changeset/eight-ligers-develop.md b/.changeset/eight-ligers-develop.md new file mode 100644 index 000000000..38bea0586 --- /dev/null +++ b/.changeset/eight-ligers-develop.md @@ -0,0 +1,6 @@ +--- +'@pothos/plugin-relay': patch +'@pothos/deno': patch +--- + +Fix a few issues with globalID parsing diff --git a/packages/deno/packages/plugin-relay/index.ts b/packages/deno/packages/plugin-relay/index.ts index cfb2cd8b0..19b501c50 100644 --- a/packages/deno/packages/plugin-relay/index.ts +++ b/packages/deno/packages/plugin-relay/index.ts @@ -15,7 +15,9 @@ export class PothosRelayPlugin extends BasePlugin, fieldConfig: PothosOutputFieldConfig): GraphQLFieldResolver { const argMappings = mapInputFields(fieldConfig.args, this.buildCache, (inputField) => { if (inputField.extensions?.isRelayGlobalID) { - return (inputField.extensions?.relayGlobalIDFor ?? true) as true | { + return (inputField.extensions?.relayGlobalIDFor ?? + inputField.extensions?.relayGlobalIDAlwaysParse ?? + false) as boolean | { typename: string; parseId: (id: string, ctx: object) => unknown; }[]; @@ -25,7 +27,7 @@ export class PothosRelayPlugin extends BasePlugin internalDecodeGlobalID(this.builder, String(globalID), ctx, info, Array.isArray(mappings.value) ? mappings.value : true)); + const argMapper = createInputValueMapper(argMappings, (globalID, mappings, ctx: Types["Context"], info: GraphQLResolveInfo) => internalDecodeGlobalID(this.builder, String(globalID), ctx, info, mappings.value ?? false)); return (parent, args, context, info) => resolver(parent, argMapper(args, undefined, context, info), context, info); } override wrapSubscribe(subscribe: GraphQLFieldResolver | undefined, fieldConfig: PothosOutputFieldConfig): GraphQLFieldResolver | undefined { diff --git a/packages/deno/packages/plugin-relay/schema-builder.ts b/packages/deno/packages/plugin-relay/schema-builder.ts index 57230920b..4d0aa554b 100644 --- a/packages/deno/packages/plugin-relay/schema-builder.ts +++ b/packages/deno/packages/plugin-relay/schema-builder.ts @@ -101,7 +101,12 @@ schemaBuilderProto.nodeInterfaceRef = function nodeInterfaceRef() { ...this.options.relayOptions.nodeQueryOptions, type: ref as InterfaceRef, args: { - id: t.arg.globalID({ required: true }), + id: t.arg.globalID({ + required: true, + extensions: { + relayGlobalIDAlwaysParse: true, + }, + }), }, resolve: resolveNodeFn ? (root, args, context, info) => resolveNodeFn(root, args as { @@ -134,7 +139,12 @@ schemaBuilderProto.nodeInterfaceRef = function nodeInterfaceRef() { ...this.options.relayOptions.nodesQueryOptions, type: [ref], args: { - ids: t.arg.globalIDList({ required: true }), + ids: t.arg.globalIDList({ + required: true, + extensions: { + relayGlobalIDAlwaysParse: true, + }, + }), }, resolve: resolveNodesFn ? (root, args, context, info) => resolveNodesFn(root, args as { diff --git a/packages/plugin-relay/src/index.ts b/packages/plugin-relay/src/index.ts index 25928321a..245863b7c 100644 --- a/packages/plugin-relay/src/index.ts +++ b/packages/plugin-relay/src/index.ts @@ -28,7 +28,7 @@ export class PothosRelayPlugin extends BasePlugin { if (inputField.extensions?.isRelayGlobalID) { return (inputField.extensions?.relayGlobalIDFor ?? - inputField.extensions?.alwaysParse ?? + inputField.extensions?.relayGlobalIDAlwaysParse ?? false) as boolean | { typename: string; parseId: (id: string, ctx: object) => unknown }[]; } diff --git a/packages/plugin-relay/src/schema-builder.ts b/packages/plugin-relay/src/schema-builder.ts index bfab4d94b..b7f06e831 100644 --- a/packages/plugin-relay/src/schema-builder.ts +++ b/packages/plugin-relay/src/schema-builder.ts @@ -161,7 +161,7 @@ schemaBuilderProto.nodeInterfaceRef = function nodeInterfaceRef() { id: t.arg.globalID({ required: true, extensions: { - alwaysParse: true, + relayGlobalIDAlwaysParse: true, }, }), }, @@ -206,7 +206,7 @@ schemaBuilderProto.nodeInterfaceRef = function nodeInterfaceRef() { ids: t.arg.globalIDList({ required: true, extensions: { - alwaysParse: true, + relayGlobalIDAlwaysParse: true, }, }), },