Load resolvers
Up until now, we have not interacted with AppSync Butler. We have
- Defined a GraphQL schema.
- Setup the resolvers.
- Instantialized the AppSync API construct.
The AppSync construct is not yet aware of the on-disk resolvers.
AppSync Butler handles this process seamlessly. To conveniently
retrieve a CDK or SST Loader instance, we can utilize the createLoader
function.
- Serverless Stack Toolkit
- AWS Cloud Development Kit
stacks/MyStack.ts
import * as sst from "@serverless-stack/resources";
import { createLoader } from 'aws-appsync-butler';
export default class MyStack extends sst.Stack {
constructor(scope: sst.App, id: string, props: sst.StackProps) {
super(scope, id, props);
const api = new sst.AppSyncApi(this, "api", {
graphqlApi: { schema: "graphql/index.graphql" }
});
const loader = createLoader(this, { api });
loader.load();
}
}
lib/app-stack.ts
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { GraphqlApi } from '@aws-cdk/aws-appsync';
import { createLoader } from 'aws-appsync-butler';
export class AppStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const api = new GraphqlApi(this, "api", {
name: "time-pingpong-api"
});
const loader = createLoader(this, { api });
loader.load();
}
}
tip
Instead of explicitly associating resolvers with data sources in request mapping templates, you can specify a default data source when creating the loader.
const loader = createLoader(this, { api, defaultUnitResolverDataSource: 'none' });
For other options that you may pass, check LoaderOptions.