How to access nested args in an AWS AppSync __resolveReference resolver

25 Views Asked by At

Say I have the below partial schema in a subgraph backed by AWS AppSync:

type Query @extends {
  _entities(representations: [_Any!]!): [_Entity]!
}

type Banana @key(fields: "id") @extends {
  id: ID! @external
  """
  List of trees bananas grow on.
  """
  trees(treeType: String): Trees
}

union _Entity = Banana

input _Any {
  __typename: String!
  ids: [String]
  id: String
}

Assuming I'm using a Lambda to resolve the Banana reference, how can I access the argument to trees? When I invoke the resolver through the AppSync console with the below query:

query MyQuery {
  _entities(representations: {__typename: "Banana", id: "12345"}) {
    ... on Banana {
      id
      trees(treeType: "Big tree") {
        id
      }
    }
  }
}

I get the following event in the Lambda:

"event": {
  "arguments": {
    "__typename": "Banana",
    "id": "12345"
  },
  "identity": {
    ...
  },
  "source": null,
  "request": {
    "headers": {
      ...
    },
    "domainName": null
  },
  "prev": null,
  "info": {
    "selectionSetList": [],
    "selectionSetGraphQL": "{\n  ... on Banana {\n    id\n    trees(treeType: \"Big tree\") {\n        id\n      }\n  }\n}",
    "fieldName": "_entities",
    "parentTypeName": "Query",
    "variables": {}
  },
  "stash": {}
}

Is my only option to parse selectionSetGraphQL? Or is this an issue with my schema/AppSync? Parsing selectionSetGraphQL doesn't feel idiomatic, and my gut is saying code smell.

0

There are 0 best solutions below