3. 3
NodeXperts
Schema
We know that graphQL is strictly Type system, So,
it can not perform operation without Schema.
Scalar Types in GraphQL :-
- Int - A signed 32‐bit integer.
- Float - A signed double-precision
floating-point value.
- String - A UTF‐8 character sequence.
- Boolean - true or false.
- ID - A unique string identifier.
4. 4
NodeXperts
Schema
Apart from the mentioned type we have user defined type which is constructed
using these types.
Most types in our schema is a object type which we construct using the available
scalar type.
Apart from that we have three types which are special in schema, which define
the entry point of the graphQL operations.
5. 5
NodeXperts
Schema
We will learn schema with an example.
Construct a schema Person with below
attributes.
- name should be of type string.
- id should be a unique identifier.
- Age should be of type number.
- student should be of type boolean
Each Schema definition is start with the
keyword type.
type Person {
name: String
id: ID!
age: Int
student: Boolean
}
6. 6
NodeXperts
Schema
Special types in graphQL
- query :- Entry point for query operations.
- mutation :- Entry point for mutation
operations.
- subscription :- Entry point for subscription
operations.
How we define these types?
Apart from these three special type we have
to define each type using those scalar types
available to us.
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
7. 7
NodeXperts
The team structure of
each DAN POD is
optimised per set
hierarchy
Schema
So, in our last example we have seen that we have
types types which is non scalar.
- Query
- Resolver
- Subscription
So, these types are called as root types in graphQL.
Take example of Query type.
Each query operation in graphQL is start with the
root query type.
type Query {
person: Person
}
8. 8
NodeXperts
The team structure of
each DAN POD is
optimised per set
hierarchy
Schema
Each root type is associated with the corresponding resolvers. The name of the resolvers should
be the same as the name of the fields in root type.
We will discuss resolvers later.
9. 9
NodeXperts
How we Query fields in GraphQL?
So, to get data from the graphQL we have to
query the fields from the root type of the
schema.
There is a specified format of writing queries in
graphQL.
Schema
Query Format in graphQL is looks like a json object.
query {
person {
name
id
student
}
}