forked from graphql-nexus/nexus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
58 lines (55 loc) · 1.44 KB
/
schema.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
import { makeSchema } from 'nexus'
import { GraphQLNamedType, isObjectType } from 'graphql'
import path from 'path'
import * as types from './types'
export const schema = makeSchema({
types,
outputs: {
schema: path.join(__dirname, '../ts-ast-reader-schema.graphql'),
typegen: path.join(__dirname, 'ts-ast-reader-typegen.ts'),
},
sourceTypes: {
modules: [
{
alias: 'ts',
module: 'typescript',
glob: false,
typeMatch: tsTypeMatch,
},
{
alias: 't',
module: path.join(__dirname, './types/index.ts'),
onlyTypes: [],
},
],
mapping: {
Token: 'ts.Token<any>',
},
// debug: true,
},
contextType: {
module: path.join(__dirname, './types/context.ts'),
export: 'ContextType',
},
prettierConfig: require.resolve('../../../.prettierrc'),
nonNullDefaults: {
output: true,
},
features: {
abstractTypeStrategies: {
resolveType: true,
},
},
})
/**
* When the type is a "Node", we want to first look for types with the name `Node`, e.g. TypeReferenceNode vs
* TypeReference
*/
function tsTypeMatch(type: GraphQLNamedType, defaultMatch: RegExp) {
if (isNodeType(type)) {
return [new RegExp(`(?:interface|type|class)\\s+(${type.name}Node)\\W`, 'g'), defaultMatch]
}
return defaultMatch
}
const isNodeType = (type: GraphQLNamedType) =>
Boolean(isObjectType(type) && type.getInterfaces().find((i) => i.name === 'Node'))