Top Banner
Intro to GraphQL Vol.01 Feb/10/2017 Hiroto Fukui EC Marketplace RMS Development Department Rakuten, Inc. http://www.rakuten.co.jp/
16

Intro to GraphQL

Apr 12, 2017

Download

Technology

Rakuten, Inc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intro to GraphQL

Intro to GraphQL

Vol01 Feb102017

Hiroto Fukui

EC Marketplace RMS Development Department

Rakuten Inc

httpwwwrakutencojp

2

Typical REST API

REST API

Server

Client

application

GET itemitemId=XXX

item

itemId ldquoXXXXXrdquo

hellip

payment

paymentMethodId ldquoXXXrdquo

campaign

campaignId ldquoXXXrdquo

hellip

3

Common issues for REST API

bull Over fetching

o GEThelliporderresponseField=shippingampresponseField=payment

ampresponseField=promotion

o GET hellipuser rarr GET helliporders rarr GET hellipitem

bull Multiple IFs for multiple clients

o GET item GET mobileitem

bull Non-detailed error message in 4XX response

o POST order -gt ldquostatusrdquo 400 ldquomessagerdquo ldquobad requestrdquo

bull Managing API design changes

o Versioning

o Deprecation

o Documentation

4

GraphQL

ldquoGraphQL is a query language for your

API and a server-side runtime for

executing queries by using a type system

you define for your datardquo

httpgraphqlorglearn

5

History

bull Developed by facebook in 2012 for internal usage

bull Specification became RFC in 2015

- ldquoThis year(2015) weve begun the process of open-sourcing GraphQL

by drafting a specification releasing a reference implementation and

forming a community around it at graphqlorgrdquo

from blog post on codefacebookcom

bull Exploring GraphQL - Lee Byron React Europe 2015

bull Doc httpgraphqlorg

bull Implementations httpsgithubcomgraphql

6

GraphQL Approach

Gra

ph

QL

Client

application

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

runtime1

runtime2

runtime3

runtime4

- Parse

- Type Validation

My App

7

An real example1

httpapiendpointgraphqlquery= player(playerName Ash) name age items

name quantity

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 2: Intro to GraphQL

2

Typical REST API

REST API

Server

Client

application

GET itemitemId=XXX

item

itemId ldquoXXXXXrdquo

hellip

payment

paymentMethodId ldquoXXXrdquo

campaign

campaignId ldquoXXXrdquo

hellip

3

Common issues for REST API

bull Over fetching

o GEThelliporderresponseField=shippingampresponseField=payment

ampresponseField=promotion

o GET hellipuser rarr GET helliporders rarr GET hellipitem

bull Multiple IFs for multiple clients

o GET item GET mobileitem

bull Non-detailed error message in 4XX response

o POST order -gt ldquostatusrdquo 400 ldquomessagerdquo ldquobad requestrdquo

bull Managing API design changes

o Versioning

o Deprecation

o Documentation

4

GraphQL

ldquoGraphQL is a query language for your

API and a server-side runtime for

executing queries by using a type system

you define for your datardquo

httpgraphqlorglearn

5

History

bull Developed by facebook in 2012 for internal usage

bull Specification became RFC in 2015

- ldquoThis year(2015) weve begun the process of open-sourcing GraphQL

by drafting a specification releasing a reference implementation and

forming a community around it at graphqlorgrdquo

from blog post on codefacebookcom

bull Exploring GraphQL - Lee Byron React Europe 2015

bull Doc httpgraphqlorg

bull Implementations httpsgithubcomgraphql

6

GraphQL Approach

Gra

ph

QL

Client

application

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

runtime1

runtime2

runtime3

runtime4

- Parse

- Type Validation

My App

7

An real example1

httpapiendpointgraphqlquery= player(playerName Ash) name age items

name quantity

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 3: Intro to GraphQL

3

Common issues for REST API

bull Over fetching

o GEThelliporderresponseField=shippingampresponseField=payment

ampresponseField=promotion

o GET hellipuser rarr GET helliporders rarr GET hellipitem

bull Multiple IFs for multiple clients

o GET item GET mobileitem

bull Non-detailed error message in 4XX response

o POST order -gt ldquostatusrdquo 400 ldquomessagerdquo ldquobad requestrdquo

bull Managing API design changes

o Versioning

o Deprecation

o Documentation

4

GraphQL

ldquoGraphQL is a query language for your

API and a server-side runtime for

executing queries by using a type system

you define for your datardquo

httpgraphqlorglearn

5

History

bull Developed by facebook in 2012 for internal usage

bull Specification became RFC in 2015

- ldquoThis year(2015) weve begun the process of open-sourcing GraphQL

by drafting a specification releasing a reference implementation and

forming a community around it at graphqlorgrdquo

from blog post on codefacebookcom

bull Exploring GraphQL - Lee Byron React Europe 2015

bull Doc httpgraphqlorg

bull Implementations httpsgithubcomgraphql

6

GraphQL Approach

Gra

ph

QL

Client

application

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

runtime1

runtime2

runtime3

runtime4

- Parse

- Type Validation

My App

7

An real example1

httpapiendpointgraphqlquery= player(playerName Ash) name age items

name quantity

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 4: Intro to GraphQL

4

GraphQL

ldquoGraphQL is a query language for your

API and a server-side runtime for

executing queries by using a type system

you define for your datardquo

httpgraphqlorglearn

5

History

bull Developed by facebook in 2012 for internal usage

bull Specification became RFC in 2015

- ldquoThis year(2015) weve begun the process of open-sourcing GraphQL

by drafting a specification releasing a reference implementation and

forming a community around it at graphqlorgrdquo

from blog post on codefacebookcom

bull Exploring GraphQL - Lee Byron React Europe 2015

bull Doc httpgraphqlorg

bull Implementations httpsgithubcomgraphql

6

GraphQL Approach

Gra

ph

QL

Client

application

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

runtime1

runtime2

runtime3

runtime4

- Parse

- Type Validation

My App

7

An real example1

httpapiendpointgraphqlquery= player(playerName Ash) name age items

name quantity

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 5: Intro to GraphQL

5

History

bull Developed by facebook in 2012 for internal usage

bull Specification became RFC in 2015

- ldquoThis year(2015) weve begun the process of open-sourcing GraphQL

by drafting a specification releasing a reference implementation and

forming a community around it at graphqlorgrdquo

from blog post on codefacebookcom

bull Exploring GraphQL - Lee Byron React Europe 2015

bull Doc httpgraphqlorg

bull Implementations httpsgithubcomgraphql

6

GraphQL Approach

Gra

ph

QL

Client

application

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

runtime1

runtime2

runtime3

runtime4

- Parse

- Type Validation

My App

7

An real example1

httpapiendpointgraphqlquery= player(playerName Ash) name age items

name quantity

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 6: Intro to GraphQL

6

GraphQL Approach

Gra

ph

QL

Client

application

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

Type1- Field 1

- Field 2

Type2- Field 3

- Field 4

runtime1

runtime2

runtime3

runtime4

- Parse

- Type Validation

My App

7

An real example1

httpapiendpointgraphqlquery= player(playerName Ash) name age items

name quantity

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 7: Intro to GraphQL

7

An real example1

httpapiendpointgraphqlquery= player(playerName Ash) name age items

name quantity

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 8: Intro to GraphQL

8

An real example2

httpapiendpointgraphqlquery= player(playerName Ash) name age

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 9: Intro to GraphQL

9

Type

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 10: Intro to GraphQL

10

Alias

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 11: Intro to GraphQL

11

Validation

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 12: Intro to GraphQL

12

Versioning

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 13: Intro to GraphQL

13

Relay

bull A javascript framework for React that work with GraphQL

bull Naturally integrate GraphQL API call into React component

bull Manage cache pagination object identification

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 14: Intro to GraphQL

14

Demo Time

bull Incrementally build applications

bull From HelloWorld to calling GraphQL API from Relay app

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 15: Intro to GraphQL

15

When you should do should not do

Should

bull When you build brand new UI application with brand new API

application

bull When you tired of maintaining document up-to-date

bull When you answered inquiries from your clients 100 times

bull When you got to build hellipv3itemhellip

Should not

bull When you already got many conservative clients

bull When you have no time to maintain both REST and GraphQL during

migration

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria

Page 16: Intro to GraphQL

16

References

bull Learning GraphQL and Relay by Samer Buna

bull GraphQL official doc

bull Relay official doc

bull GraphQL with Sangria