--- title: Schema Design description: The best way to fetch data, update it, and keep things running for a long time --- GraphQL schemas are at their best when they are designed around the need of client applications, instead of the shape of how the data is stored. Often times teams will create schemas that are literal mappings on top of their collections or tables with CRUD like root fields. While this may be a fast way to get up and running, a strong long term GraphQL schema is built around the products usage. ## Style conventions The GraphQL specification is flexible in the style that it dictates and doesn't impose specific naming guidelines. In order to facilitate development and continuity across GraphQL deployments, we suggest the following style conventions : - **Fields**: are recommended to be written in `camelCase`, since the majority of consumers will be client applications written in JavaScript. - **Types**: should be `PascalCase`. - **Enums**: should have their name in `PascalCase` and their values in `ALL_CAPS` to denote their special meaning. ## Using interfaces **Interfaces** are a powerful way to build and use GraphQL schemas. A GraphQL Interface is an abstract type (meaning it can't be used directly in the schema as an Object type) which describes required fields that implementing types must include. A simple example would look like this: ```graphql interface Book { title: String author: Author } ``` This interface describes what all books in our schema will look like. At this point, we can't actually query for a `Book`, but we can use the interface to create concrete types. For example, we may have a screen in our app that wants to display `TextBooks` and `ColoringBooks` no matter what they actually are. To create something like this, we can do something like this: ```graphql type TextBook implements Book { title: String author: Author classes: [Class] } type ColoringBook implements Book { title: String author: Author colors: [Color] } type Query { schoolBooks: [Book] } ``` Since we return `Book` for the field `schoolBooks`, when writing a query we don't need to worry about what kind of `Book` we actually return. This is really helpful for feeds of common content, user role systems, and more! Here is what a query would look like for the above schema: ```graphql query GetBooks { schoolBooks { title author } } ``` If we wanted to return specific data for `TextBook`s or `ColoringBook`s, we could include and inline fragment specificying what concrete type we want to select fields on. For example: ```graphql query GetBooks { schoolBooks { title ... on TextBook { classes { name } } ... on ColoringBook { colors { name } } } } ``` The amazing thing about interfaces is that if the first book was a `TextBook`, it wouldn't have a field called `colors` in the response, but if it was a `ColoringBook` it would! To see an interface in practice, check out this [example]() ## Node interface Given the power of interfaces, one pattern that can add a safe layer of flexibility to our schema is the `Node` interface pattern. We really recommend all schemas to follow this pattern if possible! The `Node` interface provides a way to fetch potentially any type in our schema with just an `id` field. We will explain how it works though a common example: Say we have a database with two different tables; `Author` and `Post`. Each of these tables have an `id` column that is unique for that table. To use the `Node` interface we would add the following to our schema: ```graphql interface Node { id: ID! } ``` This is the actual `Node` interface. It has only one field which is an `ID!`, meaning it is a schema unique string that is required to exist. To use the `Node` interface in our example, we would write our types like so: ```graphql type Post implements Node { id: ID! title: String! author: Author! } type Author implements Node { id: ID! name: String! posts: [Post] } ``` By implementing the `Node` interface, we know that anytime we have an `id` field from either `Author` or `Post`, we can send it back to our server and retreive that exact piece of data back! But earlier we said our database has ids that are unique only to each table, so how is this possible?