Context

A context is data source that is kept as saved and passed to every GraphQL or Rest Api execution, like Resolver on GraphQL and req in express rest api. Following is sent to each request:

  • user: The current user if logged in.
  • permissions: The given permissions to the user.
  • dbTables: Database models(Mongoose or Sequelize)
  • models: Wertik models
  • context: Custom context passed from configuration
  • createContext: Context(data) created from createContext method from context.
  • sendEmail: Method to send emails.
  • emailTemplates: All email templates including templates sent from configuration

Context in GraphQL

Consider this resolver in GraphQL:


function (_, args, context,info) {
  // You can access wertik context through context.[context_name], including configuration passed context.
}

You can access context with context.[context_name].

Context in Rest API

Consider this rest api handler:


function (req,res) {
  // context is available in req.[context_name] and configuration passed context is available at req.context
}

Context is available in req.[context_name] and configuration passed context is available at req.context