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

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

Changed files
+43 -22
.changeset
packages
introspection
+5
.changeset/tiny-candles-dress.md
···
+
---
+
'@urql/introspection': patch
+
---
+
+
Fix `Any` type being included, even when it isn’t needed.
+38 -22
packages/introspection/src/minifyIntrospectionQuery.ts
···
IntrospectionType,
IntrospectionTypeRef,
IntrospectionInputValue,
+
IntrospectionDirective,
} from 'graphql';
let _includeScalars = false;
···
};
case 'SCALAR':
-
_hasAnyType = _hasAnyType || _includeScalars;
-
return _includeScalars ? fromType : anyType;
+
if (_includeScalars) {
+
return fromType;
+
} else {
+
_hasAnyType = true;
+
return anyType;
+
}
case 'INPUT_OBJECT':
-
_hasAnyType = _hasAnyType || _includeInputs;
-
return _includeInputs ? fromType : anyType;
+
if (_includeInputs) {
+
return fromType;
+
} else {
+
_hasAnyType = true;
+
return anyType;
+
}
case 'ENUM':
-
_hasAnyType = _hasAnyType || _includeEnums;
-
return _includeEnums ? fromType : anyType;
+
if (_includeEnums) {
+
return fromType;
+
} else {
+
_hasAnyType = true;
+
return anyType;
+
}
case 'OBJECT':
case 'INTERFACE':
···
})
.map(minifyIntrospectionType);
-
const minifiedDirectives = (directives || []).map(directive => ({
-
name: directive.name,
-
isRepeatable: directive.isRepeatable ? true : undefined,
-
locations: directive.locations,
-
args: directive.args.map(
-
arg =>
-
({
-
name: arg.name,
-
type: mapType(arg.type),
-
defaultValue: arg.defaultValue || undefined,
-
}) as IntrospectionInputValue
-
),
-
}));
+
if (_hasAnyType) {
+
minifiedTypes.push({ kind: 'SCALAR', name: anyType.name });
+
}
-
if (!_includeScalars || !_includeEnums || !_includeInputs || _hasAnyType) {
-
minifiedTypes.push({ kind: 'SCALAR', name: anyType.name });
+
let minifiedDirectives: IntrospectionDirective[] = [];
+
if (opts.includeDirectives) {
+
minifiedDirectives = (directives || []).map(directive => ({
+
name: directive.name,
+
isRepeatable: directive.isRepeatable ? true : undefined,
+
locations: directive.locations,
+
args: directive.args.map(
+
arg =>
+
({
+
name: arg.name,
+
type: mapType(arg.type),
+
defaultValue: arg.defaultValue || undefined,
+
}) as IntrospectionInputValue
+
),
+
}));
}
return {
···
mutationType,
subscriptionType,
types: minifiedTypes,
-
directives: opts.includeDirectives ? minifiedDirectives : [],
+
directives: minifiedDirectives,
},
};
};