|
7 | 7 | isTypeSystemExtensionNode, |
8 | 8 | parse, |
9 | 9 | } from 'graphql'; |
10 | | -import { AllTypes, ParserField, ParserTree, TypeDefinitionDisplayMap } from '@/Models'; |
| 10 | +import { AllTypes, ParserField, ParserTree, TypeDefinitionDisplayMap, Options } from '@/Models'; |
11 | 11 | import { Directive, Helpers, OperationType, TypeDefinition, TypeExtension } from '@/Models/Spec'; |
12 | 12 | import { TypeResolver } from './typeResolver'; |
13 | 13 | import { ParserUtils } from './ParserUtils'; |
@@ -36,18 +36,19 @@ export class Parser { |
36 | 36 | type: |
37 | 37 | d.kind === 'DirectiveDefinition' |
38 | 38 | ? { |
39 | | - name: TypeDefinitionDisplayMap[d.kind], |
| 39 | + fieldType: { name: TypeDefinitionDisplayMap[d.kind], type: Options.name }, |
40 | 40 | directiveOptions: d.locations.map((l) => l.value as Directive), |
41 | 41 | } |
42 | 42 | : { |
43 | | - name: TypeDefinitionDisplayMap[d.kind], |
| 43 | + fieldType: { name: TypeDefinitionDisplayMap[d.kind], type: Options.name }, |
44 | 44 | }, |
45 | 45 | data: { |
46 | 46 | type: d.kind as AllTypes, |
47 | 47 | }, |
48 | | - description: 'description' in d && d.description ? d.description.value : '', |
49 | | - interfaces: 'interfaces' in d && d.interfaces ? d.interfaces.map((i) => i.name.value) : undefined, |
50 | | - directives: 'directives' in d && d.directives ? TypeResolver.iterateDirectives(d.directives) : undefined, |
| 48 | + |
| 49 | + ...('description' in d && d.description?.value ? { description: d.description.value } : {}), |
| 50 | + interfaces: 'interfaces' in d && d.interfaces ? d.interfaces.map((i) => i.name.value) : [], |
| 51 | + directives: 'directives' in d && d.directives ? TypeResolver.iterateDirectives(d.directives) : [], |
51 | 52 | args: TypeResolver.resolveFieldsFromDefinition(d), |
52 | 53 | }; |
53 | 54 | } |
@@ -94,19 +95,22 @@ export class Parser { |
94 | 95 | .filter((t) => 'name' in t && t.name && !excludeRoots.includes(t.name.value)) |
95 | 96 | .map(Parser.documentDefinitionToSerializedNodeTree) |
96 | 97 | .filter((d) => !!d) as ParserField[]; |
97 | | - const comments: ParserField[] = Parser.findComments(schema).map( |
98 | | - (description) => |
99 | | - ({ |
| 98 | + const comments: ParserField[] = Parser.findComments(schema).map((description) => ({ |
| 99 | + name: Helpers.Comment, |
| 100 | + type: { |
| 101 | + fieldType: { |
100 | 102 | name: Helpers.Comment, |
101 | | - type: { |
102 | | - name: Helpers.Comment, |
103 | | - }, |
104 | | - data: { |
105 | | - type: Helpers.Comment, |
106 | | - }, |
107 | | - description, |
108 | | - } as ParserField), |
109 | | - ); |
| 103 | + type: Options.name, |
| 104 | + }, |
| 105 | + }, |
| 106 | + args: [], |
| 107 | + directives: [], |
| 108 | + interfaces: [], |
| 109 | + data: { |
| 110 | + type: Helpers.Comment, |
| 111 | + }, |
| 112 | + description, |
| 113 | + })); |
110 | 114 | const nodeTree: ParserTree = { |
111 | 115 | nodes: [...comments, ...nodes], |
112 | 116 | }; |
@@ -137,15 +141,9 @@ export class Parser { |
137 | 141 | if (!extendedNode) { |
138 | 142 | throw new Error(`Invalid extension node`); |
139 | 143 | } |
140 | | - if (e.directives) { |
141 | | - extendedNode.directives = [...(extendedNode.directives || []), ...e.directives]; |
142 | | - } |
143 | | - if (e.interfaces) { |
144 | | - extendedNode.interfaces = [...(extendedNode.interfaces || []), ...e.interfaces]; |
145 | | - } |
146 | | - if (e.args) { |
147 | | - extendedNode.args = [...(extendedNode.args || []), ...e.args]; |
148 | | - } |
| 144 | + extendedNode.directives = [...(extendedNode.directives || []), ...e.directives]; |
| 145 | + extendedNode.interfaces = [...(extendedNode.interfaces || []), ...e.interfaces]; |
| 146 | + extendedNode.args = [...(extendedNode.args || []), ...e.args]; |
149 | 147 | }); |
150 | 148 |
|
151 | 149 | return { nodes }; |
|
0 commit comments