Class: Reader
Resolver and function reader.
import { Reader } from '@appsync-butler/core';
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');
Extended by
Constructors
new Reader()
new Reader(
optionsOrRoot):Reader
Parameters
optionsOrRoot
Path to VTL directory or reading directives
string | ReaderOptions
Returns
Properties
structure
protectedreadonlystructure:object
functions
functions:
string
functionStructure
functionStructure:
object
functionStructure.description
functionStructure.description:
string
functionStructure.request
functionStructure.request:
string
functionStructure.response
functionStructure.response:
string
pipelineStructure
pipelineStructure:
object
pipelineStructure.after
pipelineStructure.after:
string
pipelineStructure.before
pipelineStructure.before:
string
pipelineStructure.pipeline
pipelineStructure.pipeline:
string
resolvers
resolvers:
string
root
root:
string
unitStructure
unitStructure:
object
unitStructure.request
unitStructure.request:
string
unitStructure.response
unitStructure.response:
string
Methods
getFunctionPath()
protectedgetFunctionPath(functionName):string
Parameters
functionName
string
Returns
string
getResolverPath()
protectedgetResolverPath(typeName,fieldName):string
Parameters
typeName
string
fieldName
string
Returns
string
path()
protectedpath(...args):string
Parameters
args
...string[]
Returns
string
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
typeName
string
GraphQL type name
Returns
string[]
A list of GraphQL fields
readFunction()
readFunction(
functionName):FunctionInfo
Reads an AWS AppSync Function from disk.
Parameters
functionName
string
Function name
Returns
Function information
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
readResolver()
readResolver(
typeName,fieldName):ResolverInfo
Reads a GraphQL field resolver from disk.
Parameters
typeName
string
GraphQL type name
fieldName
string
GraphQL field name
Returns
Unit or Pipeline Resolver information
readSubdirsSync()
protectedreadSubdirsSync(dir,ignoreNoent):string[]
Parameters
dir
string
ignoreNoent
boolean = false
Returns
string[]
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