Skip to main content

Class: Loader

Load resolvers into an AppSync GraphQL API construct.

import { Loader } from '@appsync-butler/core';
import { GraphqlApi } from '@aws-cdk/aws-appsync-alpha';
import { Table } from '@aws-cdk/aws-dynamodb';

const graphqlApi = new GraphqlApi(...);
const userTable = new Table(...);
const orderTable = new Table(...);
const userDs = graphqlApi.addDynamoDbDataSource('userDs', table);
const orderDs = graphqlApi.addDynamoDbDataSource('orderDs', table);

const loader = new Loader(appStack, {
api: graphqlApi,
defaultUnitResolverDataSource: tableDs,
defaultFunctionDataSource: 'none',
dataSources: {
orders: orderDs
},
variables: {
tableName: table.tableName
}
});
loader.load();

Constructors​

new Loader()​

new Loader(scope, options): Loader

Parameters​

scope​

Construct

A CDK construct. Usually, it is the stack instance.

options​

LoaderOptions

Loading, parsing, or reading directives.

Returns​

Loader

Properties​

api​

protected readonly api: GraphqlApi

The passed API instance.


builder​

readonly builder: Builder

The underlying builder instance that is responsible for building the resolver tree and function dictionary.


dataSources?​

protected readonly optional dataSources: Record<string, BaseDataSource>

Data source dictionary


defaultFunctionDs?​

readonly optional defaultFunctionDs: DataSource

The passed default function data source.


defaultUnitResolverDs?​

readonly optional defaultUnitResolverDs: DataSource

The passed default unit resolver data source.


functions​

readonly functions: Record<string, AppsyncFunction> = {}

The created Appsync Functions. Only populated after loading.


noneDs?​

protected optional noneDs: BaseDataSource

None data source object. Created and reused when necessary.


scope​

protected readonly scope: Construct

The passed scope. Used when creating Appsync Functions

Methods​

addFunction()​

protected addFunction(func): void

Parameters​

func​

ParsedFunctionInfo

Returns​

void


addResolver()​

protected addResolver(resolver): void

Parameters​

resolver​

ParsedResolverInfo

Returns​

void


getAppSyncFunction()​

protected getAppSyncFunction(name): AppsyncFunction

Parameters​

name​

string

Returns​

AppsyncFunction


getFunctionDataSource()​

protected getFunctionDataSource(func): NonNullable<undefined | DataSource>

Parameters​

func​

ParsedFunctionInfo

Returns​

NonNullable<undefined | DataSource>


getMappingTemplate()​

Call Signature​

protected getMappingTemplate(data): MappingTemplate

Parameters​
data​

string

Returns​

MappingTemplate

Call Signature​

protected getMappingTemplate(data): undefined

Parameters​
data​

undefined

Returns​

undefined

Call Signature​

protected getMappingTemplate(data): undefined | MappingTemplate

Parameters​
data​

undefined | string

Returns​

undefined | MappingTemplate


getNoneDs()​

protected getNoneDs(): BaseDataSource

Returns​

BaseDataSource


getResolverProps()​

protected getResolverProps(resolver): Omit<BaseResolverProps, "fieldName" | "typeName">

Parameters​

resolver​

ParsedResolverInfo

Returns​

Omit<BaseResolverProps, "fieldName" | "typeName">


getUnitResolverDataSource()​

protected getUnitResolverDataSource(resolver): NonNullable<undefined | DataSource>

Parameters​

resolver​

ParsedUnitResolverInfo

Returns​

NonNullable<undefined | DataSource>


load()​

load(): void

Load on-disk resolvers and functions into AppSync.

Returns​

void


loadFunctions()​

protected loadFunctions(): void

Returns​

void


loadResolvers()​

protected loadResolvers(): void

Returns​

void


resolveDataSource()​

protected resolveDataSource(ds): BaseDataSource

Parameters​

ds​

DataSource

Returns​

BaseDataSource


resolveStringDataSource()​

protected resolveStringDataSource(ds): BaseDataSource

Parameters​

ds​

string

Returns​

BaseDataSource


throwNoDefaultFunctionDataSourceFound()​

protected throwNoDefaultFunctionDataSourceFound(noDataSourceFunction): never

Parameters​

noDataSourceFunction​

ParsedFunctionInfo

Returns​

never


throwNoDefaultUnitDataSourceFound()​

protected throwNoDefaultUnitDataSourceFound(noDataSourceResolver): never

Parameters​

noDataSourceResolver​

ParsedUnitResolverInfo

Returns​

never