GraphQL

How do we get responces from server?

Create a method

GetUser

GetUserById

GetUserByIdWithPic

GetUserByIdWithoutPic

GetUser2

GetUserById2

GetUserByIdWithPic2

GetUserByIdWithoutPic2

pros

  • Fast (one big method)
  • Cheep
  • Happy client (0 hours on architecture)
  • Not extendable
  • Copy/paste
  • Not flexible
  • A lot of bugs

Cons

RESTful

RESTful

pros

  • Easy (no bugs)
  • Flexible
  • Extendable
  • Difficult to implement
  • Too slow
  • Too many data

Cons

RESTful is a pattern

let's build something new

Too slow

Add new request: multiple 

Get -> Users

Get -> User/id:4

Get -> User/id:1

Get -> User/id:3

Get -> User/id:2

Get -> User/id:N

Too slow

Add new request: multiple 

Get -> Users

Multiple -> (Get -> User/id:1, Get -> User/id:2 ... Get -> User/id:N)

Too much data

Add mask to method

Get -> User/id:1, mask: ('firstName', 'lastName')

Get -> User/id:1

Too difficult

(((((

 

Facebook

What is GraphQL?

https://facebook.github.io/graphql/

Graph query language

{
  "user": {
    "id": 4,
    "name": "Vladimir Dashukevich",
    "smallPic": "https://cdn.site.io/pic-4-64.jpg",
    "bigPic": "https://cdn.site.io/pic-4-1024.jpg"
  }
}
{
  user(id: 4) {
    name
  }
}
{
  "user": {
    "name": "Vladimir Dashukevich"
  }
}
query withFragments {
  user(id: 4) {
    friends(first: 10) {
      ...friendFields
    }
    mutualFriends(first: 10) {
      ...friendFields
    }
  }
}

fragment friendFields on User {
  id
  name
  profilePic(size: 50)
}

Types

type Person {
  name: String
  age: Int
  picture: Url
}
{
  "name": "Mark Zuckerberg",
  "age": 30,
  "picture": "http://some.cdn/picture.jpg"
}
type Person {
  name: String
  age: Int
  picture: Url
  relationship: Person
}

Main points

  • things that you really need
  • formal models
  • no methods
  • front-end doesn't depend on back-end
  • no problems with deprecated API
  • tests

The mainest point

It is standart

What should be done

  • Parse request
  • Serialize/deserialize data

graphQL.js

http://graphql.org/docs/getting-started/

GraphQL + React = Relay)))

Questions

GraphQL

By Vladimir

GraphQL

  • 164