From 7896b721469b6cd778a861ac3db48bd91bcfa465 Mon Sep 17 00:00:00 2001 From: Jonathan Berger Date: Thu, 10 Oct 2024 18:38:44 -0700 Subject: [PATCH 1/3] Update schema.mdx --- src/pages/learn/schema.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/learn/schema.mdx b/src/pages/learn/schema.mdx index b87c116561..2bcec62d4b 100644 --- a/src/pages/learn/schema.mdx +++ b/src/pages/learn/schema.mdx @@ -76,7 +76,7 @@ schema { } ``` -Every GraphQL service has a `query` type and may or may not have a `mutation` type. These types are the same as a regular object type, but they are special because they define the _entry point_ of every GraphQL query. So if you see a query that looks like: +Every GraphQL service has a `Query` type and may or may not have a `Mutation` type. These types are the same as a regular object type, but they are special because they define the _entry point_ of every GraphQL query. So if you see a query that looks like: ```graphql # { "graphiql": true } From 6e23c01e48caca1af27b37c223052ec3806b5807 Mon Sep 17 00:00:00 2001 From: Jonathan Berger Date: Sat, 12 Oct 2024 13:07:00 -0700 Subject: [PATCH 2/3] Update schema.mdx 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. --- src/pages/learn/schema.mdx | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/pages/learn/schema.mdx b/src/pages/learn/schema.mdx index 2bcec62d4b..a301000ca8 100644 --- a/src/pages/learn/schema.mdx +++ b/src/pages/learn/schema.mdx @@ -67,16 +67,7 @@ Arguments can be either required or optional. When an argument is optional, we c ## The Query and Mutation types -Most types in your schema will just be normal object types, but there are two types that are special within a schema: - -```graphql -schema { - query: Query - mutation: Mutation -} -``` - -Every GraphQL service has a `Query` type and may or may not have a `Mutation` type. These types are the same as a regular object type, but they are special because they define the _entry point_ of every GraphQL query. So if you see a query that looks like: +There are two special "entry point" types that by default are named `Query` and `Mutation`. These types are the same as a regular object type, but they are special because they define the _entry point_ of every GraphQL query. So if you see a query that looks like: ```graphql # { "graphiql": true } @@ -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. ## Scalar types From d06f813b71c39976ad3cd557adc418559c276225 Mon Sep 17 00:00:00 2001 From: Benjie Date: Thu, 24 Oct 2024 12:07:10 +0100 Subject: [PATCH 3/3] Apply suggestions from code review --- src/pages/learn/schema.mdx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/learn/schema.mdx b/src/pages/learn/schema.mdx index a301000ca8..451ccb4b26 100644 --- a/src/pages/learn/schema.mdx +++ b/src/pages/learn/schema.mdx @@ -67,7 +67,7 @@ Arguments can be either required or optional. When an argument is optional, we c ## The Query and Mutation types -There are two special "entry point" types that by default are named `Query` and `Mutation`. These types are the same as a regular object type, but they are special because they define the _entry point_ of every GraphQL query. So if you see a query that looks like: +Every GraphQL schema must support `query` operations, the _entry point_ for these operations is a regular object type that by default is called `Query`. So if you see a query that looks like: ```graphql # { "graphiql": true } @@ -90,10 +90,19 @@ 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. +Schemas may also choose to support `mutation` operations by adding another entry point type, by default called `Mutation`. Mutations work in a similar way to queries - you define fields on the `Mutation` type, and those are available as the root mutation fields you can call in your mutation operation. 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 +} +``` + ## Scalar types A GraphQL object type has a name and fields, but at some point those fields have to resolve to some concrete data. That's where the scalar types come in: they represent the leaves of the query.