SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
Adding GraphQL to our REST APIs
without writing a single custom resolver
Declarative GraphQL
Bryan Kane
! @bryanskane
" bryan-coursera
2
REST APIs at Coursera
4
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
584
resources
1352
endpoints
70
services
30
backend devs
Chapter 4:
Lessons

in DX
5
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Benefits of Naptime
6
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
APIs are consistent:

Every API returns data in the same format and handles requests in
the same way

Lower cost:

Building new APIs requires much lower time investment

and fewer lines-of-code required

Type safety / correctness checking:

APIs are validated for correctness at compile time
Chapter 4:
Lessons

in DX
REST isn’t perfect, even with Naptime
7
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Loading related data isn’t well defined:

Requires multiple roundtrips or one-off models with weird syntax

API discovery is hard:

If a developer can’t find an existing API, they’ll build their own
Communities are important:

Maintaining a library [and documentation] in house is expensive
Chapter 4:
Lessons

in DX
Our GraphQL Story
9
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
GraphQL is closer to perfect…
Solves almost every problem that we had with our REST APIs:

• API discoverability is much easier with GraphiQL

• Nested / related data is intuitive

• There’s a standard [and a spec] behind it
Chapter 4:
Lessons

in DX
10
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
… but getting there is harder
We don’t want to write 584 resolvers by hand.

• Developers are lazy

• Requires keeping two services in sync

• Schema design could be inconsistent
Chapter 4:
Lessons

in DX
11
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
So we automated it
Naptime gives us three important things:

• A schema that defines available endpoints

• Detailed type information about parameters

• Schema definitions for all response bodies
Chapter 4:
Lessons

in DX
12
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Adapting to GraphQL
Built a new service that could:

• Parse API schemas and build a unified GraphQL schema

• Resolve GraphQL queries against our REST APIs
Chapter 4:
Lessons

in DX
13
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Schema Design
type CoursesV1 {
id: String!
slug: String!
...more fields
}
type CoursesV1Resource {
myWatchlist(limit: Int = 100, start: String): CoursesV1Connection!
bySlug(slug: String!, limit: Int = 100, start: String): CoursesV1Connection!
getAll(limit: Int = 100, start: String): CoursesV1Connection!
get(id: String!): CoursesV1
multiGet(ids: [String!]!, limit: Int = 100, start: String): CoursesV1Connection!
}
type CoursesV1Connection {
elements: [CoursesV1]!
paging: ResponsePagination!
}
Chapter 4:
Lessons

in DX
14
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Schema Design
type CoursesV1Resource {
myWatchlist(...): CoursesV1Connection!
bySlug(...): CoursesV1Connection!
getAll(...): CoursesV1Connection!
get(...): CoursesV1
multiGet(...): CoursesV1Connection!
}
type root {
coursesWatchlist(...): CoursesV1Connection!
courseBySlug(...): CoursesV1Connection!
allCourses(...): CoursesV1Connection!
course(...): CoursesV1
courses(...): CoursesV1Connection!
}
Linking It All Together
15
16
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Data Relations are Powerful
query CoursePageQuery {
CoursesV1Resource {
course(limit: 123) {
instructor {
name
university {
slug
country
}
}
myEnrollments {
grade
}
}
}
}
17
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Backend APIs are a black box
• Joining arbitrary data is easy in a relational database,

joining across APIs is harder

• We have no control over backend systems
• Most data is stored in Cassandra, a NoSQL database
• This requires explicit indexes on data for lookups

• We want to keep services as independent as possible
18
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Three types of relationships
model A knows about model B
Course Instructor
model Course {
id
slug
instructorIds
}
model Instructor {
id
name
}
19
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Three types of relationships
Course Instructor
model Course {
id
slug
}
model A doesn’t know about model B

model B knows about model A
model Instructor {
id
name
courseIds
}
20
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Three types of relationships
Course Instructor
model Course {
id
slug
}
model A doesn’t know about model B

model B doesn’t know about model A
model Instructor {
id
name
}
21
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Forward Relationships
These are easy — just fetch the data you need by ID
courseResource.withRelations(
"instructors" -> MultiGetRelation(
resourceName = "instructors.v1",
ids = “$instructorIds",
arguments = Map("includeHidden" -> "true"))
22
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Reverse Relationships
• Define an endpoint on resource B to lookup by model A
• Define in resource A how to look up on resource B
resource.withRelations(
"instructors" -> FinderReverseRelation(
resourceName = "instructors.v1",
finderName = “byCourseId",
arguments = Map("courseId" -> "$id"))
23
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Resources with no connection
Define a new resource that can link the two resources together,
and use a reverse relationship.
Learnings in

Developer Experience
25
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Declarative over Imperative
• On the client, GraphQL is great for defining your data needs, not
how to fetch the data

• We took the same approach for adding GraphQL and relations
on the backend:
• Developers define the structure of their data and
relationships, but not how to fetch the data
26
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Large migrations are expensive
• It takes many resources to convert our client API calls

from REST to GraphQL.

• If we had to pay another cost on the backend for each resource,
migrating to GraphQL would be too expensive
27
Chapter 1:
Coursera’s

REST APIs
Chapter 2:
Adapting to
GraphQL
Chapter 3:
Linking the
Resources
Chapter 4:
Lessons

in DX
Figure out schemas before building products
• We initially built out our assembler service without support for
reverse relations.

• If we had defined our ideal schemas for products before building
anything, we would’ve seen that this was a requirement.
Thanks!
Bryan Kane
! @bryanskane
" bryan-coursera

Mais conteúdo relacionado

Semelhante a Declarative GraphQL: Adding GraphQL to our REST APIs without writing a single custom resolver

GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfKnoldus Inc.
 
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...apidays
 
GraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessGraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessConnected Data World
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPAndrew Rota
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 
GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022Soham Dasgupta
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/MeteorWhy UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/MeteorJon Wong
 
Why UI developers love GraphQL
Why UI developers love GraphQLWhy UI developers love GraphQL
Why UI developers love GraphQLSashko Stubailo
 
GraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptxGraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptxSoham Dasgupta
 
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or ServerlessYour API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or ServerlessQAware GmbH
 
How to Deploy a GraphQL API A Comprehensive Guide.docx
How to Deploy a GraphQL API A Comprehensive Guide.docxHow to Deploy a GraphQL API A Comprehensive Guide.docx
How to Deploy a GraphQL API A Comprehensive Guide.docxssuser5583681
 
Let's start GraphQL: structure, behavior, and architecture
Let's start GraphQL: structure, behavior, and architectureLet's start GraphQL: structure, behavior, and architecture
Let's start GraphQL: structure, behavior, and architectureAndrii Gakhov
 
Advanced search and Top-K queries in Cassandra
Advanced search and Top-K queries in CassandraAdvanced search and Top-K queries in Cassandra
Advanced search and Top-K queries in CassandraStratio
 
Diving into GraphQL, React & Apollo
Diving into GraphQL, React & ApolloDiving into GraphQL, React & Apollo
Diving into GraphQL, React & ApolloNikolas Burk
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB
 
Camunda GraphQL Extension (09/2017 Berlin)
Camunda GraphQL Extension (09/2017 Berlin)Camunda GraphQL Extension (09/2017 Berlin)
Camunda GraphQL Extension (09/2017 Berlin)Harald J. Loydl
 
RACK-Tool-ICSE2017
RACK-Tool-ICSE2017RACK-Tool-ICSE2017
RACK-Tool-ICSE2017Masud Rahman
 

Semelhante a Declarative GraphQL: Adding GraphQL to our REST APIs without writing a single custom resolver (20)

GraphQL-ify your APIs
GraphQL-ify your APIsGraphQL-ify your APIs
GraphQL-ify your APIs
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
Serverless GraphQL with AWS AppSync & AWS Amplify
Serverless GraphQL with AWS AppSync & AWS AmplifyServerless GraphQL with AWS AppSync & AWS Amplify
Serverless GraphQL with AWS AppSync & AWS Amplify
 
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
 
GraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessGraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database access
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
Graphql
GraphqlGraphql
Graphql
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/MeteorWhy UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
 
Why UI developers love GraphQL
Why UI developers love GraphQLWhy UI developers love GraphQL
Why UI developers love GraphQL
 
GraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptxGraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptx
 
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or ServerlessYour API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
 
How to Deploy a GraphQL API A Comprehensive Guide.docx
How to Deploy a GraphQL API A Comprehensive Guide.docxHow to Deploy a GraphQL API A Comprehensive Guide.docx
How to Deploy a GraphQL API A Comprehensive Guide.docx
 
Let's start GraphQL: structure, behavior, and architecture
Let's start GraphQL: structure, behavior, and architectureLet's start GraphQL: structure, behavior, and architecture
Let's start GraphQL: structure, behavior, and architecture
 
Advanced search and Top-K queries in Cassandra
Advanced search and Top-K queries in CassandraAdvanced search and Top-K queries in Cassandra
Advanced search and Top-K queries in Cassandra
 
Diving into GraphQL, React & Apollo
Diving into GraphQL, React & ApolloDiving into GraphQL, React & Apollo
Diving into GraphQL, React & Apollo
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
 
Camunda GraphQL Extension (09/2017 Berlin)
Camunda GraphQL Extension (09/2017 Berlin)Camunda GraphQL Extension (09/2017 Berlin)
Camunda GraphQL Extension (09/2017 Berlin)
 
RACK-Tool-ICSE2017
RACK-Tool-ICSE2017RACK-Tool-ICSE2017
RACK-Tool-ICSE2017
 

Último

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Último (20)

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 

Declarative GraphQL: Adding GraphQL to our REST APIs without writing a single custom resolver

  • 1. Adding GraphQL to our REST APIs without writing a single custom resolver Declarative GraphQL Bryan Kane ! @bryanskane " bryan-coursera
  • 2. 2
  • 3. REST APIs at Coursera
  • 4. 4 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources 584 resources 1352 endpoints 70 services 30 backend devs Chapter 4: Lessons
 in DX
  • 5. 5 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX
  • 6. Benefits of Naptime 6 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources APIs are consistent:
 Every API returns data in the same format and handles requests in the same way
 Lower cost:
 Building new APIs requires much lower time investment
 and fewer lines-of-code required
 Type safety / correctness checking:
 APIs are validated for correctness at compile time Chapter 4: Lessons
 in DX
  • 7. REST isn’t perfect, even with Naptime 7 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Loading related data isn’t well defined:
 Requires multiple roundtrips or one-off models with weird syntax
 API discovery is hard:
 If a developer can’t find an existing API, they’ll build their own Communities are important:
 Maintaining a library [and documentation] in house is expensive Chapter 4: Lessons
 in DX
  • 9. 9 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources GraphQL is closer to perfect… Solves almost every problem that we had with our REST APIs:
 • API discoverability is much easier with GraphiQL
 • Nested / related data is intuitive
 • There’s a standard [and a spec] behind it Chapter 4: Lessons
 in DX
  • 10. 10 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources … but getting there is harder We don’t want to write 584 resolvers by hand.
 • Developers are lazy
 • Requires keeping two services in sync
 • Schema design could be inconsistent Chapter 4: Lessons
 in DX
  • 11. 11 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources So we automated it Naptime gives us three important things:
 • A schema that defines available endpoints
 • Detailed type information about parameters
 • Schema definitions for all response bodies Chapter 4: Lessons
 in DX
  • 12. 12 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Adapting to GraphQL Built a new service that could:
 • Parse API schemas and build a unified GraphQL schema
 • Resolve GraphQL queries against our REST APIs Chapter 4: Lessons
 in DX
  • 13. 13 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Schema Design type CoursesV1 { id: String! slug: String! ...more fields } type CoursesV1Resource { myWatchlist(limit: Int = 100, start: String): CoursesV1Connection! bySlug(slug: String!, limit: Int = 100, start: String): CoursesV1Connection! getAll(limit: Int = 100, start: String): CoursesV1Connection! get(id: String!): CoursesV1 multiGet(ids: [String!]!, limit: Int = 100, start: String): CoursesV1Connection! } type CoursesV1Connection { elements: [CoursesV1]! paging: ResponsePagination! } Chapter 4: Lessons
 in DX
  • 14. 14 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Schema Design type CoursesV1Resource { myWatchlist(...): CoursesV1Connection! bySlug(...): CoursesV1Connection! getAll(...): CoursesV1Connection! get(...): CoursesV1 multiGet(...): CoursesV1Connection! } type root { coursesWatchlist(...): CoursesV1Connection! courseBySlug(...): CoursesV1Connection! allCourses(...): CoursesV1Connection! course(...): CoursesV1 courses(...): CoursesV1Connection! }
  • 15. Linking It All Together 15
  • 16. 16 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Data Relations are Powerful query CoursePageQuery { CoursesV1Resource { course(limit: 123) { instructor { name university { slug country } } myEnrollments { grade } } } }
  • 17. 17 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Backend APIs are a black box • Joining arbitrary data is easy in a relational database,
 joining across APIs is harder
 • We have no control over backend systems • Most data is stored in Cassandra, a NoSQL database • This requires explicit indexes on data for lookups
 • We want to keep services as independent as possible
  • 18. 18 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Three types of relationships model A knows about model B Course Instructor model Course { id slug instructorIds } model Instructor { id name }
  • 19. 19 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Three types of relationships Course Instructor model Course { id slug } model A doesn’t know about model B
 model B knows about model A model Instructor { id name courseIds }
  • 20. 20 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Three types of relationships Course Instructor model Course { id slug } model A doesn’t know about model B
 model B doesn’t know about model A model Instructor { id name }
  • 21. 21 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Forward Relationships These are easy — just fetch the data you need by ID courseResource.withRelations( "instructors" -> MultiGetRelation( resourceName = "instructors.v1", ids = “$instructorIds", arguments = Map("includeHidden" -> "true"))
  • 22. 22 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Reverse Relationships • Define an endpoint on resource B to lookup by model A • Define in resource A how to look up on resource B resource.withRelations( "instructors" -> FinderReverseRelation( resourceName = "instructors.v1", finderName = “byCourseId", arguments = Map("courseId" -> "$id"))
  • 23. 23 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Resources with no connection Define a new resource that can link the two resources together, and use a reverse relationship.
  • 25. 25 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Declarative over Imperative • On the client, GraphQL is great for defining your data needs, not how to fetch the data
 • We took the same approach for adding GraphQL and relations on the backend: • Developers define the structure of their data and relationships, but not how to fetch the data
  • 26. 26 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Large migrations are expensive • It takes many resources to convert our client API calls
 from REST to GraphQL.
 • If we had to pay another cost on the backend for each resource, migrating to GraphQL would be too expensive
  • 27. 27 Chapter 1: Coursera’s
 REST APIs Chapter 2: Adapting to GraphQL Chapter 3: Linking the Resources Chapter 4: Lessons
 in DX Figure out schemas before building products • We initially built out our assembler service without support for reverse relations.
 • If we had defined our ideal schemas for products before building anything, we would’ve seen that this was a requirement.
  • 28.