1 | import { RawResolversConfig } from '@graphql-codegen/visitor-plugin-common';
|
2 | /**
|
3 | * @description This plugin generates TypeScript signature for `resolve` functions of your GraphQL API.
|
4 | * You can use this plugin a to generate simple resolvers signature based on your GraphQL types, or you can change it's behavior be providing custom model types (mappers).
|
5 | *
|
6 | * You can find a blog post explaining the usage of this plugin here: https://the-guild.dev/blog/better-type-safety-for-resolvers-with-graphql-codegen
|
7 | *
|
8 | */
|
9 | export interface TypeScriptResolversPluginConfig extends RawResolversConfig {
|
10 | /**
|
11 | * @description Adds an index signature to any generates resolver.
|
12 | * @default false
|
13 | *
|
14 | * @exampleMarkdown
|
15 | * ```yml
|
16 | * generates:
|
17 | * path/to/file.ts:
|
18 | * plugins:
|
19 | * - typescript
|
20 | * - typescript-resolvers
|
21 | * config:
|
22 | * useIndexSignature: true
|
23 | * ```
|
24 | */
|
25 | useIndexSignature?: boolean;
|
26 | /**
|
27 | * @description Disables Schema Stitching support.
|
28 | *
|
29 | * Note: The default behavior will be reversed in the next major release. Support for Schema Stitching will be disabled by default.
|
30 | * @default false
|
31 | *
|
32 | * @exampleMarkdown
|
33 | * ```yml
|
34 | * generates:
|
35 | * path/to/file.ts:
|
36 | * plugins:
|
37 | * - typescript
|
38 | * - typescript-resolvers
|
39 | * config:
|
40 | * noSchemaStitching: true
|
41 | * ```
|
42 | */
|
43 | noSchemaStitching?: boolean;
|
44 | /**
|
45 | * @description Set to `true` in order to wrap field definitions with `FieldWrapper`.
|
46 | * This is useful to allow return types such as Promises and functions. Needed for
|
47 | * compatibility with `federation: true` when
|
48 | * @default true
|
49 | */
|
50 | wrapFieldDefinitions?: boolean;
|
51 | /**
|
52 | * @description You can provide your custom GraphQLResolveInfo instead of the default one from graphql-js
|
53 | * @default "graphql#GraphQLResolveInfo"
|
54 | *
|
55 | * @exampleMarkdown
|
56 | * ```yml
|
57 | * generates:
|
58 | * path/to/file.ts:
|
59 | * plugins:
|
60 | * - typescript
|
61 | * - typescript-resolvers
|
62 | * config:
|
63 | * customResolveInfo: ./my-types#MyResolveInfo
|
64 | * ```
|
65 | */
|
66 | customResolveInfo?: string;
|
67 | /**
|
68 | * @description You can provide your custom ResolveFn instead the default. It has to be a type that uses the generics <TResult, TParent, TContext, TArgs>
|
69 | * @default "(parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => Promise<TResult> | TResult"
|
70 | *
|
71 | * @exampleMarkdown
|
72 | * ## Custom Signature
|
73 | * ```yml
|
74 | * generates:
|
75 | * path/to/file.ts:
|
76 | * plugins:
|
77 | * - typescript
|
78 | * - typescript-resolvers
|
79 | * config:
|
80 | * customResolverFn: ./my-types#MyResolveFn
|
81 | * ```
|
82 | *
|
83 | * ## With Graphile
|
84 | * ```yml
|
85 | * generates:
|
86 | * path/to/file.ts:
|
87 | * plugins:
|
88 | * - add: "import { GraphileHelpers } from 'graphile-utils/node8plus/fieldHelpers';"
|
89 | * - typescript
|
90 | * - typescript-resolvers
|
91 | * config:
|
92 | * customResolverFn: |
|
93 | * (
|
94 | * parent: TParent,
|
95 | * args: TArgs,
|
96 | * context: TContext,
|
97 | * info: GraphQLResolveInfo & { graphile: GraphileHelpers<TParent> }
|
98 | * ) => Promise<TResult> | TResult;
|
99 | * ```
|
100 | */
|
101 | customResolverFn?: string;
|
102 | /**
|
103 | * @description Allow you to override the `ParentType` generic in each resolver, by avoid enforcing the base type of the generated generic type.
|
104 | *
|
105 | * This will generate `ParentType = Type` instead of `ParentType extends Type = Type` in each resolver.
|
106 | *
|
107 | * @exampleMarkdown
|
108 | * ```yml
|
109 | * config:
|
110 | * allowParentTypeOverride: true
|
111 | * ```
|
112 | *
|
113 | */
|
114 | allowParentTypeOverride?: boolean;
|
115 | /**
|
116 | * @description Sets `info` argument of resolver function to be optional field. Useful for testing.
|
117 | *
|
118 | * @exampleMarkdown
|
119 | * ```yml
|
120 | * config:
|
121 | * optionalInfoArgument: true
|
122 | * ```
|
123 | *
|
124 | */
|
125 | optionalInfoArgument?: boolean;
|
126 | }
|