Skip to main content

Load resolvers

Up until now, we have not interacted with AppSync Butler. We have

  1. Defined a GraphQL schema.
  2. Setup the resolvers.
  3. Instantialized the AppSync API construct.

The AppSync construct is not yet aware of the on-disk resolvers. AppSync Butler handles this process seamlessly. To load on-disk resolvers and functions, use Loader or SstLoader for CDK and SST applications respectively

stacks/MyStack.ts
import { StackContext, AppSyncApi } from "@serverless-stack/resources";
import { SstLoader as Loader } from '@appsync-butler/sst';

export function MyStack({ stack }: StackContext) {
const api = new AppSyncApi(stack, "api", {
schema: "graphql/index.graphql"
});
const loader = new Loader(stack, { api });
loader.load();
stack.addOutputs({
GraphQlApiEndpoint: api.url,
});
}
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 = new Loader(this, { api, defaultUnitResolverDataSource: 'none' });

For other options that you may pass, check CDK:LoaderOptions or SST:LoaderOptions.