-
Notifications
You must be signed in to change notification settings - Fork 0
/
codegen.ts
107 lines (99 loc) · 4.45 KB
/
codegen.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// #region Environment variable file parsing
// Environment file parsing and updating
import * as DotEnv from 'dotenv'
import { expand } from 'dotenv-expand'
import path from 'node:path'
import fs from 'node:fs'
import figures from 'figures'
import chalk from 'chalk'
// Process environment files, to ensure the enviornment configuration is applied
const envFiles : string[] = [".env", ".env.local"]
if (process.env.NODE_ENV) {
envFiles.push(`.env.${ process.env.NODE_ENV }`)
envFiles.push(`.env.${ process.env.NODE_ENV }.local`)
}
envFiles.map(s => path.join(process.cwd(), s)).filter(s => fs.existsSync(s)).reverse().forEach(fileName => {
var result = DotEnv.config({ path: fileName, override: false })
expand(result)
console.log(`${ chalk.greenBright(figures.tick) } Processed ${fileName}`)
})
// #endregion
// Actual code generation setup
import type { CodegenConfig } from '@graphql-codegen/cli'
import getSchemaInfo from '@remkoj/optimizely-graph-client/codegen'
import OptimizelyGraphPreset, {type PresetOptions as OptimizelyGraphPresetOptions} from '@remkoj/optimizely-graph-functions/preset'
// Create the configuration itself
const config: CodegenConfig = {
schema: getSchemaInfo(),
// Allow & parse GraphQL Queries from anywhere within the codebase
documents: [
// Add local GraphQL files
'src/**/*.graphql',
// Add Definitions from components
'src/**/!(*.d).{ts,tsx}'
],
generates: {
'./src/gql/': {
preset: OptimizelyGraphPreset,
presetConfig: {
// By default the preset will generate recursive queries
// untill multiple recursions are supported, this needs to
// be disabled when there's more then one component that
// will use recursion
recursion: false,
// The GQL tag to be used to identify inline GraphQL queries
gqlTagName: 'gql',
// Configure the fragments that will be spread into the utility
// partial fragments. You can use any fragment here, however the
// system is designed for the following receiving fragments:
// - PageData => For all page-level components
// - BlockData => For everyting that can be rendered as individual component
// - ElementData => For all element types that are useable within Visual Builder
injections: [
{
// Add from all Pages, within code
into: "PageData",
pathRegex: "src\/components\/cms\/page\/.*\.[tj]s(x){0,1}$"
},
{
// Add from all Experiences, within code
into: "PageData",
pathRegex: "src\/components\/cms\/experience\/.*\.[tj]s(x){0,1}$"
},
{
// Add from all Blocks, within code
into: "BlockData",
pathRegex: "src\/components\/cms\/component\/.*\.[tj]s(x){0,1}$"
},
{
// Add from all Elements, within code
into: "ElementData",
pathRegex: "src\/components\/cms\/element\/.*\.[tj]s(x){0,1}$"
},
{
// Add from all Pages, as .page.graphql file
into: "PageData",
pathRegex: "src\/components\/cms\/.*\.page\.graphql$"
},
{
// Add from all Experiences, as .experience.graphql file
into: "PageData",
pathRegex: "src\/components\/cms\/.*\.experience\.graphql$"
},
{
// Add from all Blocks, as .component.graphql file
into: "BlockData",
pathRegex: "src\/components\/cms\/.*\.component\.graphql$"
},
{
// Add from all Elements, as .element.graphql file
into: "ElementData",
pathRegex: "src\/components\/cms\/.*\.element\.graphql$"
}
],
} as OptimizelyGraphPresetOptions
}
},
ignoreNoDocuments: false
}
export default config