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
demandé il y a 5 ans429 vues
3 réponses
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

répondu il y a 5 ans
0

Great, thank you!

bboure
répondu il y a 5 ans
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
répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions