Skip to content

Conversation

ascherkus
Copy link
Contributor

@ascherkus ascherkus commented Jun 12, 2025

…tion type names

From the GraphQL spec:

While any type can be the root operation type for a GraphQL operation, the type system definition language can omit the schema definition when the query, mutation, and subscription root types are named "Query", "Mutation", and "Subscription" respectively.
Likewise, when representing a GraphQL schema using the type system definition language, a schema definition should be omitted if it only uses the default root operation type names.

If a schema uses a mix of custom and default root operation type names, the formatter should emit a complete schema definition for all root operations defined.

Describe your PR and link to any relevant issues.

I have:

  • Added tests covering the bug / feature
  • Updated any relevant documentation

…tion type names

From the GraphQL spec:
> While any type can be the root operation type for a GraphQL operation, the type system definition language can omit the schema definition when the query, mutation, and subscription root types are named "Query", "Mutation", and "Subscription" respectively.
> Likewise, when representing a GraphQL schema using the type system definition language, a schema definition should be omitted if it only uses the default root operation type names.

If a schema uses a mix of custom and default root operation type names, the formatter
should emit a complete schema definition for all root operations defined.
@coveralls
Copy link

Coverage Status

coverage: 87.658% (+0.009%) from 87.649%
when pulling 075c3ec on roundtrip:inferred-root-types
into f7a3835 on vektah:master.

@StevenACoffman
Copy link
Collaborator

Hey, this is an unpaid volunteer, community-led project and I really appreciate you catching and fixing this (with tests 🥳 )!

Sorry that I've been sort of stalling on merging it for these few days. In this bit of code, it had already bothered me that the same nil conditions were checked multiple times, and this adds to that a bit. Not a criticism of your changes, just triggered me to try to step back and wonder if this is going to need more extension in the future. 🤔

I'm going to merge this as it is, but I'm always interested to know how you're using this, and if there are any other friction or pain points you've encountered that I could help with. If GitHub isn't a convenient way to discuss things, feel free to reach out to me on LinkedIn or via my email (although sometimes miss email when it gets flagged as spam without me noticing).

While I live in Ann Arbor, Michigan, I spend a lot of time in Toronto visiting friends and relatives, so it's always fun to connect with folks in the general area. Let me know if I can help in with whatever you're doing!

@StevenACoffman StevenACoffman merged commit 895262c into vektah:master Jun 15, 2025
7 checks passed
@ascherkus
Copy link
Contributor Author

Oh no worries about the timeline on merging! Thanks for taking the time to review and merge. I wasn't particularly happy with the duplicate nil checks either but struggled to find a more elegant way that didn't blow up into a bigger change.

I'm using gqlparser in tandem with gqlgen to generate a subset of a much larger GraphQL schema. The input schema I'm working with uses a custom query root type called QueryRoot while using the default mutation root type Mutation:

schema {
  query: QueryRoot
  mutation: Mutation
}

I came across this bug as my generated formatted subset only defined QueryRoot in the schema block, but not Mutation, which led to gqlgen not generating any of my mutations.

Overall both gqlgen and gqlparser has worked pretty well and as advertised. The one-size-fits-all Definition type took a bit to get used to but once I wrapped my head around things it was fine.

Funny enough I have in laws in Ann Arbor. Washtenaw Dairy and Zingerman's were two highlights of my visit there :)

@StevenACoffman
Copy link
Collaborator

Uh-oh. Ok, let's make a deal. If it turns out we are related and have been in mutual family gathering photos, let's not tell anyone we didn't recognize each other, ok? 😆

If not, go ahead and hit me up on LinkedIn and maybe we can go out to coffee next time one of us is in the other one's city. I'm always up for Zingerman's. In Toronto, I haven't found a favorite sandwich shop to since Stockyard's closed.

BTW, I cut a new gqlgen release https://github.com/99designs/gqlgen/releases/tag/v0.17.75 including which includes the gqlparser release with this PR.

Also, let me know if you think of anything else that could work better!

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

Successfully merging this pull request may close these issues.

3 participants