Appsync created with CDK, Query not showing results

0

I created an AppSync API via the console, referencing an existing table. It works well (query list returns all the table records)

I then created an AppSync API via CDK. I copied into my project the schema from the console version. I defined the table. I added a Resolver for the "query list"

I see the datasource and schema in the cdk version if API. From the console I run the list query. The response is: { "data": { "listMyTables": { "nextToken": null, "items": null } } }

I see in the CloudwatchLogs the full table has been retrieved. Perhaps there is some "mapping" between the schema.graphql and the cdk parameters, so the information can populate the "items" in the response?

2개 답변
0

Hello,

I understand that you have created AppSync API using CDK, which is returning null response for listMyTables query.

Here is a blogpost example on creating AppSync API, using CDK:

https://aws.amazon.com/blogs/mobile/building-scalable-graphql-apis-on-aws-with-cdk-and-aws-appsync/

In order to troubleshoot this issue, we require details that are specific to AppSync API deployment in your account. We need to evaluate schema definition, resolver, data source, permissions and AppSync logs for your API. Please open a support case with AWS, including these details, using this link

AWS
지원 엔지니어
Isha_K
답변함 2년 전
profile picture
전문가
검토됨 14일 전
0

Thank you Isha. I opened a support case and received a helpful answer. I ended up having to provide more detail in my resolver. I copied the code that was generated in the "console" created api, and pasted it in like below. With this change, the API functioned as expected:

change from this:

datasource.createResolver({
        typeName: 'Query',
        fieldName: 'listCctSharedCallRoutingGlobalDbs',
        requestMappingTemplate: MappingTemplate.dynamoDbScanTable(),
        responseMappingTemplate: MappingTemplate.dynamoDbResultList(),
      });

to this:

datasource.createResolver({
      typeName: 'Query',
      fieldName: 'listCctSharedCallRoutingGlobalDbs',
      requestMappingTemplate: MappingTemplate.fromString(`
      #set( $ListRequest = {
        "version": "2018-05-29"
      } )
      #if( $context.args.nextToken )
        #set( $ListRequest.nextToken = $context.args.nextToken )
      #end
      #if( $context.args.limit )
        #set( $ListRequest.limit = $context.args.limit )
      #end
      $util.qr($ListRequest.put("operation", "Scan"))
      $util.toJson($ListRequest)
    `),
      responseMappingTemplate: MappingTemplate.fromString(`
      #if( $ctx.error)
        $util.error($ctx.error.message, $ctx.error.type)
      #else
        $util.toJson($ctx.result)
      #end
      `),
    });
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠