06 24 2019 dark mode hook2019 06 09 graphql and gatsby2019 06 13 graphql schema definition 101Graphql schema 101About linkAdd BlogCommit blockCommit block listGridGrid2Header linksHeader logoHomeIndexMy ProfileSidebarTable notesselect-dropbox-root-foldersodebrrr
Components
Flex
General
Layouts
Projects
blogs
Graphql schema 101
Why might you need to define a graphql schema?
There are a few reasons this could happen:
Lets look at a simple type to represent a customer
type Customer {firstName: String!lastName: String!age: Int!}
Here we are defining a Customer
type
It has a first name, a last name (strings) and an age (an int). The exclamation points following the type names signify that the fields are required.
Simple enough, but things start to get more complex when you want to model something on our Customer
that doesn't map to a primitive like a String or an Int, Like lets say we want to also have types for Product
and Order
.
type Customer {...orders: [Order]!}type Product {name: String!}type Order {products: [Product!]!customer: Customer!}
So now we have a Customer
and we can track their orders of given products.