Skip to content

Instantly share code, notes, and snippets.

@nara-l
Last active October 23, 2019 16:59
Show Gist options
  • Save nara-l/d0f4eccbefc72423b3ce353e4e330f57 to your computer and use it in GitHub Desktop.
Save nara-l/d0f4eccbefc72423b3ce353e4e330f57 to your computer and use it in GitHub Desktop.
GraphQL - Part1 notes
// WHat is it? GraphQL
It's a consistent way for your frontend to request data from your backend. It's beatufiul because the frontend sends a query
which is in the same format as what the backend would return. Less ambiguity
e.g requesting sandwitch from backend , a gql query may be:
sandwidth {
bread
ham
cheese
}
//
GraphQL on the server side is strongly typed as well
GraphQL data types:
Scalar types:
- String
- Int
- Float
- Boolean
Default types is null.
String! ( means data type cannot be null )
To use a list type, surround the type in square brackets, so [Int] is a list of integers.
// How is this different from rest?
REST - Representational State Transfer
think about making API request for sandwidth, in rest we'll do 3 api requests:
1 for bread, 1 for ham, 1 for cheese
Graphql we have just 1 end point. The return from backend is dependent on the query from frontend APi.
// Wwhen do we need GraphQL then?
1. For large sized projects where data is changing fast. No advantage from smaller projects and smaller teams
We see that GraphQL simplifies how we return data from frontend code
GraphQL mutation:
it's a convention to indicate that data would be modified on the server
// We can write GraphQL with Apollo client - best and easiest way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment