36
Viacheslav Slinko CIAN Group @vslinko GraphQL Relay and

GraphQL & Relay

Embed Size (px)

Citation preview

Page 1: GraphQL & Relay

Viacheslav SlinkoCIAN Group

@vslinko

GraphQL

Relayand

Page 2: GraphQL & Relay

Problems

2

Page 3: GraphQL & Relay

Problems• UI Driven Data Fetching

• Network Op!miza!ons

• Simple API Versioning

• Incremental Rendering

3

Page 4: GraphQL & Relay

REST is resource oriented

4

Page 5: GraphQL & Relay

REST is not op!mal

5

Page 6: GraphQL & Relay

En!!es should be synchronized

6

Page 7: GraphQL & Relay

Intro

7

Page 8: GraphQL & Relay

{ me { nickname } }

GraphQL Request

8

Page 9: GraphQL & Relay

{“data”: { “me”: { “nickname”: “vslinko” } }}

GraphQL Response

9

Page 10: GraphQL & Relay

Data Layer

Applica!on Layer

GraphQL

10

Your current business logic

Library on your favorite language

Any database you want

Page 11: GraphQL & Relay

Data Layer

Applica!on Layer

GraphQL

Relay

React

11

Your current business logic

Library on your favorite language

Any database you want

Client JavaScript Framework

View Layer

Page 12: GraphQL & Relay

Good Parts

12

Page 13: GraphQL & Relay

Modern Applica!ons

13

Page 14: GraphQL & Relay

fragments: { object: () => Relay.QL` fragment on Object { title photos(width: 300) { url } } `, }

fragments: { object: () => Relay.QL` fragment on Object { title photos(width: 300) { url } } `, }

fragments: { object: () => Relay.QL` fragment on Object { title photos(width: 300) { url } } `, }

fragments: { object: () => Relay.QL` fragment on Object { title photos(width: 300) { url } } `, }

Parse Requirements

14

Page 15: GraphQL & Relay

fragments: { user: () => Relay.QL` fragment on User { favourites(first: 10) { ${ObjectView.getFragment(‘object’)} } } `, }

Compose Requirements

15

Page 16: GraphQL & Relay

fragments: { root: () => Relay.QL` fragment on RootQuery { me { balance ${ObjectView.getFragment(‘user’)} } } `, }

Send Composed Query

16

Page 17: GraphQL & Relay

Balance

User

Object

Photo 1 Photo 2 Photo 3

Execute QueryTime

17

Page 18: GraphQL & Relay

User

Object

Object

Object

PhotoPhotoPhoto

PhotoPhotoPhoto

PhotoPhotoPhoto

Render and Cache

18

Page 19: GraphQL & Relay

Data Re-usage

19

Page 20: GraphQL & Relay

There are only two hard things

in Computer Science: cache invalida!on and naming things.

20

Page 21: GraphQL & Relay

21

Page 22: GraphQL & Relay

Muta!ons• Data Changes

• Side-effects

• Declara!ve API

• Op!mis!c Updates

22

Page 23: GraphQL & Relay

Incremental Rendering

23

Page 24: GraphQL & Relay

24

GraphQL

Version 1

Applica!on

Version 1

Versioning

Ini!al release

Page 25: GraphQL & Relay

GraphQL

Version 1

Applica!on

Version 1Version 2

Versioning

New features — new fields 24

Page 26: GraphQL & Relay

GraphQL

Version 1

Applica!on

Version 1Version 2Version 3

Versioning

Change fields without problems 24

Page 27: GraphQL & Relay

GraphQL

Version 1

Applica!on

Version 997Version 998Version 999

Applica!on

Version 1

Versioning

Do not delete fields — deprecate them 24

Page 28: GraphQL & Relay

25

Page 29: GraphQL & Relay

Good Parts: Recap• Declara!ve & UI Oriented

• Very Effec!ve

• Simple Maintenance

• Extra Pre#y Features

26

Page 30: GraphQL & Relay

Bad Parts

27

Page 31: GraphQL & Relay

Verbose code

28

Page 32: GraphQL & Relay

Documenta!on is not complete

29

Page 33: GraphQL & Relay

Current Problems• No Subscrip!ons

• No Local State Management

• Complex Setup Process

30

Page 34: GraphQL & Relay

In Conclusion

31

Page 35: GraphQL & Relay

In Conclusion• Tries to Solve All Problems

• Simple but Not Easy

• Growing Community

32

Page 36: GraphQL & Relay

Thanks! Ques!ons?

h"p://bit.ly/gr-notes

Viacheslav SlinkoCIAN Group

@vslinko