Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call with empty parameter list is considered a parse error #300

Closed
jhelberg opened this issue Jun 5, 2024 · 2 comments
Closed

call with empty parameter list is considered a parse error #300

jhelberg opened this issue Jun 5, 2024 · 2 comments

Comments

@jhelberg
Copy link

jhelberg commented Jun 5, 2024

What happened?

I have the following in my definition file under Queries:

    "Return the participant representing the logged on user."
    mmi(): participant

gqlparse bombs out with:

expected at least one definition, found )

What did you expect?

I think it is allowed to have a query without paratemers. I expect gqlparse to accept this line.

Minimal graphql.schema and models to reproduce

schema {
    query: Query
}

type participant {
          id:        ID!
    nickname:        String!
}
type Query {
    "Return the participant representing the logged on user."
    mmi(): participant
}

versions

  • github.com/vektah/gqlparser/v2 v2.5.11
  • go version go1.22.3 linux/amd64
@StevenACoffman
Copy link
Collaborator

StevenACoffman commented Jun 5, 2024

Thank you for taking the time to report this, but I'm not sure this is a bug, even if it is a change in behavior from the past.

The GraphQL documentation gives these examples showing omitting parenthesis for queries when there are no arguments:

type Query {
  books: [Book]
  authors: [Author]
}

And the spec states that if you try to add empty parenthesis like:

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

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.

This parser used to allow empty parenthesis, but we are trying to maintain spec compliance. The change was made here:
#293

@jhelberg
Copy link
Author

jhelberg commented Jun 5, 2024

thx for taking the time. Seems that () is not allowed indeed.
regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants