Search code examples
amazon-web-servicesaws-lambdagraphqlaws-appsync

AWS AppSync Lambda resolver fields


I have the following query:

query xxx {
   getSomething(id: "id") {
      field1
      field2
   }
}

Is there any way for me to get field1 and field2 in lambda? For example, to query only those fields in mysql, not get all of them just to be discarded by AppSync later.

I tried logging all the $context in the request mapper VTL file but they are not there. Any ideas? Seems quite stupid to not be able to do that. The only thing I get in lambda is the id argument.

Thanks, Mihai


Solution

  • It might not be the answer you want to hear, but as you've spotted AppSync simply doesn't make the graphql (fields, or otherwise) available to you.

    The only two 'options" I can put to you are:

    • Design your query schema so that you can be more precise with your fetching (e.g. getThingFromTableA and getThingFromTableB rather than just getThing)
    • Use field resolvers for expensive to get fields, and employ nested objects if these are all from the same datasource (e.g. { cheapA, cheapB, expensiveA { expensiveTableAThingA, expensiveTableAThingB }, expensiveB }).

    n.b. it isn't that uncommon, for example Apollo doesn't by default either.