Closed
Description
The validate
function does not find any issues if you pass an AST with an empty selection set for an object/interface field.
Running into this when building a query ast based on a form, and toggling form fields sometimes lead to an empty selection set. I'm going to properly handle "empty" selection sets (by removing the node from the ast), but it being caught by validation would be really nice as well as a backup and for correctness.
From the spec:
If selectionType is an interface, union, or object:
The subselection set of that selection must NOT BE empty.
Repro (sandbox):
import {
buildSchema,
DocumentNode,
Kind,
OperationTypeNode,
validate
} from "graphql";
const s = `
type Query {
dog: Int
}
schema {
query: Query
}
`;
const schema = buildSchema(s);
const query: DocumentNode = {
kind: Kind.DOCUMENT,
definitions: [
{
kind: Kind.OPERATION_DEFINITION,
operation: OperationTypeNode.QUERY,
selectionSet: {
kind: Kind.SELECTION_SET,
selections: []
}
}
]
};
console.log(validate(schema, query)); // outputs `[]`
Happy to fix this but this would be my first OSS contribution so wanted to ask:
- Is this the right place to post this?
- Is this actually an issue?
- What is the general approach to a fix?
- What is the right wording for any error messaging?
Metadata
Metadata
Assignees
Labels
No labels