Skip to content

Simple, Intuitive API

IdentityFlow provides a clean and developer-friendly API for defining and managing workflows using familiar TypeScript/JavaScript patterns.

import { defineWorkflow } from '@identity-flow/sdk';
// This binding helper facilitates creating typed GraphQL clients
// See @identity-flow/binding-graphql and gql.tada documentation
import { createGraphqlClient } from '@identity-flow/sdk/bindings/graphql';
// Define a stable binding function for lazy injection
const GraphqlClient = () => createGraphqlClient();
export default defineWorkflow(
{
name: 'user-approval', // Name moved into config object
},
async (flow) => {
// Option 1: Lazy-load and cache the GraphQL client
const client = flow.use(GraphqlClient);
await flow.do('fetch-data-1', async () => {
const data = await client.request('{ user { id } }'); // Example query
});
// Options 2: Directly use the GraphQL client via task context
await flow.do('fetch-data-2', async ({ use }) => {
const data = await use(GraphqlClient).request('{ user { name } }'); // Example query
});
},
);

Key API Design Principles:

  • Code-First: Define workflows directly in your codebase using TypeScript or JavaScript.
  • Declarative Style: Clearly express workflow logic with helper functions like flow.do(), flow.sleep(), flow.use().
  • Lazy Loading: Efficiently manage external service integrations (like GraphQL clients) with flow.use().
  • Async/Await: Leverage modern JavaScript features for clean asynchronous code.

This approach empowers developers to build complex automations without a steep learning curve, integrating seamlessly with existing development practices.

See our Workflow Rules for best practices.