Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds graphql resolve info to loader ts definition #917

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface Loader<
queries: Array<{
obj: TObj;
params: TParams;
info?: GraphQLResolveInfo;
}>,
context: TContext & {
reply: FastifyReply;
Expand Down
11 changes: 8 additions & 3 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
}
}
})
Expand Down