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
PDF. Data sources and resolvers are how AWS AppSync translates GraphQL requests and fetches information from your AWS resources. AWS AppSync has support for automatic provisioning and connections with certain data source types.
From the schema editor in the AWS AppSync console, on the right side, choose Attach Resolver for getPost(id:ID!): Post . Choose your Lambda data source. In the request mapping template section, choose Invoke And Forward Arguments. In the response mapping template section, choose Return Lambda Result.
Create A Pipeline ResolverIn the AWS AppSync console, go to the Schema page. We are going to wire a pipeline resolver to the signUp field on the Mutation type. In the Mutation type on the right side, choose Attach resolver next to the signUp field. On the Create Resolver page, click on the Switch to Pipeline button.
In the AWS AppSync console choose the Queries tab on the left hand side. The pane on the right side enables you to click through the operations, including queries, mutations, and subscriptions that your schema has exposed. Choose the Mutation node to see a mutation.
A resolver defines how a GraphQL field gets its value, such as what database query should AppSync run when a query needs that field, or what HTTP request to send. AppSync supports several resolver types, and one of them is the Lambda resolver.
From the schema editor in the AWS AppSync console, on the right side choose Attach Resolver for getPost (id:ID!): Post . Choose your AWS Lambda data source.
The AWS::AppSync::Resolver resource defines the logical GraphQL resolver that you attach to fields in a schema. Request and response templates for resolvers are written in Apache Velocity Template Language (VTL) format.
Now that we’ve registered an AWS Lambda data source and a valid GraphQL schema, we can connect our GraphQL fields to our Lambda data source using resolvers. To create a resolver, we’ll need mapping templates.
AppSync now supports getting the GraphQL Info object. You can get the list of requested columns from the selectionSetList variable.
The layout of the Info object:
{
"fieldName": "string",
"parentTypeName": "string",
"variables": { ... },
"selectionSetList": ["string"],
"selectionSetGraphQL": "string"
}
An example passing the selectionSetList property to a lambda resolver:
{
"version" : "2017-02-28",
"operation": "Invoke",
"payload": {
"arguments": $utils.toJson($ctx.args),
"selectionSetList": $utils.toJson($ctx.info.selectionSetList),
"selectionSetGraphQL": $utils.toJson($ctx.info.selectionSetGraphQL)
}
}
Note: If you are trying to pass the selectionSetList then you need to specifically reference it (like in the example above). The list will not be available if the info object is passed in directly with something like $utils.toJson($ctx.info)
.
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:
getThingFromTableA
and getThingFromTableB
rather than just getThing
){ cheapA, cheapB, expensiveA { expensiveTableAThingA, expensiveTableAThingB }, expensiveB }
).n.b. it isn't that uncommon, for example Apollo doesn't by default either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With