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
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠