Function: createAppSyncMiddleware()
createAppSyncMiddleware<
TSource,TContext,TArgs>(fn):IMiddlewareFunction<TSource,TContext,TArgs>
Defined in: appSyncMiddleware.ts:68
Creates a properly-typed AppSync middleware function.
When using @ttoss/appsync-api, the info object passed to resolvers has
the AppSync-specific shape (AppSyncInfo), not the standard
GraphQLResolveInfo expected by graphql-middleware. This helper lets you
write middlewares with the correct AppSync info type while remaining
compatible with the BuildSchemaInput.middlewares array.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSource | unknown |
TContext | unknown |
TArgs | unknown |
Parameters
| Parameter | Type |
|---|---|
fn | AppSyncMiddlewareFn<TSource, TContext, TArgs> |
Returns
IMiddlewareFunction<TSource, TContext, TArgs>
Example
import { createAppSyncMiddleware } from '@ttoss/appsync-api';
const timingMiddleware = createAppSyncMiddleware(
async (resolve, source, args, context, info) => {
const start = Date.now();
const resolverName = `${info.parentTypeName}.${info.fieldName}`;
try {
const result = await resolve(source, args, context, info);
console.log(`${resolverName} took ${Date.now() - start}ms`);
return result;
} catch (error) {
console.error(`${resolverName} failed after ${Date.now() - start}ms`);
throw error;
}
}
);