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 {
    id
    firstname: name
    weight
    category
    }
    }
  • Using variables in arguments - use to capture dynamic values/ user inputs

    query ($category:PetCategory $status: PetStatus) {
    allPets(category:$category status:$status) {
    id
    name
    status
    category
    }
    }
  • 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

subscription {
result {
alex
eve
}
}