0

Heyo. I've got an AppSync resolver with a field that is attached to a resolver. The query accepts an argument that is the same argument the inner resolver would need. For the sake of terseness, I'd like to just pass it down from context instead of having to specify it. The datasource for the resolver is a dynamoDB table Say the schema looks like

type Query {
   getThings(key: String!): AResult!
}

type AResult {
   getOtherThings(key: String!): String!
}

I could construct a query as such

query Query {
  getThings(key: "123") {
    getOtherThings(key: "123")
  }
}

Which is clumsy and redundant. Ideally, I'd just want to create a query that looks like

query Query {
  getThings(key: "123") {
    getOtherThings
  }
}

And the resolver can pull key from the context of the request and reuse it. The request template for getOtherThings resolver looks like:

{
    "version": "2017-02-28",
    "operation": "Query",
    "query": {
        "expression" : "key = :key",
        "expressionValues" : {
            ":key" : $util.dynamodb.toDynamoDBJson($context.arguments.key)
        }
    }
}

But $context.guments.key is null. As is $context.args.key and $ctx.args.key and $ctx.arguments.key. If I examine the logs from the request when executing getThings I can see the expected arguments:

{
    "logType": "RequestMapping",
    "path": [
        "getThings"
    ],
    "fieldName": "getThings",
    "context": {
        "arguments": {
            "key": "123"
        },
        "stash": {},
        "outErrors": []
    },
    "fieldInError": false,
    "errors": [],
    "parentType": "Query"
}

So I surmise that the context does not persist between the parent resolver (getThings) and its child resolver (getOtherThings), but I can't make this out from the logs.

Is this even possible - I'm coming up dry on searching through AWS logs

nbpeth
  • 2,967
  • 4
  • 24
  • 34

1 Answers1

0

The answer lies in ctx.source. ctx.source is a map of the parent field, so I can grab it from there.

{
    "logType": "RequestMapping",
    "path": [
        "getThings"
    ], 
    "source": {
       "key":"123"
    },
    "fieldName": "getThings",
    "context": {
        "arguments": {
            "key": "123"
        },
        "stash": {},
        "outErrors": []
    },
    "fieldInError": false,
    "errors": [],
    "parentType": "Query"
}
nbpeth
  • 2,967
  • 4
  • 24
  • 34