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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ