@@ -26,6 +26,7 @@ import {
26
26
TokenKind ,
27
27
GraphQLEnumValueConfigMap ,
28
28
GraphQLFieldConfigArgumentMap ,
29
+ valueFromASTUntyped ,
29
30
} from 'graphql' ;
30
31
31
32
import { graphqlVersion } from '../utils/index' ;
@@ -67,12 +68,13 @@ export default function typeFromAST(
67
68
function makeObjectType ( node : ObjectTypeDefinitionNode ) : GraphQLObjectType {
68
69
const config = {
69
70
name : node . name . value ,
70
- fields : ( ) => makeFields ( node . fields ) ,
71
+ description : getDescription ( node , backcompatOptions ) ,
71
72
interfaces : ( ) =>
72
73
node . interfaces . map ( ( iface ) =>
73
74
createNamedStub ( iface . name . value , 'interface' ) ,
74
75
) ,
75
- description : getDescription ( node , backcompatOptions ) ,
76
+ fields : ( ) => makeFields ( node . fields ) ,
77
+ astNode : node ,
76
78
} ;
77
79
return new GraphQLObjectType ( config ) ;
78
80
}
@@ -82,16 +84,17 @@ function makeInterfaceType(
82
84
) : GraphQLInterfaceType {
83
85
const config = {
84
86
name : node . name . value ,
85
- fields : ( ) => makeFields ( node . fields ) ,
87
+ description : getDescription ( node , backcompatOptions ) ,
86
88
interfaces :
87
89
graphqlVersion ( ) >= 15
88
90
? ( ) =>
89
91
( ( node as unknown ) as ObjectTypeDefinitionNode ) . interfaces . map (
90
92
( iface ) => createNamedStub ( iface . name . value , 'interface' ) ,
91
93
)
92
94
: undefined ,
93
- description : getDescription ( node , backcompatOptions ) ,
95
+ fields : ( ) => makeFields ( node . fields ) ,
94
96
resolveType : ( parent : any ) => resolveFromParentTypename ( parent ) ,
97
+ astNode : node ,
95
98
} ;
96
99
return new GraphQLInterfaceType ( config ) ;
97
100
}
@@ -109,18 +112,20 @@ function makeEnumType(node: EnumTypeDefinitionNode): GraphQLEnumType {
109
112
110
113
return new GraphQLEnumType ( {
111
114
name : node . name . value ,
112
- values,
113
115
description : getDescription ( node , backcompatOptions ) ,
116
+ values,
117
+ astNode : node ,
114
118
} ) ;
115
119
}
116
120
117
121
function makeUnionType ( node : UnionTypeDefinitionNode ) : GraphQLUnionType {
118
122
return new GraphQLUnionType ( {
119
123
name : node . name . value ,
124
+ description : getDescription ( node , backcompatOptions ) ,
120
125
types : ( ) =>
121
126
node . types . map ( ( type ) => createNamedStub ( type . name . value , 'object' ) ) ,
122
- description : getDescription ( node , backcompatOptions ) ,
123
127
resolveType : ( parent ) => resolveFromParentTypename ( parent ) ,
128
+ astNode : node ,
124
129
} ) ;
125
130
}
126
131
@@ -135,6 +140,7 @@ function makeScalarType(node: ScalarTypeDefinitionNode): GraphQLScalarType {
135
140
// always pass validation.
136
141
parseValue : ( ) => false ,
137
142
parseLiteral : ( ) => false ,
143
+ astNode : node ,
138
144
} ) ;
139
145
}
140
146
@@ -143,8 +149,9 @@ function makeInputObjectType(
143
149
) : GraphQLInputObjectType {
144
150
return new GraphQLInputObjectType ( {
145
151
name : node . name . value ,
146
- fields : ( ) => makeValues ( node . fields ) ,
147
152
description : getDescription ( node , backcompatOptions ) ,
153
+ fields : ( ) => makeValues ( node . fields ) ,
154
+ astNode : node ,
148
155
} ) ;
149
156
}
150
157
@@ -169,9 +176,10 @@ function makeFields(
169
176
...prev ,
170
177
[ node . name . value ] : {
171
178
type : createStub ( node . type , 'output' ) ,
172
- args : makeValues ( node . arguments ) ,
173
179
description : getDescription ( node , backcompatOptions ) ,
180
+ args : makeValues ( node . arguments ) ,
174
181
deprecationReason,
182
+ astNode : node ,
175
183
} ,
176
184
} ;
177
185
} , { } ) ;
@@ -185,8 +193,9 @@ function makeValues(
185
193
...prev ,
186
194
[ node . name . value ] : {
187
195
type : createStub ( node . type , 'input' ) ,
188
- defaultValue : node . defaultValue ,
196
+ defaultValue : valueFromASTUntyped ( node . defaultValue ) ,
189
197
description : getDescription ( node , backcompatOptions ) ,
198
+ astNode : node ,
190
199
} ,
191
200
} ) ,
192
201
{ } ,
@@ -203,8 +212,10 @@ function makeDirective(node: DirectiveDefinitionNode): GraphQLDirective {
203
212
return new GraphQLDirective ( {
204
213
name : node . name . value ,
205
214
description : node . description != null ? node . description . value : null ,
206
- args : makeValues ( node . arguments ) ,
207
215
locations,
216
+ isRepeatable : node . repeatable ,
217
+ args : makeValues ( node . arguments ) ,
218
+ astNode : node ,
208
219
} ) ;
209
220
}
210
221
0 commit comments