From d77deb59036912cc38ef2335e16fc737d6fe6f01 Mon Sep 17 00:00:00 2001 From: maruware Date: Mon, 21 Oct 2024 21:34:07 +0900 Subject: [PATCH 1/3] Fix ref relay options in plugin-prisma --- packages/plugin-prisma/src/schema-builder.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin-prisma/src/schema-builder.ts b/packages/plugin-prisma/src/schema-builder.ts index b16425e5f..9a7967c47 100644 --- a/packages/plugin-prisma/src/schema-builder.ts +++ b/packages/plugin-prisma/src/schema-builder.ts @@ -179,7 +179,7 @@ schemaBuilderProto.prismaNode = function prismaNode( this.configStore.onTypeConfig(ref, (nodeConfig) => { this.objectField( ref, - (this.options as { relayOptions?: { idFieldName?: string } }).relayOptions?.idFieldName ?? + (this.options as { relay?: { idFieldName?: string } }).relay?.idFieldName ?? 'id', (t) => ( @@ -187,7 +187,7 @@ schemaBuilderProto.prismaNode = function prismaNode( globalID: (options: Record) => FieldRef; } ).globalID({ - ...(this.options as { relayOptions?: { idFieldOptions?: object } }).relayOptions + ...(this.options as { relay?: { idFieldOptions?: object } }).relay ?.idFieldOptions, ...idOptions, nullable: false, From 2f91f2bc4aa230b54632f30983c316e9c808fbc3 Mon Sep 17 00:00:00 2001 From: maruware Date: Mon, 21 Oct 2024 21:40:36 +0900 Subject: [PATCH 2/3] Add changeset --- .changeset/cold-cups-love.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cold-cups-love.md diff --git a/.changeset/cold-cups-love.md b/.changeset/cold-cups-love.md new file mode 100644 index 000000000..c9913937a --- /dev/null +++ b/.changeset/cold-cups-love.md @@ -0,0 +1,5 @@ +--- +"@pothos/plugin-prisma": patch +--- + +Fix ref relay options in plugin-prisma From 54019c9b67ad45bb0bee3608fa56fa055ec9068d Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Mon, 21 Oct 2024 14:24:26 -0700 Subject: [PATCH 3/3] use builder.nodeRef in prisma plugin --- packages/plugin-prisma/src/schema-builder.ts | 46 ++++---------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/packages/plugin-prisma/src/schema-builder.ts b/packages/plugin-prisma/src/schema-builder.ts index 9a7967c47..d37af37a5 100644 --- a/packages/plugin-prisma/src/schema-builder.ts +++ b/packages/plugin-prisma/src/schema-builder.ts @@ -125,7 +125,6 @@ schemaBuilderProto.prismaNode = function prismaNode( }: PrismaNodeOptions, ) { const fieldName = field as unknown as string; - const interfaceRef = this.nodeInterfaceRef?.(); const resolve = rawResolve ?? getDefaultIDSerializer(type, fieldName, this); const idParser = fieldName ? getDefaultIDParser(type, fieldName, this) : undefined; const typeName = variant ?? name ?? type; @@ -135,16 +134,20 @@ schemaBuilderProto.prismaNode = function prismaNode( rawFindUnique(resolve(parent as never, context) as string, context) : ModelLoader.getFindUniqueForField(nodeRef, type, fieldName, this); - if (!interfaceRef) { - throw new PothosError('builder.prismaNode requires @pothos/plugin-relay to be installed'); - } - const extendedOptions = { ...options, name, variant, - interfaces: [interfaceRef], findUnique, + }; + + const ref = this.prismaObject(type, extendedOptions as never); + + (this as typeof this & { nodeRef: (ref: unknown, options: unknown) => unknown }).nodeRef(ref, { + id: { + ...idOptions, + resolve: (parent: never, _args: object, context: object) => resolve(parent, context), + }, loadWithoutCache: async ( id: string, context: SchemaTypes['Context'], @@ -168,37 +171,6 @@ schemaBuilderProto.prismaNode = function prismaNode( return record; }, - }; - - const ref = this.prismaObject(type, extendedOptions as never); - - if (options.interfaces) { - ref.addInterfaces(options.interfaces); - } - - this.configStore.onTypeConfig(ref, (nodeConfig) => { - this.objectField( - ref, - (this.options as { relay?: { idFieldName?: string } }).relay?.idFieldName ?? - 'id', - (t) => - ( - t as unknown as { - globalID: (options: Record) => FieldRef; - } - ).globalID({ - ...(this.options as { relay?: { idFieldOptions?: object } }).relay - ?.idFieldOptions, - ...idOptions, - nullable: false, - args: {}, - resolve: (parent: never, _args: object, context: object) => - completeValue(resolve(parent, context), (id) => ({ - type: nodeConfig.name, - id, - })), - }), - ); }); this.configStore.associateParamWithRef(nodeRef, ref);