mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 17:18:23 +00:00
(processVariables: true) do not collect input if variable is missing (#456)
This commit is contained in:
parent
e85d8220a7
commit
fb9b624ab8
5 changed files with 45 additions and 3 deletions
5
.changeset/slow-pets-scream.md
Normal file
5
.changeset/slow-pets-scream.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/client': patch
|
||||
---
|
||||
|
||||
(processVariables: true) do not collect input when corresponding variable is missing
|
||||
|
|
@ -318,8 +318,8 @@ export function createCollector({
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// Collect the entire type
|
||||
collectInputType(namedType.name);
|
||||
// Collect type without fields
|
||||
markAsUsed(makeId(namedType.name));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue