3 Types of GraphQL Operations
Use query
to get data back
GraphQL argument is like a filter on particular field.
Use alias
- to send same query with different arguments ie
available
&checkedOut
- to rename any field
query {available:totalPets(status: AVAILABLE)checkedOut:totalPets(status: CHECKEDOUT)allPets {idfirstname: nameweightcategory}}- to send same query with different arguments ie
Using variables in arguments - use to capture dynamic values/ user inputs
query ($category:PetCategory $status: PetStatus) {allPets(category:$category status:$status) {idnamestatuscategory}}Send in variables by using Query Variables panel:
{"cateogry": "DOG","status": "AVAILABLE"}Shortcut Tip: CTRL-space in any graphql playground within context of query to bring up all queries/fileds are available
Use mutation
to change data
- convention is to use verbs
mutation { vote(host:EVE)}
Use subscription
to listen for data
- listens for data changes in real time over websockets
- open 2 way connection to listen in real time, when mutation comes in, it auto pushes changes to client
- [Subscriptions on Apollo Server]
- [Subscriptions on Apollo Client]
subscription { result { alex eve }}