(processVariables: true) do not collect input if variable is missing (#456)

This commit is contained in:
Dmitry Til 2022-10-25 16:27:26 +02:00 committed by GitHub
parent e85d8220a7
commit fb9b624ab8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'@graphql-hive/client': patch
---
(processVariables: true) do not collect input when corresponding variable is missing

View file

@ -318,8 +318,8 @@ export function createCollector({
}
}
} else {
// Collect the entire type
collectInputType(namedType.name);
// Collect type without fields
markAsUsed(makeId(namedType.name));
}
});
} else {

View file

@ -336,6 +336,32 @@ test('(processVariables: true) collect used-only input fields', async () => {
expect(info.fields).not.toContain(`PaginationInput.offset`);
});
test('(processVariables: true) should collect input object without fields when corresponding variable is not provided', async () => {
const collect = createCollector({
schema,
max: 1,
processVariables: true,
});
const info = collect(
parse(/* GraphQL */ `
query getProjects($pagination: PaginationInput, $type: ProjectType!) {
projects(filter: { pagination: $pagination, type: $type }) {
id
}
}
`),
{
type: 'STITCHING',
}
).value;
expect(info.fields).toContain(`FilterInput.type`);
expect(info.fields).toContain(`FilterInput.pagination`);
expect(info.fields).toContain(`PaginationInput`);
expect(info.fields).not.toContain(`PaginationInput.limit`);
expect(info.fields).not.toContain(`PaginationInput.offset`);
});
test('(processVariables: true) collect used-only input type fields from an array', async () => {
const collect = createCollector({
schema,

View file

@ -134,6 +134,8 @@ export function GraphQLTypeCard(
name: string;
description?: string | null;
implements?: string[];
totalRequests?: number;
usage?: DocumentType<typeof SchemaExplorerUsageStats_UsageFragment>;
}>
) {
return (
@ -156,6 +158,9 @@ export function GraphQLTypeCard(
</div>
</div>
) : null}
{props.usage && typeof props.totalRequests !== 'undefined' ? (
<SchemaExplorerUsageStats totalRequests={props.totalRequests} usage={props.usage} />
) : null}
</div>
<div>{props.children}</div>
</div>

View file

@ -19,7 +19,13 @@ export function GraphQLInputObjectTypeComponent(props: {
totalRequests: number;
}) {
return (
<GraphQLTypeCard kind="input" name={props.type.name} description={props.type.description}>
<GraphQLTypeCard
kind="input"
name={props.type.name}
description={props.type.description}
totalRequests={props.totalRequests}
usage={props.type.usage}
>
<GraphQLInputFields fields={props.type.fields} totalRequests={props.totalRequests} />
</GraphQLTypeCard>
);