mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:51:59 +00:00
* gulp: disable graphql-codegen's watch feature Due to https://github.com/dotansimha/graphql-code-generator/issues/1796, gulp is currently consuming a non-trivial amount of a CPU core watching for updates that regenerate the GraphQL operations files. Let's use Chokidar directly (via Gulp) and then we can be smarter about when we actually trigger the several second generation process. * Hush eslint. * Simplify logic and ensure graphql types are generated before first run of webpack Co-authored-by: Erik Seliger <erikseliger@me.com>
112 lines
3.2 KiB
JavaScript
112 lines
3.2 KiB
JavaScript
// @ts-check
|
|
|
|
const { generate } = require('@graphql-codegen/cli')
|
|
const path = require('path')
|
|
|
|
const ROOT_FOLDER = path.resolve(__dirname, '../../../')
|
|
|
|
const WEB_FOLDER = path.resolve(ROOT_FOLDER, './client/web')
|
|
const BROWSER_FOLDER = path.resolve(ROOT_FOLDER, './client/browser')
|
|
const SHARED_FOLDER = path.resolve(ROOT_FOLDER, './client/shared')
|
|
const SCHEMA_PATH = path.join(ROOT_FOLDER, './cmd/frontend/graphqlbackend/schema.graphql')
|
|
|
|
const SHARED_DOCUMENTS_GLOB = [`${SHARED_FOLDER}/src/**/*.{ts,tsx}`, `!${SHARED_FOLDER}/src/testing/**/*.*`]
|
|
|
|
const WEB_DOCUMENTS_GLOB = [
|
|
`${WEB_FOLDER}/src/**/*.{ts,tsx}`,
|
|
`!${WEB_FOLDER}/src/regression/**/*.*`,
|
|
`!${WEB_FOLDER}/src/end-to-end/**/*.*`,
|
|
]
|
|
|
|
const BROWSER_DOCUMENTS_GLOB = [
|
|
`${BROWSER_FOLDER}/src/**/*.{ts,tsx}`,
|
|
`!${BROWSER_FOLDER}/src/end-to-end/**/*.*`,
|
|
'!**/*.d.ts',
|
|
]
|
|
|
|
// Define ALL_DOCUMENTS_GLOB as the union of the previous glob arrays.
|
|
const ALL_DOCUMENTS_GLOB = [...new Set([...SHARED_DOCUMENTS_GLOB, ...WEB_DOCUMENTS_GLOB, ...BROWSER_DOCUMENTS_GLOB])]
|
|
|
|
const plugins = [`${SHARED_FOLDER}/dev/extractGraphQlOperationCodegenPlugin.js`, 'typescript', 'typescript-operations']
|
|
|
|
/**
|
|
* Generates TypeScript files with types for all GraphQL operations.
|
|
*/
|
|
async function generateGraphQlOperations() {
|
|
await generate(
|
|
{
|
|
schema: SCHEMA_PATH,
|
|
hooks: {
|
|
afterOneFileWrite: 'prettier --write',
|
|
},
|
|
errorsOnly: true,
|
|
config: {
|
|
preResolveTypes: true,
|
|
operationResultSuffix: 'Result',
|
|
omitOperationSuffix: true,
|
|
skipTypename: true,
|
|
namingConvention: {
|
|
typeNames: 'keep',
|
|
enumValues: 'keep',
|
|
transformUnderscore: true,
|
|
},
|
|
declarationKind: 'interface',
|
|
avoidOptionals: {
|
|
field: true,
|
|
inputValue: false,
|
|
object: true,
|
|
},
|
|
scalars: {
|
|
DateTime: 'string',
|
|
JSON: 'object',
|
|
JSONValue: 'unknown',
|
|
GitObjectID: 'string',
|
|
JSONCString: 'string',
|
|
PublishedValue: "boolean | 'draft'",
|
|
},
|
|
},
|
|
generates: {
|
|
[path.join(BROWSER_FOLDER, './src/graphql-operations.ts')]: {
|
|
documents: BROWSER_DOCUMENTS_GLOB,
|
|
config: {
|
|
onlyOperationTypes: true,
|
|
noExport: false,
|
|
enumValues: '../../shared/src/graphql-operations',
|
|
interfaceNameForOperations: 'BrowserGraphQlOperations',
|
|
},
|
|
plugins,
|
|
},
|
|
|
|
[path.join(WEB_FOLDER, './src/graphql-operations.ts')]: {
|
|
documents: WEB_DOCUMENTS_GLOB,
|
|
config: {
|
|
onlyOperationTypes: true,
|
|
noExport: false,
|
|
enumValues: '../../shared/src/graphql-operations',
|
|
interfaceNameForOperations: 'WebGraphQlOperations',
|
|
},
|
|
plugins,
|
|
},
|
|
|
|
[path.join(SHARED_FOLDER, './src/graphql-operations.ts')]: {
|
|
documents: SHARED_DOCUMENTS_GLOB,
|
|
config: {
|
|
onlyOperationTypes: true,
|
|
noExport: false,
|
|
interfaceNameForOperations: 'SharedGraphQlOperations',
|
|
},
|
|
plugins,
|
|
},
|
|
},
|
|
},
|
|
true
|
|
)
|
|
}
|
|
|
|
module.exports = {
|
|
generateGraphQlOperations,
|
|
SHARED_DOCUMENTS_GLOB,
|
|
WEB_DOCUMENTS_GLOB,
|
|
ALL_DOCUMENTS_GLOB,
|
|
}
|