1. Context
  2. Introduction

Context

Context Services

The IdentityHub provides various services through the GraphQL context that can be used in custom resolvers, schema extensions, and business logic. These services abstract common functionality and provide consistent APIs for interacting with external systems.

Available Context Services

Messaging

The Messaging provides a unified API for sending messages through different transports (email, SMS, webhooks, etc.). It handles transport configuration, error handling, and provides a consistent interface regardless of the underlying transport technology.

Key features:

  • Multiple transport support (SMTP, with more coming)
  • Automatic message formatting and validation
  • Consistent error handling across all transports
  • Transport-agnostic API design
  • Configuration-driven transport selection

Other Context Services

The GraphQL context also provides access to other services like:

  • LDAP: For directory operations
  • Userapp: For workflow and permission management
  • Alfresco: For document management operations
  • Workflow: For process automation

Usage Pattern

Context services follow a consistent pattern:

export const myCustomResolver = async (source, args, context) => {
	// Access services through context
	const { messaging, templating, ldap, userapp } = context;

	// Use services to implement business logic
	const user = await ldap.findUserById(args.userId);

	// Generate localized content using template service
	const emailBody = context.templating.render(
		`<h1><%~ t('welcome.greeting', { name: data.user.givenName }) %></h1>`,
		{
			data: { user },
		},
		context, // Pass GraphQL context for locale detection
	);

	const result = await context.messaging.send({
		transport: 'smtp',
		to: user.mail,
		subject: t('notification.email_subject', { ns: 'templating' }),
		html: emailBody,
	});

	return result;
};