Class: Parser
Resolver and function parser.
import { Parser } from 'aws-appsync-butler';
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');
Hierarchy
โณ
Parser
Constructors
constructor
โข new Parser(optionsOrRoot?
)
Parameters
Name | Type | Description |
---|---|---|
optionsOrRoot | string | ParserOptions | Path to VTL directory or parsing directives. |
Overrides
Methods
setVariable
โธ setVariable(key
, value
): Parser
Sets an in-memory variable for VTL file parsing.
#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
Name | Type | Description |
---|---|---|
key | string | Variable identifier |
value | string | Value |
Returns
getVariable
โธ getVariable(key
): undefined
| string
Retrieves the defined variable value.
parser.setVariable('name', 'Ali');
parser.getVariable('name'); // 'Ali'
Parameters
Name | Type | Description |
---|---|---|
key | string | Variable identifier |
Returns
undefined
| string
Variable value if set, undefined otherwise.
parseResolver
โธ parseResolver(typeName
, fieldName
): ParsedResolverInfo
Parses Resolver files including variable substitution in mapping templates, pipeline sequence defintion parsing, and data source binding.
Parameters
Name | Type | Description |
---|---|---|
typeName | string | GraphQL type name |
fieldName | string | GraphQL field name |
Returns
Parsed resolver information
parseFunction
โธ parseFunction(functionName
): ParsedFunctionInfo
Parses function files including variable substitution in mapping templates and data source binding.
Parameters
Name | Type | Description |
---|---|---|
functionName | string | Function name |
Returns
Parsed 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
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
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
Name | Type | Description |
---|---|---|
typeName | string | GraphQL type name |
Returns
string
[]
A list of GraphQL fields
Inherited from
readResolver
โธ readResolver(typeName
, fieldName
): ResolverInfo
Reads a GraphQL field resolver from disk.
Parameters
Name | Type | Description |
---|---|---|
typeName | string | GraphQL type name |
fieldName | string | GraphQL field name |
Returns
Unit or Pipeline Resolver information
Inherited from
readFunction
โธ readFunction(functionName
): FunctionInfo
Reads an AWS AppSync Function from disk.
Parameters
Name | Type | Description |
---|---|---|
functionName | string | Function name |
Returns
Function information