Aws appsync - Selection set

0

Hi,

I am currently building a Graphql API using AWS App sync and I was wondering if there was a way to get the current Selection Set from the query in the resolvers / request template.
I did not find anything in the Utility reference (https://docs.aws.amazon.com/appsync/latest/devguide/resolver-util-reference.html) and after debugging, I do not see anything either in the lambda event/context variables.

I think this would be very useful in order to optimise DB requests inside the resolvers and only get exactly the fields you need instead of just filtering them out in the response (app sync does that automatically). Getting ALL possible fields results in an unnecessary overhead when you just need a few of them.

On top of that, in some cases, that would allow us when possible to do batch resolving like this projects does with Neo4j: https://github.com/neo4j-graphql/neo4j-graphql-js

In fact, I would expect something like the info field in Apollo: https://www.apollographql.com/docs/graphql-tools/resolvers.html#Resolver-function-signature

That sounds like something that could easily be done. Would this be something you would consider implementing?

Thank you!

bboure
gefragt vor 5 Jahren429 Aufrufe
3 Antworten
0

Hi,

That feature request makes sense to me, I'll bring it back to the team for discussion and prioritization. Thanks for the feedback!

Thanks,
Jeff

beantwortet vor 5 Jahren
0

Great, thank you!

bboure
beantwortet vor 5 Jahren
0

It is a long time since this question was posted and indeed the AppSync team added the requested functionality.

First, they added to the context object the selection set list (ctx.info.selectionSetList).

Second, they updated the DynamoDB Tutorial to include an example of using the selection set list as the projection argument to DynamoDB, as suggested:

import { util } from '@aws-appsync/utils';

export function request(ctx) {
  return dynamoDBGetItemRequest(ctx);
}

export function response(ctx) {
  return ctx.result;
}

/**
 * A helper function to get a DynamoDB item
 */
function dynamoDBGetItemRequest(ctx) {
  return {
    operation: 'GetItem',
    key: util.dynamodb.toMapValues({ id: ctx.args.id}),
    projection: {
      expression : ctx.info.selectionSetList.join(",")
    }
  }
}
MLGuy
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen