Class: Parser
Resolver and function parser.
import { Parser } from '@appsync-butler/core';
const parser = new Parser();
parser.readTypes(); // ['Query', 'Mutation', 'Post']
parser.readFields('Query'); // ['getPost', 'getAuthor']
const resolver = parser.parseResolver('Query', 'getPost');
parser.readFunctions(); // ['getPostById', 'getAuthorByPostId']
const func = reader.parseFunction('getPostById');
Extends
Constructors
new Parser()
new Parser(
optionsOrRoot
):Parser
Parameters
optionsOrRoot
Path to VTL directory or parsing directives.
string
| ParserOptions
Returns
Overrides
Properties
structure
protected
readonly
structure: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
Inherited from
Methods
getFunctionPath()
protected
getFunctionPath(functionName
):string
Parameters
functionName
string
Returns
string
Inherited from
getResolverPath()
protected
getResolverPath(typeName
,fieldName
):string
Parameters
typeName
string
fieldName
string
Returns
string
Inherited from
getVariable()
getVariable(
key
):undefined
|string
Retrieves the defined variable value.
parser.setVariable('name', 'Ali');
parser.getVariable('name'); // 'Ali'
Parameters
key
string
Variable identifier
Returns
undefined
| string
Variable value if set, undefined otherwise.
parseFunction()
parseFunction(
functionName
):ParsedFunctionInfo
Parses function files including variable substitution in mapping templates and data source binding.
Parameters
functionName
string
Function name
Returns
Parsed function information
parseResolver()
parseResolver(
typeName
,fieldName
):ParsedResolverInfo
Parses Resolver files including variable substitution in mapping templates, pipeline sequence defintion parsing, and data source binding.
Parameters
typeName
string
GraphQL type name
fieldName
string
GraphQL field name
Returns
Parsed resolver information
path()
protected
path(...args
):string
Parameters
args
...string
[]
Returns
string
Inherited from
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
Inherited from
readFunction()
readFunction(
functionName
):FunctionInfo
Reads an AWS AppSync Function from disk.
Parameters
functionName
string
Function name
Returns
Function information
Inherited from
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
Inherited from
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
Inherited from
readSubdirsSync()
protected
readSubdirsSync(dir
,ignoreNoent
):string
[]
Parameters
dir
string
ignoreNoent
boolean
= false
Returns
string
[]
Inherited from
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
Inherited from
setVariable()
setVariable(
key
,value
):this
Sets an AppSync Butler variable for VTL file parsing. Usually, you would not call this method directory. Instead, specify your variables in LoaderOptions.variables
#set($postId = $util.autoId())
{
"version" : "2018-05-29",
"operation" : "BatchPutItem",
"tables": {
"{{ tableName }}": [
{
"pk": $util.dynamodb.toDynamoDBJson("p-$postId"),
"sk": $util.dynamodb.toDynamoDBJson("A"),
"postTitle": $util.dynamodb.toDynamoDBJson($ctx.args.postInput.title),
"postContent": $util.dynamodb.toDynamoDBJson($ctx.args.postInput.content)
},
{
"pk": $util.dynamodb.toDynamoDBJson("u-$ctx.identity.sub"),
"sk": $util.dynamodb.toDynamoDBJson("p-$postId")
}
]
}
}
parser.setVariable("tableName", dynamodbTable.tableName);
const resolver = parser.parseResolver('Mutation', 'addPost');
Parameters
key
string
Variable identifier
value
string
Value
Returns
this