Skip to content

Instantly share code, notes, and snippets.

@bushidocodes
Last active February 23, 2018 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bushidocodes/fce9ffcb7d2ab6e0965855c4bfb3904f to your computer and use it in GitHub Desktop.
Save bushidocodes/fce9ffcb7d2ab6e0965855c4bfb3904f to your computer and use it in GitHub Desktop.
GraphQL Notw

Why does GraphQL exist?

  • Difficult to scale REST-ful conventions out to nested sets of data.
  • When dealing with normalized data, retrieving state likely ends up requiring multiple HTTP requests.
  • Usuallys returns all data associated with a particular model, even if the consumer doesn't need this data.

Tradeoffs with REST

  • Follow RESTful conventions strictly, issue multiple HTTP requests, and force the consumer to compose the data together
  • Develop more sophisticated backend routes that nest using RESTful conventions, simplifying the API for the consumer but increasing backend complexity
  • Abandon RESTful conventions and create a custom routes that feeds the precise need by a particular application use case

Overserving by default

Also, usually a route will return all of the data associated with a particular model, even if the consumer doesn't need this data, which increases network payload.

GraphQL wants to simplify RESTful routing and reduce oversharing

Graph models our data using a Graph Data Structure of

  • Nodes
  • Relations (called edges)

GraphQL Query

What are the names of the companies where users connected to user 23 work?

query {
  user(id: '23') {
    users {
      company {
        name
      }
    }
  }
}
+++++++++++++++++++++++     +++++++++++++++++++++++     +++++++++++++++++++++++   
+ GraphiQL front-end  +  => + GraphQL Server      +  => + Mock Discovery Src  +
+++++++++++++++++++++++     +++++++++++++++++++++++     +++++++++++++++++++++++     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment