Skip to content

validate does not check that selection sets are non-empty #3790

Closed
@berkowitze

Description

@berkowitze

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions