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
9 changes: 8 additions & 1 deletion packages/mercurius-codegen/src/mercuriusLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ export const MercuriusLoadersPlugin: CodegenPlugin<MercuriusLoadersPluginConfig>
if (type instanceof GraphQLObjectType) {
const fields = type.getFields()

const typeCode: Record<string, string> = {}
const typeCode: Record<string, string> = {
__resolveReference: `LoaderResolver<${namespacedImportPrefix}${
config.loadersCustomParentTypes?.[type.name] || type.name
},${namespacedImportPrefix}${
config.loadersCustomParentTypes?.[type.name] || type.name
},{}, TContext>`,
}

Object.entries(fields).forEach(([key, value]) => {
const tsType = fieldToType(value)

Expand Down
2 changes: 2 additions & 0 deletions packages/mercurius-codegen/test/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export interface Loaders<
}
> {
Human?: {
__resolveReference?: LoaderResolver<Human, Human, {}, TContext>
name?: LoaderResolver<Scalars['String'], Human, {}, TContext>
father?: LoaderResolver<Maybe<Human>, Human, {}, TContext>
hasSon?: LoaderResolver<
Expand Down Expand Up @@ -342,6 +343,7 @@ export interface Loaders<
}

NArray?: {
__resolveReference?: LoaderResolver<NArray, NArray, {}, TContext>
nArray?: LoaderResolver<
Maybe<Array<Maybe<Array<Maybe<Scalars['Int']>>>>>,
NArray,
Expand Down
14 changes: 11 additions & 3 deletions packages/mercurius-codegen/test/snapshots/index.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Generated by [AVA](https://avajs.dev).
}␊
export interface Loaders<TContext = import("mercurius").MercuriusContext & { reply: import("fastify").FastifyReply }> {␊
Human?: {␊
name?: LoaderResolver<Scalars["String"],TP_Types.Human,{}, TContext>;father?: LoaderResolver<Maybe<Human>,TP_Types.Human,{}, TContext>;hasSon?: LoaderResolver<Maybe<Scalars["Boolean"]>,TP_Types.Human,TP_Types.HumanhasSonArgs, TContext>;sons?: LoaderResolver<Array<Maybe<Human>>,TP_Types.Human,TP_Types.HumansonsArgs, TContext>;confirmedSonsNullable?: LoaderResolver<Maybe<Array<Human>>,TP_Types.Human,TP_Types.HumanconfirmedSonsNullableArgs, TContext>;confirmedSonsNonNullItems?: LoaderResolver<Array<Human>,TP_Types.Human,TP_Types.HumanconfirmedSonsNonNullItemsArgs, TContext>;sonNames?: LoaderResolver<Maybe<Array<Maybe<Scalars["String"]>>>,TP_Types.Human,{}, TContext>;nonNullssonNames?: LoaderResolver<Array<Scalars["String"]>,TP_Types.Human,{}, TContext>;␊
__resolveReference?: LoaderResolver<TP_Types.Human,TP_Types.Human,{}, TContext>;name?: LoaderResolver<Scalars["String"],TP_Types.Human,{}, TContext>;father?: LoaderResolver<Maybe<Human>,TP_Types.Human,{}, TContext>;hasSon?: LoaderResolver<Maybe<Scalars["Boolean"]>,TP_Types.Human,TP_Types.HumanhasSonArgs, TContext>;sons?: LoaderResolver<Array<Maybe<Human>>,TP_Types.Human,TP_Types.HumansonsArgs, TContext>;confirmedSonsNullable?: LoaderResolver<Maybe<Array<Human>>,TP_Types.Human,TP_Types.HumanconfirmedSonsNullableArgs, TContext>;confirmedSonsNonNullItems?: LoaderResolver<Array<Human>,TP_Types.Human,TP_Types.HumanconfirmedSonsNonNullItemsArgs, TContext>;sonNames?: LoaderResolver<Maybe<Array<Maybe<Scalars["String"]>>>,TP_Types.Human,{}, TContext>;nonNullssonNames?: LoaderResolver<Array<Scalars["String"]>,TP_Types.Human,{}, TContext>;␊
};␊
NArray?: {␊
nArray?: LoaderResolver<Maybe<Array<Maybe<Array<Maybe<Scalars["Int"]>>>>>,TP_Types.NArray,{}, TContext>;␊
__resolveReference?: LoaderResolver<TP_Types.NArray,TP_Types.NArray,{}, TContext>;nArray?: LoaderResolver<Maybe<Array<Maybe<Array<Maybe<Scalars["Int"]>>>>>,TP_Types.NArray,{}, TContext>;␊
};␊
}`

Expand Down Expand Up @@ -346,6 +346,7 @@ Generated by [AVA](https://avajs.dev).
}␊
> {␊
Human?: {␊
__resolveReference?: LoaderResolver<Human, Human, {}, TContext>␊
name?: LoaderResolver<Scalars['String'], Human, {}, TContext>␊
father?: LoaderResolver<Maybe<Human>, Human, {}, TContext>␊
hasSon?: LoaderResolver<␊
Expand Down Expand Up @@ -382,6 +383,7 @@ Generated by [AVA](https://avajs.dev).
}␊
NArray?: {␊
__resolveReference?: LoaderResolver<NArray, NArray, {}, TContext>␊
nArray?: LoaderResolver<␊
Maybe<Array<Maybe<Array<Maybe<Scalars['Int']>>>>>,␊
NArray,␊
Expand All @@ -399,7 +401,7 @@ Generated by [AVA](https://avajs.dev).

## supports addUnderscoreToArgsType config option

> addUnderscoreToArgsType code
> generated code

`import type {␊
GraphQLResolveInfo,␊
Expand Down Expand Up @@ -708,6 +710,7 @@ Generated by [AVA](https://avajs.dev).
}␊
> {␊
Human?: {␊
__resolveReference?: LoaderResolver<Human, Human, {}, TContext>␊
name?: LoaderResolver<Scalars['String'], Human, {}, TContext>␊
father?: LoaderResolver<Maybe<Human>, Human, {}, TContext>␊
hasSon?: LoaderResolver<␊
Expand Down Expand Up @@ -744,6 +747,7 @@ Generated by [AVA](https://avajs.dev).
}␊
NArray?: {␊
__resolveReference?: LoaderResolver<NArray, NArray, {}, TContext>␊
nArray?: LoaderResolver<␊
Maybe<Array<Maybe<Array<Maybe<Scalars['Int']>>>>>,␊
NArray,␊
Expand Down Expand Up @@ -1089,6 +1093,7 @@ Generated by [AVA](https://avajs.dev).
}␊
> {␊
Human?: {␊
__resolveReference?: LoaderResolver<Human, Human, {}, TContext>␊
name?: LoaderResolver<Scalars['String'], Human, {}, TContext>␊
father?: LoaderResolver<Maybe<Human>, Human, {}, TContext>␊
hasSon?: LoaderResolver<␊
Expand Down Expand Up @@ -1125,6 +1130,7 @@ Generated by [AVA](https://avajs.dev).
}␊
NArray?: {␊
__resolveReference?: LoaderResolver<NArray, NArray, {}, TContext>␊
nArray?: LoaderResolver<␊
Maybe<Array<Maybe<Array<Maybe<Scalars['Int']>>>>>,␊
NArray,␊
Expand Down Expand Up @@ -1468,6 +1474,7 @@ Generated by [AVA](https://avajs.dev).
}␊
> {␊
Human?: {␊
__resolveReference?: LoaderResolver<Human, Human, {}, TContext>␊
name?: LoaderResolver<Scalars['String'], Human, {}, TContext>␊
father?: LoaderResolver<Maybe<Human>, Human, {}, TContext>␊
hasSon?: LoaderResolver<␊
Expand Down Expand Up @@ -1504,6 +1511,7 @@ Generated by [AVA](https://avajs.dev).
}␊
NArray?: {␊
__resolveReference?: LoaderResolver<NArray, NArray, {}, TContext>␊
nArray?: LoaderResolver<␊
Maybe<Array<Maybe<Array<Maybe<Scalars['Int']>>>>>,␊
NArray,␊
Expand Down
Binary file modified packages/mercurius-codegen/test/snapshots/index.test.ts.snap
Binary file not shown.