Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Designing GraphQL Schemas

Designing GraphQL Schemas

Shopify has been building GraphQL APIs for over 2 years and we've learned a lot along the way. In this talk I'll reveal some of the fundamental concepts we use to design and build our schemas. We'll be implementing a sample ecommerce feature to demonstrate these concepts and best practices.

Scott Walkinshaw

May 30, 2018
Tweet

More Decks by Scott Walkinshaw

Other Decks in Technology

Transcript

  1. List-type fields should almost always non-null lists with non-null elements.

    Like lists, boolean fields should almost always non-null. Tips
  2. type Collection { id: ID! rules: [CollectionRule!]! rulesApplyDisjunctively: Bool! products:

    [Product!]! title: String! imageId: ID bodyHtml: String } type CollectionRule { column: String! relation: String! condition: String! }
  3. Choose field names based on what makes sense, not based

    on the implementation or what the field is called in legacy APIs. Rule #6
  4. The API should provide business logic, not just data. Complex

    calculations should be done on the server, in one place, not on the client, in many places. Rule #9
  5. Mutations should provide user/business-level errors via a userErrors field on

    the mutation payload. The top-level query errors entry is reserved for client and server-level errors. Rule #13