GraphQL Authentication/Authorisation And Error Handling With Apollo

Authentication/Authorisation

Where could we do access controll?

  • on Express router not on apollo itself when running on HTTP
    • get user/token with an auth middleware before reaching /graphql endpoint
    • user/token will be put in the graphql context for later use(fine-grained authorisation etc.)
  • on model layer
    • recommended by Facebook
    • good if you have a separate model layer API, for example a set of Restful APIs
  • wrapper queries
  • custom directives

Error Handling

How do we handle errors?

  • errors handled in the standard errors array on the response body with a consistent machine-readable structure
  • use error types defined by apollo-server, with custom names