UNPKG

4.85 kBTypeScriptView Raw
1import { 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 to generate simple resolvers signature based on your GraphQL types, or you can change its 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 */
9export interface TypeScriptResolversPluginConfig extends RawResolversConfig {
10 /**
11 * @description Adds an index signature to any generates resolver.
12 * @default false
13 *
14 * @exampleMarkdown
15 * ```yaml
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/Enables Schema Stitching support.
28 * By default, the resolver signature does not include the support for schema-stitching.
29 * Set to `false` to enable that.
30 *
31 * @default true
32 * @exampleMarkdown
33 * ```yaml
34 * generates:
35 * path/to/file.ts:
36 * plugins:
37 * - typescript
38 * - typescript-resolvers
39 * config:
40 * noSchemaStitching: false
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 * ```yaml
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 *
74 * ```yaml
75 * generates:
76 * path/to/file.ts:
77 * plugins:
78 * - typescript
79 * - typescript-resolvers
80 * config:
81 * customResolverFn: ./my-types#MyResolveFn
82 * ```
83 *
84 * ## With Graphile
85 *
86 * ```yaml
87 * generates:
88 * path/to/file.ts:
89 * plugins:
90 * - add:
91 * content: "import { GraphileHelpers } from 'graphile-utils/node8plus/fieldHelpers';"
92 * - typescript
93 * - typescript-resolvers
94 * config:
95 * customResolverFn: |
96 * (
97 * parent: TParent,
98 * args: TArgs,
99 * context: TContext,
100 * info: GraphQLResolveInfo & { graphile: GraphileHelpers<TParent> }
101 * ) => Promise<TResult> | TResult;
102 * ```
103 */
104 customResolverFn?: string;
105 /**
106 * @description Map the usage of a directive into using a specific resolver.
107 * @exampleMarkdown
108 * ```yaml
109 * config:
110 * customResolverFn: ../resolver-types.ts#UnauthenticatedResolver
111 * directiveResolverMappings:
112 * authenticated: ../resolvers-types.ts#AuthenticatedResolver
113 * ```
114 */
115 directiveResolverMappings?: Record<string, string>;
116 /**
117 * @description Allow you to override the `ParentType` generic in each resolver, by avoid enforcing the base type of the generated generic type.
118 *
119 * This will generate `ParentType = Type` instead of `ParentType extends Type = Type` in each resolver.
120 *
121 * @exampleMarkdown
122 * ```yaml
123 * config:
124 * allowParentTypeOverride: true
125 * ```
126 *
127 */
128 allowParentTypeOverride?: boolean;
129 /**
130 * @description Sets `info` argument of resolver function to be optional field. Useful for testing.
131 *
132 * @exampleMarkdown
133 * ```yaml
134 * config:
135 * optionalInfoArgument: true
136 * ```
137 *
138 */
139 optionalInfoArgument?: boolean;
140 /**
141 * @description Set to `true` in order to allow the Resolver type to be callable
142 *
143 * @exampleMarkdown
144 * ```yaml
145 * config:
146 * makeResolverTypeCallable: true
147 * ```
148 */
149 makeResolverTypeCallable?: boolean;
150}