Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(appsync): Fails with error "Only one resolver is allowed per field." in using 1.91.0 #13238

Closed
pdlug opened this issue Feb 23, 2021 · 5 comments
Labels
@aws-cdk/aws-appsync Related to AWS AppSync guidance Question that needs advice or information.

Comments

@pdlug
Copy link

pdlug commented Feb 23, 2021

❓ General Issue

The Question

After upgrading to 1.91.0 from 1.90.1 my AppSync API is failing with the error:

Only one resolver is allowed per field. (Service: AWSAppSync; Status Code: 400; Error Code: BadRequestException; Request ID: ea61d8d6-1d06-4009-8054-8a2493ceb42b; Proxy: null)

My API has a mix of templated resolvers and a Lambda, none are duplicated as far as I can tell. Here is the relevant code:

const api = new appsync.GraphqlApi(this, "API", {
  name: "dataset-requests",
  schema: appsync.Schema.fromAsset("graphql/schema.graphql"),
  authorizationConfig: {
    defaultAuthorization: {
      authorizationType: appsync.AuthorizationType.API_KEY,
      apiKeyConfig: {
        expires: cdk.Expiration.after(cdk.Duration.days(365)),
      },
    },
  },
  xrayEnabled: true,
});

const dataSource = api.addDynamoDbDataSource("dataSource", table);

dataSource.createResolver({
  typeName: "Query",
  fieldName: "getDatasetRequests",
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});

dataSource.createResolver({
  typeName: "Mutation",
  fieldName: "createDatasetRequest",
  requestMappingTemplate: appsync.MappingTemplate.fromFile(
    "lib/appsync/templates/Mutation.createDatasetRequest.req.vtl",
  ),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(),
});

dataSource.createResolver({
  typeName: "Query",
  fieldName: "getDatasetRequestById",
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbGetItem("id", "id"),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(),
});

const graphqlLamda = new lambdaNodeJS.NodejsFunction(this, "GraphQLLambda", {
  entry: "../lambda-graphql/src/graphql/index.ts",
  handler: "handler",
  runtime: lambda.Runtime.NODEJS_14_X,
  environment: {
    TABLE_NAME: table.tableName,
  },
});
table.grantFullAccess(graphqlLamda);

// Set the new Lambda function as a data source for the AppSync API
const lambdaDs = api.addLambdaDataSource("lambdaDatasource", graphqlLamda);

lambdaDs.createResolver({
  typeName: "Mutation",
  fieldName: "approveDatasetRequest",
});

lambdaDs.createResolver({
  typeName: "Mutation",
  fieldName: "rejectDatasetRequest",
});

--

Environment

  • CDK CLI Version: 1.91.0
  • Module Version: @aws-cdk/aws-appsync 1.91.0
  • Node.js Version: v14.15.1
  • OS: macOS Big Sur
  • Language (Version): TypeScript 4.2

Other information

@pdlug pdlug added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Feb 23, 2021
@github-actions github-actions bot added the @aws-cdk/aws-appsync Related to AWS AppSync label Feb 23, 2021
@MrArnoldPalmer
Copy link
Contributor

Hey there, so this is a result of the fix we did for #12635. There seems to be an issue with AppSync in CFN where ordering of delete/create operations causes duplicates to occur when replacing existing resolvers. I created this issue to track that: #13269

Right now they only workaround is to remove the resolver resources, deploy that to the stack, then add them back and redeploy. If you want to avoid downtime, you can spin up a parallel instance of the GraphqlAPI construct in a new stack, point your clients to that, and then remove the old one.

@bigkraig
Copy link

Parallel instances won't work if you use API keys, as you cannot specify the key value when creating them.

@MrArnoldPalmer MrArnoldPalmer removed their assignment Jun 21, 2021
@NGL321 NGL321 removed the needs-triage This issue or PR still needs to be triaged. label Jul 23, 2021
@peterwoodworth
Copy link
Contributor

Closing this, any concerns with this should go to #13269

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@simiyu1
Copy link

simiyu1 commented Sep 20, 2021

I had this issue for the last 2 days... My structure is several microservices expose their schemas to AppSync which then compiles them to gether with their resolvers into one. My bug was caused by one microservice that was trying to create the resolver's datasource. The fix was to ensure that no microservices is trying to create the datasources. Create is only done by Appsync API..

Might be worth looking into if you are also facing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

6 participants