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

Make "Schemas and Types" page more approachable to newcomers #1794

Closed
wants to merge 3 commits into from

Conversation

jonathanberger
Copy link
Contributor

@jonathanberger jonathanberger commented Oct 11, 2024

I'm new to GraphQL so I may be mistaken but I believe the author intended to capitalize the type names in this passage since they are capitalized in the paragraphs below. The capitalization is important to get right in this context since the example right above the changed text has both "query" and "Query" in it.

Copy link

vercel bot commented Oct 11, 2024

@jonathanberger is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

linux-foundation-easycla bot commented Oct 11, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jonathanberger / name: Jonathan Berger (7896b72, 6e23c01)
  • ✅ login: benjie / name: Benjie (d06f813)

@jorydotcom
Copy link
Contributor

Thanks for contributing, @jonathanberger ! Can you sign our CLA?

@benjie
Copy link
Member

benjie commented Oct 11, 2024

Hi @jonathanberger; thanks for your contribution! These terms can be overloaded quite heavily, making it confusing; I did some work on the spec to stop us using the word query in so many ways: graphql/graphql-spec#715

I believe that the text here is not (contrary to what it says) referring to a Query type, but instead saying that there must be a type (it can have any valid name) that's used for the "query operation". We now call this the "root operation type" for the query operation: https://spec.graphql.org/draft/#sec-Root-Operation-Types

e.g. this is a valid schema:

type Query {
  a: Int
}

This is also a valid schema (note it does not have a Query type, but it does have a type for the query operation, called Root):

schema {
  query: Root
  mutation: Changes
}
type Root {
  a: Int
}
type Changes {
  b: Int
}

This is also valid (but super confusing!):

schema {
  query: Mutation
  subscription: Query
}
"""The query root operation type in this schema"""
type Mutation {
  a: Int
}
"""The subscription root operation type in this schema"""
type Query {
  b: Int
}

I agree the text you've found is confusing; would you like to submit an improved fix that factors in this knowledge?

Simplify description of Query and Mutation types.

I think it's safe not to introduce the `schema` keyword in the second page that beginners will come to when learning about GraphQL. Changing the names of the root operation types is, I assume, rare, and so I'm suggesting with these edits to omit going into that detail.
Copy link
Contributor Author

@jonathanberger jonathanberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benjie, thanks so much. That really help clarifies. I took a crack at updating the docs to what I think I would have wanted before wading into this and understanding it a bit more. I realize I'm cutting out an example that is there today, but I think it's a beneficial simplification that will ease the GraphQL learning curve.

I had already been confused why this special word schema was being used without being fully explained anywhere else on the page, so I took out the example that used it.

Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation is significantly out of date, we've not even mentioned subscriptions for example. I've taken a slightly alternative approach, what do you think?

src/pages/learn/schema.mdx Outdated Show resolved Hide resolved
src/pages/learn/schema.mdx Outdated Show resolved Hide resolved
@@ -101,7 +92,7 @@ type Query {

Mutations work in a similar way - you define fields on the `Mutation` type, and those are available as the root mutation fields you can call in your query.

It's important to remember that other than the special status of being the "entry point" into the schema, the `Query` and `Mutation` types are the same as any other GraphQL object type, and their fields work exactly the same way.
It's important to remember that other than the special status of being the entry points, the `Query` and `Mutation` types are the same as any other GraphQL object type, and their fields work exactly the same way.
Copy link
Member

@benjie benjie Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had already been confused why this special word schema was being used without being fully explained anywhere else on the page, so I took out the example that used it.

I see what you mean; it's introduced a little to early. But since we talk about naming things by default maybe it's best to reintroduce the schema keyword at the end of this section detailing what you need to do if you don't want the defaults:

Suggested change
It's important to remember that other than the special status of being the entry points, the `Query` and `Mutation` types are the same as any other GraphQL object type, and their fields work exactly the same way.
It's important to remember that other than the special status of being the entry points, the `Query` and `Mutation` types are the same as any other GraphQL object type, and their fields work exactly the same way.
You can choose to name your entry point types differently; if you choose to do so then you will need to inform GraphQL of the new names using the `schema` keyword:
```graphql
schema {
query: MyQueryType
mutation: MyMutationType
}
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What percent of users would you estimate rename their entry points?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to say; but our very own swapi-graphql example API does: https://graphql.org/swapi-graphql/?query=%7B__typename%7D

@benjie benjie changed the title Update schema.mdx Make "Schemas and Types" page more approachable to newcomers Oct 24, 2024
@benjie
Copy link
Member

benjie commented Oct 24, 2024

@jonathanberger I still would like your feedback on that last point, but I've gone ahead and committed the changes since there is overlapping work in #1800

@jonathanberger
Copy link
Contributor Author

I think your latest approach is an improvement. Thanks!

@benjie
Copy link
Member

benjie commented Oct 31, 2024

Awesome; your work has been incorporated into #1800 so I'm going to close this PR - thanks again @jonathanberger 🙌

@benjie benjie closed this Oct 31, 2024
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