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 conveniently retrieve a CDK or SST Loader instance, we can utilize the createLoader function.

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();
}
}
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.