Skip to content

Commit

Permalink
(introspection) - Improve schema minification by removing meta types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten authored Jan 29, 2021
1 parent 27a88ab commit c38c721
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-maps-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/introspection': minor
---

Update `minifyIntrospectionQuery` utility to remove additional information on arguments and to filter out schema metadata types, like `__Field` and others.
31 changes: 21 additions & 10 deletions packages/introspection/src/minifyIntrospectionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ const minifyIntrospectionType = (
args:
field.args &&
field.args.map(arg => ({
...arg,
name: arg.name,
type: mapType(arg.type, anyType),
defaultValue: undefined,
})),
} as any)
),
Expand All @@ -84,9 +83,8 @@ const minifyIntrospectionType = (
args:
field.args &&
field.args.map(arg => ({
...arg,
name: arg.name,
type: mapType(arg.type, anyType),
defaultValue: undefined,
})),
} as any)
),
Expand Down Expand Up @@ -133,12 +131,25 @@ export const minifyIntrospectionQuery = (
} = schema;

const minifiedTypes = types
.filter(
type =>
type.kind === 'OBJECT' ||
type.kind === 'INTERFACE' ||
type.kind === 'UNION'
)
.filter(type => {
switch (type.name) {
case '__Directive':
case '__DirectiveLocation':
case '__EnumValue':
case '__InputValue':
case '__Field':
case '__Type':
case '__TypeKind':
case '__Schema':
return false;
default:
return (
type.kind === 'OBJECT' ||
type.kind === 'INTERFACE' ||
type.kind === 'UNION'
);
}
})
.map(minifyIntrospectionType);

minifiedTypes.push({ kind: 'SCALAR', name: anyType.name });
Expand Down

0 comments on commit c38c721

Please sign in to comment.