Files
cypress/packages/graphql/script/codegen-mount-ts.ts
Tim Griesser a851d797a8 feat: improved DX for unified-desktop-gui (#18099)
- Moves graphql-codegen config to the root, which will serve all packages needing it
- Adds gulpfile for coordinating scripts related to dev environment in launchpad app
- yarn dev from the root runs yarn gulp dev, which:
  Runs autobarrel for rolling up the @packages/graphql files
  Cleans the dist & cache for .vite
  Starts the a codegen watcher for Nexus
  Starts the graphql-codegen --watch & highlights output
  Starts vite servers for launchpad & app
  Starts electron watch.js
2021-09-15 11:54:14 -04:00

68 lines
2.0 KiB
TypeScript

import type { CodegenPlugin } from '@graphql-codegen/plugin-helpers'
import { isInterfaceType, isObjectType } from 'graphql'
import path from 'path'
const plugin: CodegenPlugin<any> = {
plugin: (schema, documents, config, info) => {
const typesMap = schema.getTypeMap()
let typeMap: string[] = []
let objects: string[] = []
for (const [typeName, type] of Object.entries(typesMap)) {
if (!typeName.startsWith('__') && isObjectType(type) || isInterfaceType(type)) {
typeMap.push(` ${typeName}: NexusGenObjects['${typeName}'],`)
if (isObjectType(type)) {
objects.push(typeName)
}
}
}
return [
`// Generated by ${path.basename(__filename)}, do not edit directly`,
`import type { NexusGenObjects } from '@packages/graphql/src/gen/nxs.gen'`,
`export interface TestSourceTypeLookup {`,
typeMap.join('\n'),
`}`,
`
import { list, nonNull, queryField, unionType } from 'nexus'
export const testUnionType = unionType({
name: 'TestUnion',
definition (t) {
// !!! Generated by ${path.basename(__filename)}, do not edit directly !!!
t.members(
${objects.map((o) => `'${o}'`).join(',\n ')}
)
// !!! Generated by ${path.basename(__filename)}, do not edit directly !!!
},
resolveType (c) {
// @ts-ignore
return c.__typename ?? c.constructor.name
},
})
// !!! Generated by ${path.basename(__filename)}, do not edit directly !!!
export const testFragmentMember = queryField('testFragmentMember', {
description: 'Provides a fragment target for testing',
type: nonNull(testUnionType),
resolve: (source) => {
return source
}
})
// !!! Generated by ${path.basename(__filename)}, do not edit directly !!!
export const testFragmentMemberList = queryField('testFragmentMemberList', {
description: 'Provides a fragment target list for testing',
type: list(nonNull(testUnionType)),
resolve: (source) => {
return source
}
})
`,
].join('\n')
},
}
export default plugin