From 3c31062ee92ff7f6c333dbb9256f58ba16a64e69 Mon Sep 17 00:00:00 2001 From: dsoffiantini Date: Tue, 15 Nov 2022 14:01:38 -0700 Subject: [PATCH 1/2] feat: adds graphql resolve info to loader ts definition --- index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/index.d.ts b/index.d.ts index 5673216c..ce22e7ea 100644 --- a/index.d.ts +++ b/index.d.ts @@ -48,6 +48,7 @@ export interface Loader< queries: Array<{ obj: TObj; params: TParams; + info?: GraphQLResolveInfo; }>, context: TContext & { reply: FastifyReply; From 6a40bbb7f18bfe7aa2afc8c2ea75725f367739b1 Mon Sep 17 00:00:00 2001 From: dsoffiantini Date: Wed, 16 Nov 2022 18:06:23 -0700 Subject: [PATCH 2/2] test: :white_check_mark: adds test for loader info --- test/types/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/types/index.ts b/test/types/index.ts index 3e56828d..1c93925e 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -8,7 +8,7 @@ import { Readable } from 'stream' // eslint-disable-next-line no-unused-vars import mercurius, { MercuriusOptions, IResolvers, MercuriusContext, MercuriusServiceMetadata, MercuriusPlugin } from '../..' // eslint-disable-next-line no-unused-vars -import { DocumentNode, ExecutionResult, GraphQLSchema, ValidationContext, ValidationRule } from 'graphql' +import { DocumentNode, ExecutionResult, GraphQLResolveInfo, GraphQLSchema, ValidationContext, ValidationRule } from 'graphql' import { makeExecutableSchema } from '@graphql-tools/schema' import { mapSchema } from '@graphql-tools/utils' import mq from 'mqemitter' @@ -193,8 +193,13 @@ app.register(async function (app) { }) app.graphql.defineLoaders({ Dog: { - owner: async (queries: Array<{ obj: { name: keyof typeof owners }, params: {a: string} }>, _ctx) => { - return queries.map(({ obj }) => owners[obj.name]) + owner: { + async loader(queries: Array<{ obj: { name: keyof typeof owners }, params: {a: string}, info?: GraphQLResolveInfo }>, _ctx) { + return queries.map(({ obj }) => owners[obj.name]) + }, + opts: { + cache: false + } } } })