Skip to main content

Class: Reader

Resolver and function reader.

import { Reader } from 'aws-appsync-butler';
const reader = new Reader();
reader.readTypes(); // ['Query', 'Mutation', 'Post']
reader.readFields('Query'); // ['getPost', 'getAuthor']
const resolver = reader.readResolver('Query', 'getPost');

reader.readFunctions(); // ['getPostById', 'getAuthorByPostId']
const func = reader.readFunction('getPostById');

Hierarchy

Constructors

constructor

โ€ข new Reader(optionsOrRoot?)

Parameters

NameTypeDescription
optionsOrRootstring | ReaderOptionsPath to VTL directory or reading directives

Methods

readFunctions

โ–ธ readFunctions(): string[]

Reads the on-disk function directory names. Essentially, the first-level subdirectories of functions are read.

vtl
โ”œโ”€โ”€ functions
โ”‚ โ””โ”€โ”€ GetPostById
โ”‚ โ”œโ”€โ”€ request.vtl
โ”‚ โ””โ”€โ”€ response.vtl
โ””โ”€โ”€ resolvers
reader.readFunctions(); // ['GetPostById']

Returns

string[]

A list of function names


readTypes

โ–ธ readTypes(): string[]

Reads the on-disk GraphQL type names. Essentially, the first-level subdirectories of resolvers are read.

vtl
โ”œโ”€โ”€ functions
โ””โ”€โ”€ resolvers
โ”œโ”€โ”€ Mutation
โ””โ”€โ”€ Query
โ””โ”€โ”€ Post
reader.readTypes(); // ['Mutation', 'Query', 'Post']

Returns

string[]

A list of GraphQL types


readFields

โ–ธ readFields(typeName): string[]

Reads the on-disk GraphQL field names. Essentially, the second-level subdirectories of resolvers are read.

vtl
โ”œโ”€โ”€ functions
โ””โ”€โ”€ resolvers
โ”œโ”€โ”€ Mutation
โ””โ”€โ”€ Query
โ””โ”€โ”€ getPost
โ”œโ”€โ”€ request.vtl
โ””โ”€โ”€ response.vtl
reader.readFields('Query'); // ['getPost']

Parameters

NameTypeDescription
typeNamestringGraphQL type name

Returns

string[]

A list of GraphQL fields


readResolver

โ–ธ readResolver(typeName, fieldName): ResolverInfo

Reads a GraphQL field resolver from disk.

Parameters

NameTypeDescription
typeNamestringGraphQL type name
fieldNamestringGraphQL field name

Returns

ResolverInfo

Unit or Pipeline Resolver information


readFunction

โ–ธ readFunction(functionName): FunctionInfo

Reads an AWS AppSync Function from disk.

Parameters

NameTypeDescription
functionNamestringFunction name

Returns

FunctionInfo

Function information