Notes about GraphQL¶
GraphQL basics¶
-
- describe your data
- ask for what you want
- get predictable results
A GraphQL service defines types and fields on those types. A function is created for each field on each type.
field can be a specific type (like String) or an Object
arguments can be passed to fields when making a query
{ human(id: "1000") { name height } }
GraphQL schema and types
type Character { name: String! appearsIn: [Episode]! }- GraphQL Object type
Character - fields
nameandappearsIn - Scalar type
String !non-nullable (will always return a value when queried)- array
[Episode]
- GraphQL Object type
Arguments
- every field can have 0 or more arguments
- all arguments are named
- all arguments are passed by name specifically (unlike JS or Python where functions take a list of ordered arguments
- required or optional
Scalar types
- fields that resolve to real data
- leaves of the query
- default scalar types:
IntFloatStringBooleanIDunique identifier
- custom scalar types are possible i.e.
Date Enums
Modifiers: Non-Null and List (array)
- List [] can be null
- a member of the list can not be null or it will generate an error
- []! the actual list can not be null though a member can be null
Introspection is a beautiful thing; ask for
__schemafor all the good stuff on the types
GraphQL Client needs¶
- Pagination
- plurals
- slicing
- pagination and edges
- Connections
- Caching
- ID
- pros and cons of globally unique IDs
- server defined or client derived are both options