SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
React and GraphQL
at Stripe
Sashko Stubailo
Engineering Manager, Dashboard Discovery
@stubailo
O V E R V I E W
1. How GraphQL fits into the modern
product development stack
2. Novel tools that we built at Stripe
3. Unexpected benefits we're excited about
M Y B A C K G R O U N D
1. Since 2015: Worked on open source GraphQL
tooling at Apollo: Apollo Client, Server, etc
2. Since late 2018: Engineer on Stripe dashboard
platform team, helped build out GraphQL
implementation
Important note: Everything I'm about to present was
a team effort! It takes a village to build these things.
Developing in the
Stripe Dashboard
• Lots of product teams
contributing at once
• Needs to work together as a
unified whole
S T R I P E ' S W E B S TA C K
• React
• Flow
• Jest
• Webpack
• Ruby
• GraphQL and Apollo (new)
GraphQL: Define a schema instead of a list of endpoints
/authors
/authors/1
/posts
/posts/1
From separate API requests to one GraphQL query
Fetch as few or as many fields
as you want in one query, and
traverse between types
Queries are sent over POST
requests to a single /graphql
endpoint
Simple front-end data fetching
How do we make product
development better?
P R O D U C T D E V E L O P M E N T
Frontend
API
Backend
P R O D U C T D E V E L O P M E N T
Components
API
Backend
State
management
Tests
Backend
Component
explorer
Editor
CI
Monitoring
Type
generation
P R O D U C T D E V E L O P M E N T
Components
API
Backend
State
management
Tests
Backend
Component
explorer
Editor
CI
Monitoring
Type
generation
The most valuable systems are those that can
tie in to all of these aspects of development.
Example: UI component systems
P R O D U C T D E V E L O P M E N T
Components
GraphQL API
Backend
Apollo
Tests
Backend
Component
explorer
Editor
CI
Monitoring
Type
generation
P R O D U C T D E V E L O P M E N T
Components
GraphQL API
Backend
Apollo
Tests
Backend
Component
explorer
Editor
CI
Monitoring
Type
generation
GQL
GQL
GQL
GQL
GQL
GQL
GQL
Why does GraphQL have such a big impact?
The schema defines capabilities Queries define data requirements
Why does GraphQL have such a big impact?
Area GraphQL's benefit
Frontend state Sophisticated data loading and management libraries
API Incremental schema changes without versioning
Monitoring Track individual field usage
Tests Easy mocking
Frontend types Static types per-query
GraphQL contributes to every part of the workflow:
Tools we've built at Stripe:
Data mocking
Why mocking?
Write unit tests and examples
without having to call a real API
• Faster, more resilient tests
• Possible to develop components
before backend is built
• Easy to generate edge case
states
Frontend
Fake API
GraphQL makes mocking easy
We can generate mocks automatically from a schema and query.
Code snippet with graphql-tools:
Problem: What about edge cases?
A globally mocked schema isn't well suited to test...
Error states
Long lists
Loading indicators
Counting
number of
requests
Per-request
mocking
Allows you to specify
edge cases for this test,
but now you lose the
benefits of schema-
based mocking.
(Example from the
Apollo docs)
Schema mocking
with overrides
Best of both worlds:
Automatic mocks for
general testing, and the
ability to override specifics
for a single test.
E X A M P L E S : S E T T I N G U P G L O B A L M O C K S
This will allow most
components to be
rendered without any
custom mocks at all.
E X A M P L E : D E F A U LT M O C K S
In this example, we're just trying to check if the component renders
correctly. The specific data isn't important, so we don't need to
specify anything.
E X A M P L E : O V E R R I D I N G F I E L D S
In this example, we want
to assert for the presence
of specific values in the
rendered component.
We wouldn't want to rely
on global mocks having
those specific values, so
we specify them in the
test.
M O C K F O R L O A D I N G / E R R O R S TAT E S
We've also added helpers for a very common type of edge case:
Errors and loading state.
S P Y I N G O N
M U TAT I O N S
Submitting a
form and
checking that it
succeeded
O N E M O R E T H I N G : G R A P H Q L M O C K S I N O U R C O M P O N E N T S Y S T E M
We have an internal prototyping environment called SailPen, which
Jay Divock presented at DublinJS a few months ago. It also now
supports GraphQL mocking!
Tools we've built at Stripe:
Schema validation
Collaborating on an API
You shouldn't have to be aware of the larger context when making a
small, focused API change
We need guard rails to be able to easily evolve the schema without
introducing breakages
Schema guard rails
To reduce the probability of breakages related from schema
changes, we:
1. Generate a schema.graphql file and check it in to the monorepo
2. Generate Flow types for every query with apollo-codegen
3. Run a backwards compatibility checker in CI
S C H E M A . G R A P H Q L F I L E
This file encodes the current state of the schema, and is
automatically generated and checked in from the API code.
Generating Flow types
apollo-codegen to generate Flow types for each query, mutation,
and fragment.
Q U E R Y W R A P P E R B R I N G S T H E T Y P E S T O G E T H E R
Q U E R Y W R A P P E R
Backwards compatibility checker
It's not enough to make sure that the current frontend is compatible
with the current backend in the monorepo, since there might be
people who haven't refreshed their frontend in a while.
How do we make breaking changes?
Sometimes, you just don't want a field anymore, and you've verified
that nobody is using it anymore.
You can use a two step process to make a change in this case:
1. Mark as deprecated, merge
2. Delete, merge
Note: Not yet ideal for things like modifications to an existing field.
Tools we've built at Stripe:
Monitoring
What makes GraphQL different?
The URL is no longer
meaningful, since all GraphQL
requests go to a single /graphql
path
Important information like the
query name and fields are
hidden in the POST request
body, and need to be extracted
GraphQL-specific metadata
We extract the operation name for logging and charts.
Query ownership
We assign team owners to queries so that errors get routed to the
team whose feature is broken.
Query ownership
We assign team owners to queries so that errors get routed to the
team whose feature is broken.
Benefits we've seen since
adopting GraphQL
Commonly quoted benefits
As seen on graphql.org and
apollographql.com:
• Reduced overfetching
• Self-documenting, strongly typed
schema
• Great developer tools
But there are more benefits that
weren't mentioned there that really
stood out to me at Stripe.
Image from graphql.org
B E N E F I T S T O H I G H L I G H T :
1. Great community tools and docs
2. Easy to add and remove fields from the
schema
3. Localized code changes and static types
Great community tools and docs
• Apollo Client for data fetching
• Apollo Codegen for Flow type generation
• graphql-tools for mocking
We're proud of the internal tooling we've built, but every new tool
we built in-house is something to maintain
GraphQL's well-specified nature allows these tools to be broadly
useful to many organizations
Great community tools and docs
We can leverage existing docs, and growing popularity of GraphQL,
to onboard new developers faster than with custom internal tools
Easy to add and remove fields
• We can implement things just the way we want them
• Easy to iterate on the schema later if we didn't get it right the
first time
• Low cost to having unused fields
Eliminating the field/endpoint tradeoff: In REST, 3 places to add new
data, each with tradeoffs:
1. A new endpoint
2. A new field on an existing endpoint
3. Front-end data transformation
GraphQL eliminates this tradeoff - you can always just add a field!
Easy to add and remove fields
Localized code changes and static types
• Easier to review code
• Fewer unintentional
side effects
• Faster to modify one
component
C O N C L U S I O N
1. GraphQL can make data-related tooling work together
across the stack
2. We're excited about some new tools we've built internally
3. GraphQL had additional unforeseen benefits for product
development velocity
Any questions about the talk or GraphQL in general?
Also, we're hiring at Stripe, please reach out!
Sashko Stubailo, @stubailo on Twitter

Contenu connexe

Tendances

Tendances (20)

Deep dive into SoapUI
Deep dive into SoapUIDeep dive into SoapUI
Deep dive into SoapUI
 
Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon
 
Cours Génie Logiciel 2016
Cours Génie Logiciel 2016Cours Génie Logiciel 2016
Cours Génie Logiciel 2016
 
Formation jpa-hibernate-spring-data
Formation jpa-hibernate-spring-dataFormation jpa-hibernate-spring-data
Formation jpa-hibernate-spring-data
 
Learning Docker from Square One
Learning Docker from Square OneLearning Docker from Square One
Learning Docker from Square One
 
TDD (Test Driven Developement) et refactoring
TDD (Test Driven Developement) et refactoringTDD (Test Driven Developement) et refactoring
TDD (Test Driven Developement) et refactoring
 
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
 
Kubernetes a comprehensive overview
Kubernetes   a comprehensive overviewKubernetes   a comprehensive overview
Kubernetes a comprehensive overview
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
 
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
 
Protecting your data at rest with Apache Kafka by Confluent and Vormetric
Protecting your data at rest with Apache Kafka by Confluent and VormetricProtecting your data at rest with Apache Kafka by Confluent and Vormetric
Protecting your data at rest with Apache Kafka by Confluent and Vormetric
 
Modern JavaScript Frameworks: Angular, React & Vue.js
Modern JavaScript Frameworks: Angular, React & Vue.jsModern JavaScript Frameworks: Angular, React & Vue.js
Modern JavaScript Frameworks: Angular, React & Vue.js
 
A Long Walk to Water - Lssn 3
A Long Walk to Water - Lssn 3A Long Walk to Water - Lssn 3
A Long Walk to Water - Lssn 3
 
Reactive Web Best Practices
Reactive Web Best PracticesReactive Web Best Practices
Reactive Web Best Practices
 
Introduction to Nginx
Introduction to NginxIntroduction to Nginx
Introduction to Nginx
 
Workshop Spring - Session 1 - L'offre Spring et les bases
Workshop Spring  - Session 1 - L'offre Spring et les basesWorkshop Spring  - Session 1 - L'offre Spring et les bases
Workshop Spring - Session 1 - L'offre Spring et les bases
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Java logging
Java loggingJava logging
Java logging
 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservices
 
Postman
PostmanPostman
Postman
 

Similaire à React and GraphQL at Stripe

The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
Sashko Stubailo
 

Similaire à React and GraphQL at Stripe (20)

Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJSCreate GraphQL server with apolloJS
Create GraphQL server with apolloJS
 
GraphQL for Native Apps
GraphQL for Native AppsGraphQL for Native Apps
GraphQL for Native Apps
 
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
 
James Baxley - Statically typing your GraphQL app
James Baxley - Statically typing your GraphQL appJames Baxley - Statically typing your GraphQL app
James Baxley - Statically typing your GraphQL app
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
 
Serverless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersServerless GraphQL for Product Developers
Serverless GraphQL for Product Developers
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
PyCon Korea - Real World Graphene
PyCon Korea - Real World GraphenePyCon Korea - Real World Graphene
PyCon Korea - Real World Graphene
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
 
How to use apolloJS on React ?
How to use apolloJS on React ?How to use apolloJS on React ?
How to use apolloJS on React ?
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
APIdays Paris 2019 - Maintain & Evolve a Public GraphQL API by Aurélien Davi...
APIdays Paris 2019 - Maintain & Evolve a Public  GraphQL API by Aurélien Davi...APIdays Paris 2019 - Maintain & Evolve a Public  GraphQL API by Aurélien Davi...
APIdays Paris 2019 - Maintain & Evolve a Public GraphQL API by Aurélien Davi...
 

Plus de Sashko Stubailo

Plus de Sashko Stubailo (6)

Standing out as a new grad candidate
Standing out as a new grad candidateStanding out as a new grad candidate
Standing out as a new grad candidate
 
Modular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingModular GraphQL with Schema Stitching
Modular GraphQL with Schema Stitching
 
Adding GraphQL to your existing architecture
Adding GraphQL to your existing architectureAdding GraphQL to your existing architecture
Adding GraphQL to your existing architecture
 
Why UI developers love GraphQL
Why UI developers love GraphQLWhy UI developers love GraphQL
Why UI developers love GraphQL
 
GraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsGraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend Devs
 
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern AppsMeteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Dernier (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

React and GraphQL at Stripe

  • 1. React and GraphQL at Stripe Sashko Stubailo Engineering Manager, Dashboard Discovery @stubailo
  • 2. O V E R V I E W 1. How GraphQL fits into the modern product development stack 2. Novel tools that we built at Stripe 3. Unexpected benefits we're excited about
  • 3. M Y B A C K G R O U N D 1. Since 2015: Worked on open source GraphQL tooling at Apollo: Apollo Client, Server, etc 2. Since late 2018: Engineer on Stripe dashboard platform team, helped build out GraphQL implementation Important note: Everything I'm about to present was a team effort! It takes a village to build these things.
  • 4. Developing in the Stripe Dashboard • Lots of product teams contributing at once • Needs to work together as a unified whole
  • 5. S T R I P E ' S W E B S TA C K • React • Flow • Jest • Webpack • Ruby • GraphQL and Apollo (new)
  • 6. GraphQL: Define a schema instead of a list of endpoints /authors /authors/1 /posts /posts/1
  • 7. From separate API requests to one GraphQL query Fetch as few or as many fields as you want in one query, and traverse between types Queries are sent over POST requests to a single /graphql endpoint
  • 9. How do we make product development better?
  • 10. P R O D U C T D E V E L O P M E N T Frontend API Backend
  • 11. P R O D U C T D E V E L O P M E N T Components API Backend State management Tests Backend Component explorer Editor CI Monitoring Type generation
  • 12. P R O D U C T D E V E L O P M E N T Components API Backend State management Tests Backend Component explorer Editor CI Monitoring Type generation The most valuable systems are those that can tie in to all of these aspects of development. Example: UI component systems
  • 13. P R O D U C T D E V E L O P M E N T Components GraphQL API Backend Apollo Tests Backend Component explorer Editor CI Monitoring Type generation
  • 14. P R O D U C T D E V E L O P M E N T Components GraphQL API Backend Apollo Tests Backend Component explorer Editor CI Monitoring Type generation GQL GQL GQL GQL GQL GQL GQL
  • 15. Why does GraphQL have such a big impact? The schema defines capabilities Queries define data requirements
  • 16. Why does GraphQL have such a big impact? Area GraphQL's benefit Frontend state Sophisticated data loading and management libraries API Incremental schema changes without versioning Monitoring Track individual field usage Tests Easy mocking Frontend types Static types per-query GraphQL contributes to every part of the workflow:
  • 17. Tools we've built at Stripe: Data mocking
  • 18. Why mocking? Write unit tests and examples without having to call a real API • Faster, more resilient tests • Possible to develop components before backend is built • Easy to generate edge case states Frontend Fake API
  • 19. GraphQL makes mocking easy We can generate mocks automatically from a schema and query. Code snippet with graphql-tools:
  • 20. Problem: What about edge cases? A globally mocked schema isn't well suited to test... Error states Long lists Loading indicators Counting number of requests
  • 21. Per-request mocking Allows you to specify edge cases for this test, but now you lose the benefits of schema- based mocking. (Example from the Apollo docs)
  • 22. Schema mocking with overrides Best of both worlds: Automatic mocks for general testing, and the ability to override specifics for a single test.
  • 23. E X A M P L E S : S E T T I N G U P G L O B A L M O C K S This will allow most components to be rendered without any custom mocks at all.
  • 24. E X A M P L E : D E F A U LT M O C K S In this example, we're just trying to check if the component renders correctly. The specific data isn't important, so we don't need to specify anything.
  • 25. E X A M P L E : O V E R R I D I N G F I E L D S In this example, we want to assert for the presence of specific values in the rendered component. We wouldn't want to rely on global mocks having those specific values, so we specify them in the test.
  • 26. M O C K F O R L O A D I N G / E R R O R S TAT E S We've also added helpers for a very common type of edge case: Errors and loading state.
  • 27. S P Y I N G O N M U TAT I O N S Submitting a form and checking that it succeeded
  • 28. O N E M O R E T H I N G : G R A P H Q L M O C K S I N O U R C O M P O N E N T S Y S T E M We have an internal prototyping environment called SailPen, which Jay Divock presented at DublinJS a few months ago. It also now supports GraphQL mocking!
  • 29. Tools we've built at Stripe: Schema validation
  • 30. Collaborating on an API You shouldn't have to be aware of the larger context when making a small, focused API change We need guard rails to be able to easily evolve the schema without introducing breakages
  • 31. Schema guard rails To reduce the probability of breakages related from schema changes, we: 1. Generate a schema.graphql file and check it in to the monorepo 2. Generate Flow types for every query with apollo-codegen 3. Run a backwards compatibility checker in CI
  • 32. S C H E M A . G R A P H Q L F I L E This file encodes the current state of the schema, and is automatically generated and checked in from the API code.
  • 33. Generating Flow types apollo-codegen to generate Flow types for each query, mutation, and fragment.
  • 34. Q U E R Y W R A P P E R B R I N G S T H E T Y P E S T O G E T H E R
  • 35. Q U E R Y W R A P P E R
  • 36. Backwards compatibility checker It's not enough to make sure that the current frontend is compatible with the current backend in the monorepo, since there might be people who haven't refreshed their frontend in a while.
  • 37. How do we make breaking changes? Sometimes, you just don't want a field anymore, and you've verified that nobody is using it anymore. You can use a two step process to make a change in this case: 1. Mark as deprecated, merge 2. Delete, merge Note: Not yet ideal for things like modifications to an existing field.
  • 38. Tools we've built at Stripe: Monitoring
  • 39. What makes GraphQL different? The URL is no longer meaningful, since all GraphQL requests go to a single /graphql path Important information like the query name and fields are hidden in the POST request body, and need to be extracted
  • 40. GraphQL-specific metadata We extract the operation name for logging and charts.
  • 41. Query ownership We assign team owners to queries so that errors get routed to the team whose feature is broken.
  • 42. Query ownership We assign team owners to queries so that errors get routed to the team whose feature is broken.
  • 43. Benefits we've seen since adopting GraphQL
  • 44. Commonly quoted benefits As seen on graphql.org and apollographql.com: • Reduced overfetching • Self-documenting, strongly typed schema • Great developer tools But there are more benefits that weren't mentioned there that really stood out to me at Stripe. Image from graphql.org
  • 45. B E N E F I T S T O H I G H L I G H T : 1. Great community tools and docs 2. Easy to add and remove fields from the schema 3. Localized code changes and static types
  • 46. Great community tools and docs • Apollo Client for data fetching • Apollo Codegen for Flow type generation • graphql-tools for mocking We're proud of the internal tooling we've built, but every new tool we built in-house is something to maintain GraphQL's well-specified nature allows these tools to be broadly useful to many organizations
  • 47. Great community tools and docs We can leverage existing docs, and growing popularity of GraphQL, to onboard new developers faster than with custom internal tools
  • 48. Easy to add and remove fields • We can implement things just the way we want them • Easy to iterate on the schema later if we didn't get it right the first time • Low cost to having unused fields
  • 49. Eliminating the field/endpoint tradeoff: In REST, 3 places to add new data, each with tradeoffs: 1. A new endpoint 2. A new field on an existing endpoint 3. Front-end data transformation GraphQL eliminates this tradeoff - you can always just add a field! Easy to add and remove fields
  • 50. Localized code changes and static types • Easier to review code • Fewer unintentional side effects • Faster to modify one component
  • 51. C O N C L U S I O N 1. GraphQL can make data-related tooling work together across the stack 2. We're excited about some new tools we've built internally 3. GraphQL had additional unforeseen benefits for product development velocity Any questions about the talk or GraphQL in general? Also, we're hiring at Stripe, please reach out! Sashko Stubailo, @stubailo on Twitter