Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(introspetion): Fix Any type being included when it isn’t needed (#3481)

authored by

Phil Pluckthun and committed by
GitHub
cc4e1a0d 87c4bd95

+43 -22
+5
.changeset/tiny-candles-dress.md
··· 1 + --- 2 + '@urql/introspection': patch 3 + --- 4 + 5 + Fix `Any` type being included, even when it isn’t needed.
+38 -22
packages/introspection/src/minifyIntrospectionQuery.ts
··· 3 3 IntrospectionType, 4 4 IntrospectionTypeRef, 5 5 IntrospectionInputValue, 6 + IntrospectionDirective, 6 7 } from 'graphql'; 7 8 8 9 let _includeScalars = false; ··· 25 26 }; 26 27 27 28 case 'SCALAR': 28 - _hasAnyType = _hasAnyType || _includeScalars; 29 - return _includeScalars ? fromType : anyType; 29 + if (_includeScalars) { 30 + return fromType; 31 + } else { 32 + _hasAnyType = true; 33 + return anyType; 34 + } 30 35 31 36 case 'INPUT_OBJECT': 32 - _hasAnyType = _hasAnyType || _includeInputs; 33 - return _includeInputs ? fromType : anyType; 37 + if (_includeInputs) { 38 + return fromType; 39 + } else { 40 + _hasAnyType = true; 41 + return anyType; 42 + } 34 43 35 44 case 'ENUM': 36 - _hasAnyType = _hasAnyType || _includeEnums; 37 - return _includeEnums ? fromType : anyType; 45 + if (_includeEnums) { 46 + return fromType; 47 + } else { 48 + _hasAnyType = true; 49 + return anyType; 50 + } 38 51 39 52 case 'OBJECT': 40 53 case 'INTERFACE': ··· 244 257 }) 245 258 .map(minifyIntrospectionType); 246 259 247 - const minifiedDirectives = (directives || []).map(directive => ({ 248 - name: directive.name, 249 - isRepeatable: directive.isRepeatable ? true : undefined, 250 - locations: directive.locations, 251 - args: directive.args.map( 252 - arg => 253 - ({ 254 - name: arg.name, 255 - type: mapType(arg.type), 256 - defaultValue: arg.defaultValue || undefined, 257 - }) as IntrospectionInputValue 258 - ), 259 - })); 260 + if (_hasAnyType) { 261 + minifiedTypes.push({ kind: 'SCALAR', name: anyType.name }); 262 + } 260 263 261 - if (!_includeScalars || !_includeEnums || !_includeInputs || _hasAnyType) { 262 - minifiedTypes.push({ kind: 'SCALAR', name: anyType.name }); 264 + let minifiedDirectives: IntrospectionDirective[] = []; 265 + if (opts.includeDirectives) { 266 + minifiedDirectives = (directives || []).map(directive => ({ 267 + name: directive.name, 268 + isRepeatable: directive.isRepeatable ? true : undefined, 269 + locations: directive.locations, 270 + args: directive.args.map( 271 + arg => 272 + ({ 273 + name: arg.name, 274 + type: mapType(arg.type), 275 + defaultValue: arg.defaultValue || undefined, 276 + }) as IntrospectionInputValue 277 + ), 278 + })); 263 279 } 264 280 265 281 return { ··· 268 284 mutationType, 269 285 subscriptionType, 270 286 types: minifiedTypes, 271 - directives: opts.includeDirectives ? minifiedDirectives : [], 287 + directives: minifiedDirectives, 272 288 }, 273 289 }; 274 290 };