Skip to main content

GraphQL

data

Notes

  • can only do POST, always json
  • does not cache inherently
  • Models are needed
  • returns null if not valid
  • Queries Format:
query clientDetails ($clientId: String!) {
clientDetails (clientId: $clientId) {
firstName
lastName
clientNumber
clientId
phoneNumber
email
address {
buildingNumber
street
town
postCode
country
}
dob
}
}
  • GraphQL variables
{
"clientId":""
}

Nested Queries​

  • defined in the schema
  • Querying by ID:
    • job: (root, args) -> db.jobs.get(args.id)

Errors handling​

  • response.errors -> array of errors.

Mutations

mutation{
createJob(
companyId:"",
title:"",
description:""
)

}

Best practice​

  • Mutations -> return the whole Data rather than just the ID. Tradeoff -> expensive calls
  • you can assign response on mutations:
mutation{
job: createJob(
companyId:"",
title:"",
description:""
){
id
title
company {
id
name
}
}

}
  • create input types for mutations
mutation CreateJob($input: CreateJobInput) {
job: createJob($input: CreateJobInput) {
id
title
company {
id
name
}
}

}

Graphql variables

{
"input" :{
"companyId": "asdsad",
"title":"asdasd",
"description": "descripton"
}
}