You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/learn/schema.mdx
+11-6Lines changed: 11 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,12 @@ That's where the schema comes in. Every GraphQL service defines a set of types t
32
32
33
33
## Type language
34
34
35
-
GraphQL services can be written in any language and there are different approaches you can take when defining the types in a schema. Some libraries require that you only write the _resolver functions_ that provide data for the different fields in the API, then compile the schema based on that code. Other libraries allow you to define types and fields using what's commonly called the _schema definition language_ (or SDL) and then write the resolver functions for the corresponding fields separately.
35
+
GraphQL services can be written in any language and there are many different approaches you can take when defining the types in a schema:
36
+
37
+
- Some libraries have you construct the schema types, fields, and resolver functions together using the same programming language that was used to write the GraphQL implementation.
38
+
- Some libraries allow you to define types and fields more ergonomically using what's commonly called the schema definition language (or SDL) and then write the resolver functions for the corresponding fields separately.
39
+
- Some libraries allow you to write and annotate the resolver functions, and then infer the schema from that.
40
+
- Some libraries may even infer both the types and resolver functions for you, based on some underlying data source(s).
36
41
37
42
Since we can't rely on a specific programming language to discuss GraphQL schemas in this guide, we'll use SDL because it's similar to the query language that we've seen so far and allows us to talk about GraphQL schemas in a language-agnostic way.
- `Character` isaGraphQLObjecttype, meaningit'satypewithsomefields. Mostofthetypesinyourschema will be Object types.
53
-
- `name` and `appearsIn` are fields on the `Character` type. That means that `name` and `appearsIn` are the only fields that can appear in any part of a GraphQL query that operates on the `Character` type.
54
-
- `String` is one of the built-in Scalar types. These are types that resolve to a single scalar value and can't have sub-selections in the query. We'll go over Scalar types more later.
55
-
- `String!` means that the field is a Non-Null type, meaning the GraphQL service promises to give you a value whenever you query this field. In SDL, we represent those with an exclamation mark.
56
-
- `[Episode!]!` represents an List type of `Episode` objects. When a List is Non-Null, you can always expect an array (with zero or more items) when you query the `appearsIn` field. In this case, since `Episode!` is also Non-Null within the list, you can always expect every item in the array to be an `Episode` object.
57
+
- `Character` isa[GraphQLObjecttype](#object-types-and-fields), meaning it's a type with some fields. Most of the types in your schema will be Object types.
58
+
- `name` and `appearsIn` are [fields](#object-types-and-fields) on the `Character` type. That means that `name` and `appearsIn` are the only fields that can appear in any part of a GraphQL query that operates on the `Character` type.
59
+
- `String` is one of the built-in [Scalar types](#scalar-types). These are types that resolve to a single scalar value and can't have sub-selections in the query. We'll go over Scalar types more later.
60
+
- `String!` means that the field is a [Non-Null type](#non-null), meaning the GraphQL service promises to give you a value whenever you query this field. In SDL, we represent those with an exclamation mark.
61
+
- `[Episode!]!` represents an [List type](#list) of `Episode` objects. When a List is Non-Null, you can always expect an array (with zero or more items) when you query the `appearsIn` field. In this case, since `Episode!` is also Non-Null within the list, you can always expect every item in the array to be an `Episode` object.
57
62
58
63
Now you know what a GraphQL Object type looks like and how to read the basics of SDL.
0 commit comments