-
Notifications
You must be signed in to change notification settings - Fork 3
/
graphql.config.ts
89 lines (82 loc) · 3.52 KB
/
graphql.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { ModulesConfig } from '@graphql-codegen/graphql-modules-preset/config';
import type { NearOperationFileConfig } from '@graphql-codegen/near-operation-file-preset';
import type { Types as CodegenTypes } from '@graphql-codegen/plugin-helpers';
import type { TypeScriptTypedDocumentNodesConfig } from '@graphql-codegen/typed-document-node';
import type { TypeScriptPluginConfig } from '@graphql-codegen/typescript';
import type { TypeScriptDocumentsPluginConfig } from '@graphql-codegen/typescript-operations';
import type { TypeScriptResolversPluginConfig } from '@graphql-codegen/typescript-resolvers';
import type { IGraphQLConfig } from 'graphql-config';
type BackendConfig = TypeScriptPluginConfig & TypeScriptResolversPluginConfig;
type FrontendConfig = TypeScriptPluginConfig &
TypeScriptDocumentsPluginConfig &
TypeScriptTypedDocumentNodesConfig;
// Give intellisense to inline object(s)
const ident = <T>(value: T): T => value;
const graphqlModulesPath = 'backend/src/graphql/modules/';
const graphqlExtension = '{gql,graphql}';
const graphqlSchema = `${graphqlModulesPath}**/*.${graphqlExtension}` as const;
const frontendSrcPath = 'frontend/src/';
const frontendSchemaFile = 'schema.ts';
const frontendSchemaPath = `${frontendSrcPath}${frontendSchemaFile}` as const;
const graphqlConfig: IGraphQLConfig = {
projects: {
backend: {
schema: graphqlSchema,
extensions: {
codegen: ident<CodegenTypes.Config>({
config: ident<BackendConfig>({
contextType: 'GraphQLModules.Context',
optionalResolveType: true, // make `__resolveType` field optional
useIndexSignature: true, // required for compatibility with apollo server
defaultMapper: 'Partial<{T}>',
}),
generates: ident({
[graphqlModulesPath]: {
preset: 'graphql-modules',
presetConfig: ident<ModulesConfig>({
baseTypesPath: 'generated.schema.ts',
encapsulateModuleTypes: 'none',
filename: 'generated.types.ts',
}),
plugins: ['typescript', 'typescript-resolvers'],
},
}),
}),
},
},
frontend: {
schema: [
graphqlSchema,
`${frontendSrcPath}client.schema.${graphqlExtension}`,
],
documents: `${frontendSrcPath}components/**/*.${graphqlExtension}`,
extensions: {
codegen: ident<CodegenTypes.Config>({
config: ident<FrontendConfig>({
constEnums: true, // use `const enum` to define unions
declarationKind: 'interface', // use `interface` keyword to define types
immutableTypes: true, // add `readonly` keyword to frozen objects
namingConvention: 'keep', // don't rename types
dedupeOperationSuffix: true, // prevent `MyQueryQuery`
documentVariableSuffix: '', // export `MyQuery` instead of `MyQueryDocument`
operationResultSuffix: 'Data', // add `Data` suffix to result types
}),
generates: ident({
[frontendSchemaPath]: {
plugins: ['typescript'],
},
[frontendSrcPath]: {
preset: 'near-operation-file',
presetConfig: ident<NearOperationFileConfig>({
baseTypesPath: frontendSchemaFile,
extension: '.graphql.ts',
}),
plugins: ['typescript-operations', 'typed-document-node'],
},
}),
}),
},
},
},
};
export default graphqlConfig;