gqlparser icon indicating copy to clipboard operation
gqlparser copied to clipboard

Empty argument lists () should be disallowed

Open yuchenshi opened this issue 1 year ago • 1 comments

What happened?

This document validates in gqlparser.

query GetSomething() { # <-- empty arguments list here
  user() { # <-- empty argument list here
    name
  }
}

What did you expect?

There should be a validation error in Line 1 and Line 2 each because in GraphQL, Arguments must contain at least one Argument. In GraphQL spec, the notation [list] means one or more -- see spec definition

Note that the entire "Arguments" portion is optional in both contexts, therefore query GetSomething { ... } is allowed and so is user { ... }, but if the braces () are present they must contain something.

graphql-js reports errors on both cases correctly.

Minimal graphql.schema and models to reproduce

type User {
  name: String
}

Although I haven't tested this, I suspect name(): String will also parse in gqlparser but it should have errored according to the spec. There may be other cases with similar issues but I haven't done a full audit of the spec nor gqlparser.

versions

  • go list -m github.com/vektah/gqlparser/v2?
  • go version?
github.com/vektah/gqlparser/v2 v2.5.11
go version go1.18 linux/amd64

yuchenshi avatar Mar 25 '24 18:03 yuchenshi

Thank you for noticing this issue! Can you please submit a PR to correct it?

StevenACoffman avatar Mar 25 '24 20:03 StevenACoffman

@StevenACoffman Sure, #293

yuchenshi avatar Apr 05 '24 01:04 yuchenshi