question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[aws-appsync]: implementation for appsync::functionConfiguration for Pipeline Resolvers

See original GitHub issue

Current implementation doesn’t offer customers a smooth ability to create AppSync Functions for Pipeline Resolvers.

Supersedes #6923

Use Case

If users want to utilize AppSync’s graphQL functions that are serializable and functionable.

Proposed Solution

Workaround currently would be to make Lambda Functions but these are expensive and will costly for customers.

Possible solution could be to create an class that creates AppSync Functions

interface GraphQLFunctionProps {
    dataSourceName: string,
   description: string,
   functionVersion: string,
   name: string,
   requestMappingTemplate?: MappingTemplate,
   responseMappingTemplate?: MappingTemplate,
}

class GraphQLFunction extends Construct { ... }

class GraphQLApi extends Construct {
...
  createGraphQLFunction(...);
...
}

Other

The Function that can be added to the pipelineConfig is not a Lambda Function. Instead, it is AppSync::Function.

See documentation on pipelineConfig here.

See documentation on functionConfiguration here.

See documentation on appsync:CreateFunction here.


This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
BryanPan342commented, Aug 27, 2020

It isn’t a feature yet, but will be in the works soon!

You can use the L1 constructs, specifically appsync.CfnFunctionConfiguration.

CfnFunctionConfigurationProps
/**
 * Properties for defining a `AWS::AppSync::FunctionConfiguration`
 *
 * @stability external
 * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html
 */
export interface CfnFunctionConfigurationProps {

    /**
     * `AWS::AppSync::FunctionConfiguration.ApiId`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-apiid
     */
    readonly apiId: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.DataSourceName`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-datasourcename
     */
    readonly dataSourceName: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.FunctionVersion`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-functionversion
     */
    readonly functionVersion: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.Name`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-name
     */
    readonly name: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.Description`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-description
     */
    readonly description?: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.RequestMappingTemplate`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-requestmappingtemplate
     */
    readonly requestMappingTemplate?: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.RequestMappingTemplateS3Location`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-requestmappingtemplates3location
     */
    readonly requestMappingTemplateS3Location?: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.ResponseMappingTemplate`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-responsemappingtemplate
     */
    readonly responseMappingTemplate?: string;

    /**
     * `AWS::AppSync::FunctionConfiguration.ResponseMappingTemplateS3Location`
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-responsemappingtemplates3location
     */
    readonly responseMappingTemplateS3Location?: string;
}

So to create your appsync function it would look something like this:

Creating an AppSync Function
const appsyncFunction = new appsync.CfnFunctionConfiguration(stack, 'function', {
  apiId: api.apiId,
  dataSourcename: dataSource.name,
  functionVersion: '1.0.0',
  name: 'myFunction',
  requestMappingTemplate: appsync.MappingTemplate.fromFile('filepath').renderTemplate(),
  responseMappingTemplate: appsync.MappingTemplate.fromFile('filepath').renderTemplate(),
});

And adding it to a resolver would look like the following:

Creating a Pipeline Resolver
const pipelineResolver = new appsync.Resolver(stack, 'resolver', {
  api: api,
  typeName: 'Query',
  fieldName: 'fieldName',
  pipelineConfig: [appsyncFunction.name],
});
1reaction
BryanPan342commented, Sep 11, 2020

@mattiLeBlanc i wrote up a PR for pipeline functions #10111

Luckily using the other type is not an issue but for consistency it would be better to have the Resolver accept api type GraphqlApi?

Our design guidelines make it such that using the IGraphqlApi should be the reference because that way you can have multiple stacks. To be honest, I’m suprised to hear that the typescript is complaining… maybe we need an explicit implements IGraphqlApi at the end of the class declaration…

Adding resolvers to API and supply a Datasource, or add Resolvers to the Datasources which are linked to the API?

Depends on what kind of resolver you want. In the #10111 PR, we make it so that all resolvers are under the API scope instead of the data source scope (which is more consistent with the architecture of AppSync). But generally I would say if you are making a unit resolver with a data source, it is easier to do dataSouce.createResolver(...). And in the upcoming PR, you will be able to do api.createResolver(...) for convenience and to create pipeline resolvers easily!

The only thing maybe is that it is sometimes unclear if all Roles and necessary Policies are created to execute Lambdas via resolvers etc. But for now it is trial and error.

look into the Permissions section of the readme for roles and policies!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipeline resolvers (VTL) - AWS AppSync
AWS AppSync executes resolvers on a GraphQL field. In some cases, applications require executing multiple operations to resolve a single GraphQL field.
Read more >
Building AWS AppSync Pipeline Resolvers with ... - Medium
To demonstrate, we will implement the ListPosts resolver found in Nader Dabit's Intro to AWS AppSync Pipeline Functions:.
Read more >
Pipeline resolvers in AppSync - Advanced Web Machinery
Pipeline resolvers. Recommended book. Building GraphQL APIs with AWS AppSync. How to design, implement, and deploy GraphQL-based APIs on the ...
Read more >
How to Create Nested and Pipeline Resolvers with AppSync ...
If you want to learn AppSync in the best way possible check out the course I used to learn it all. Use code...
Read more >
The anatomy of an AWS AppSync pipeline resolver
Introduction AWS AppSync is a fully managed service that allows developers to create and manage scalable APIs for their applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found