|
3 | 3 | GraphQLArgument,
|
4 | 4 | getNamedType,
|
5 | 5 | GraphQLNamedType,
|
| 6 | + isIntrospectionType, |
6 | 7 | } from 'graphql'
|
7 | 8 | import { IMiddlewareFunction } from 'graphql-middleware'
|
8 | 9 |
|
@@ -46,6 +47,12 @@ function getFieldArguments(info: GraphQLResolveInfo): GraphQLArgument[] {
|
46 | 47 | return typeFields[fieldName].args
|
47 | 48 | }
|
48 | 49 |
|
| 50 | +function fieldHasIntrospectionType(info) { |
| 51 | + const { fieldName, parentType } = info |
| 52 | + const typeFields = parentType.getFields() |
| 53 | + return isIntrospectionType(typeFields[fieldName].type) |
| 54 | +} |
| 55 | + |
49 | 56 | /**
|
50 | 57 | *
|
51 | 58 | * @param type
|
@@ -153,6 +160,7 @@ export function makeArgumentTransform<T, V>(
|
153 | 160 | }
|
154 | 161 |
|
155 | 162 | return null // exclude arguments when no value provided
|
| 163 | + // (undefined is changed to null, because TypeScript) |
156 | 164 | }
|
157 | 165 | }
|
158 | 166 |
|
@@ -212,25 +220,28 @@ export function processTypeArgs<V, T>({
|
212 | 220 |
|
213 | 221 | export function visitAllArgs({ transform }): IMiddlewareFunction {
|
214 | 222 | return (resolve, parent, args, ctx, info) => {
|
215 |
| - const argDefs = getFieldArguments(info) |
216 |
| - if (argDefs.length) { |
217 |
| - // Apply argument transform function to all arguments |
218 |
| - // The caller's transform function is applied to values that may be embedded |
219 |
| - // in lists and promises, but not to null or undefined values |
220 |
| - // Finally the resolver is called with transformed argument values |
221 |
| - return ( |
222 |
| - Promise.all( |
223 |
| - filterMap( |
224 |
| - makeArgumentTransform(transform, parent, args, ctx, info), |
225 |
| - argDefs, |
226 |
| - ), |
227 |
| - ) |
228 |
| - // substitute the transformed values into the args object |
229 |
| - .then(newArgs => |
230 |
| - newArgs.reduce((args, newArg) => ({ ...args, ...newArg }), args), |
| 223 | + // TODO avoid introspection types--very fussy about introducing async into sync code |
| 224 | + if (!fieldHasIntrospectionType(info)) { |
| 225 | + const argDefs = getFieldArguments(info) |
| 226 | + if (argDefs.length) { |
| 227 | + // Apply argument transform function to all arguments |
| 228 | + // The caller's transform function is applied to values that may be embedded |
| 229 | + // in lists and promises, but not to null or undefined values |
| 230 | + // Finally the resolver is called with transformed argument values |
| 231 | + return ( |
| 232 | + Promise.all( |
| 233 | + filterMap( |
| 234 | + makeArgumentTransform(transform, parent, args, ctx, info), |
| 235 | + argDefs, |
| 236 | + ), |
231 | 237 | )
|
232 |
| - .then(newArgs => resolve(parent, newArgs, ctx, info)) |
233 |
| - ) |
| 238 | + // substitute the transformed values into the args object |
| 239 | + .then(newArgs => |
| 240 | + newArgs.reduce((args, newArg) => ({ ...args, ...newArg }), args), |
| 241 | + ) |
| 242 | + .then(newArgs => resolve(parent, newArgs, ctx, info)) |
| 243 | + ) |
| 244 | + } |
234 | 245 | }
|
235 | 246 |
|
236 | 247 | return resolve(parent, args, ctx, info)
|
|
0 commit comments