Navigating your transition to GraphQL with GraphQL first development

39
Navigating Your Transition to GraphQL A GraphQL-first approach to improving your API Sashko Stubailo Tech Lead Apollo Open Source Danielle Man Developer Apollo Services

Transcript of Navigating your transition to GraphQL with GraphQL first development

Page 1: Navigating your transition to GraphQL with GraphQL first development

Navigating Your Transition to GraphQLA GraphQL-first approach to improving your API

Sashko Stubailo Tech Lead

Apollo Open Source

Danielle Man Developer

Apollo Services

Page 2: Navigating your transition to GraphQL with GraphQL first development

Who are we?

• We build and maintain tools for the GraphQL community

• Excited about the developer experience enabled by GraphQL

• We went from 0 to GraphQL in two production apps, talked to many people who did the same

• We build new apps and features fast with a GraphQL-first workflow

apollodata.com

github.com/apollostack

Page 3: Navigating your transition to GraphQL with GraphQL first development

Announced and open-sourced

July 2015

Production ready, new site

September 2016

Great tools, best practices, efficient

workflow

The future

Initial design at Facebook

2012

Looking back…

Page 4: Navigating your transition to GraphQL with GraphQL first development

GraphQL First Development

Post

User

Comment

1. Design API schema Contract between frontend and backend with a shared schema language

2. Build UI and backend Parallelize with mocking, develop component-based UIs with GraphQL containers

3. Run in production Static queries make loading predictable, schema tells you which fields are being used

query Human

Page 5: Navigating your transition to GraphQL with GraphQL first development

Design your schema1

Page 6: Navigating your transition to GraphQL with GraphQL first development

• Database schema is not always relevant to frontend developers

• Apps are getting more complex, not all of your data is in a database!

D B S C H E M A

Page 7: Navigating your transition to GraphQL with GraphQL first development

• Contract between frontend and backend

• Declares relationships across backend data sources

• Incrementally adopt - get the API you always wanted!

# A comment submitted by a usertype Comment { # The SQL ID of this comment id: Int!

# The GitHub user who posted the comment postedBy: User!

# The text of the comment content: String!

# The repository which this comment is about repoName: String!}

G R A P H Q L S C H E M A

Page 8: Navigating your transition to GraphQL with GraphQL first development

GraphQL requests Backend fetches

Page 9: Navigating your transition to GraphQL with GraphQL first development

Incremental GraphQL Adoption

Data-Layer RedesignCombine Queries

Simplify Development

Thousands of active usersGalaxy

Page 10: Navigating your transition to GraphQL with GraphQL first development

Client

Elastic Search MongoDBAmazon Dynamo

DB

C L I E N T

A W S

Galaxy Server

Apollo Client

GraphQL Server

Page 11: Navigating your transition to GraphQL with GraphQL first development

GraphQL from the Beginning

Schema ContractParallelize Development

Schema Ownership?

Built from scratch in under 3 monthsOptics

Page 12: Navigating your transition to GraphQL with GraphQL first development

B A C K E N D F R O N T E N D

Design for different types of apps

Don’t overfit to specific features Computed fields live on the server

Components ask for exactly what they need

Generic Backend-for-

Page 13: Navigating your transition to GraphQL with GraphQL first development

Streamline your Workflow2

Page 14: Navigating your transition to GraphQL with GraphQL first development

B U I L D I N G A P P S

Product Design Engineering

Page 15: Navigating your transition to GraphQL with GraphQL first development

R E A L I T Y

Page 16: Navigating your transition to GraphQL with GraphQL first development

I D E A L

Page 17: Navigating your transition to GraphQL with GraphQL first development

Change database

Rewrite mocked data for all endpoints using it

Change schema

Update one resolver

P E R - E N D P O I N T P E R - R E S O L V E RRest Mocking GraphQL Mocking

Page 18: Navigating your transition to GraphQL with GraphQL first development

Component-First

Development

Page 19: Navigating your transition to GraphQL with GraphQL first development
Page 20: Navigating your transition to GraphQL with GraphQL first development

1. Painlessly adapted to schema changes

2. Connected front-end to back-end in under 2 days

3. Developed full app in less than 3 months

O U R E X P E R I E N C E

Page 21: Navigating your transition to GraphQL with GraphQL first development

graphql-tools

20 contributors - thanks @DxCx, @sebastienbarre, @nicolaslopezj

Implement a Node.js GraphQL schema using the schema language directly, with support for all GraphQL features

github.com/apollostack/graphql-tools

Page 22: Navigating your transition to GraphQL with GraphQL first development

graphql-tools

One-step data mocking based on schema types, customizable as much as you need.

Instrumental to GraphQL First development workflow.

github.com/apollostack/graphql-tools

Page 23: Navigating your transition to GraphQL with GraphQL first development

graphql-toolsgithub.com/apollostack/graphql-tools

Find new workflows

Managing GraphQL Development At Scale - Nick Nance

Develop new features together

Pull request by @itajaja

Page 24: Navigating your transition to GraphQL with GraphQL first development

Load Data with Queries 3

Page 25: Navigating your transition to GraphQL with GraphQL first development

GraphQL clients

Plain fetch Simple

Predictable

No UI consistency and performance features

Caching client Some work required to set up and learn

Easy to update the UI

Manage data in one place

Great dev tools

GET

Page 26: Navigating your transition to GraphQL with GraphQL first development

Incremental adoption for the client

Compatible Works with your existing client-side infrastructure

Un-opinionated Design your own schema, fit into your existing data model

Component-first Use GraphQL just one component at a time, test and reuse components

Post

User

Comment

Page 27: Navigating your transition to GraphQL with GraphQL first development

Static queries for perf and security

• Use fragments for static composition.

• Queries sent to the server are predictable, and can be optimized.

• Data requirements of app can be fully analyzed at build time.

• Better security with persisted queries.

Write your data requirements so that tooling can separate them from your UI code

Page 28: Navigating your transition to GraphQL with GraphQL first development

Code generation for result types

Write GraphQL queries

Get static typing based on schema

• Fully featured in Apollo-iOS today • Community working on TypeScript and

Flow on apollo-codegen • Work with the easy to learn GraphQL

query language, get all of the benefits of native integration

github.com/apollostack/apollo-ios github.com/apollostack/apollo-codegen

Big thanks to @rricard for working on TS and Flow!

Page 29: Navigating your transition to GraphQL with GraphQL first development

Apollo Client 0.5 dev.apollodata.com

Out today, big thanks to over 100 contributors, especially @jbaxleyiii, @rricard, @johnthepink, @abhiaiyer91, @kamilkisiela

Page 30: Navigating your transition to GraphQL with GraphQL first development

Apollo Client 0.5

• 100% GraphQL spec support: if you can type it in GraphiQL, it will work. • Fully featured: Queries, mutations, fragments, optimistic UI, pagination, and more. • Tooling friendly: Redux dev tools, static analysis, and persisted queries. • Compatible: Use it with React, React Native, Angular 1, Angular 2, Vue.js, etc. • Flexible and customizable: Fits into any architecture, customizable caching. • Futuristic: Subscriptions and custom resolvers, ideas coming from the community.

The best part is — it’s just GraphQL.

Page 31: Navigating your transition to GraphQL with GraphQL first development

GraphQL client conclusions

Use a caching client Get better UI consistency and avoid loading data you already have.

Incremental adoption and compatibility Important as you move older apps over to GraphQL, and if your tech choices change.

Static queries Predictable loading, better dev tools, clearer server insights, eventually move to persisted queries for performance and security.

Page 32: Navigating your transition to GraphQL with GraphQL first development

Monitor in Production 4

Page 33: Navigating your transition to GraphQL with GraphQL first development

1. Understand endpoint usage

2. Measure endpoint timing

3. Monitor server load

W H A T D O Y O U W A N T ?

……..

Performance

Page 34: Navigating your transition to GraphQL with GraphQL first development

1. Know exactly what fields are used and how

2. Measure field resolver performance

3. Detect breaking schema changes

……..

W H A T C A N Y O U G E T ?

Performance

Page 35: Navigating your transition to GraphQL with GraphQL first development
Page 36: Navigating your transition to GraphQL with GraphQL first development
Page 37: Navigating your transition to GraphQL with GraphQL first development

apollodata.com/optics

Execution traces Field latencies

Field usage

Optics

Page 38: Navigating your transition to GraphQL with GraphQL first development

GraphQL-First workflow

Design your schema

Implement UI and backend in parallel

Get fine-grained production understanding

Page 39: Navigating your transition to GraphQL with GraphQL first development

Sashko Stubailo Apollo Open Source

@stubailo

Danielle Man Apollo Services

@danimman

Huge thanks to the open source community!

Know anyone who wants to work on GraphQL technology full time? We’re hiring!