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
已提问 5 年前429 查看次数
3 回答
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

已回答 5 年前
0

Great, thank you!

bboure
已回答 5 年前
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
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则