hyprstack
hyprstack

Reputation: 4228

AWS appync query resolver returns null

I have the following query:

query kitchen {
  getItemKitchen(id:"fakeIdHere") {
    id
    kitchenName
  }
}

which returns:

{
  "data": {
    "getItemKitchen": null
  }
}

And have defined the query in the schema as such:

type Query @aws_cognito_user_pools
@aws_api_key {
    getItemKitchen(id: ID!): ItemKitchen

The resolver req template is:

{
    "version":"2017-02-28",
    "operation":"GET",
    "path":"/myType/myIndex/_search",
    "params": {
        "body": {
            "query": {
                "match": {
                    "id.keyword": "${context.arguments.id}"
                }
            }
        }
    }
}

And my response template:

$util.toJson($context.result.get("_source"))

I expect the following response:

{
"result": {
        "_source": {
            "id": "HelloWorldTestId",
            "createdAt": "Hello, world!"
        }
    }
}

I also have a mutation which works fine, enabling me to create items on dynamodb which is then sent to elasticsearch for querying by a lambda function.

I've checked the item exists on elasticsearch.

Both my Elasticsearch and DynamoDb instances sit in a VPC. Before adding the VPC I was able to query the elasticsearch instance and get a response. According to the docs, this kind of response means there is no resolver attached, yet the mutations seem to work just fine. I've tried removing and re-attaching the resolvers, but nothing happens.

Any help would be much appreciated as this is becoming extremely frustrating.

Upvotes: 1

Views: 879

Answers (1)

Ashwin Devendran
Ashwin Devendran

Reputation: 421

Currently, AppSync does not support Elasticsearch instances that are behind a VPC. See the first line of the documentation here:

This is why the query was working for you prior to adding the VPC.

Upvotes: 2

Related Questions