Limit child object return quantity in query?

0

I want to limit the return on the child objects in a query using a pipeline resolver (JS). Below is a sample of what I'm trying to do, my actual pipeline is more complex with multiple functions.

type Parent {
  Name: String
  FamilyName:String
  Children(limit: Int): [Child]
}

type ParentConnection {
  items: [Parent]
  nextToken: String
}

type Child {
  Name: String
}

getParents(familyName: String!, limit: Int): ParentConnection 
export function request(ctx) {
  return {
    operation: 'Query',
    index: 'familyName-index',
    limit: ctx.args.limit,
    query: {
      expression: '#familyName= :familyName',
      expressionValues: util.dynamodb.toMapValues({ ':DWGName': ctx.stash.familyName}),
      expressionNames: { '#familyName': 'familyName' },
    },
  };
}

export function response(ctx) {
    return ctx.prev.result
}
query MyQuery {
  getParents(FamilyName: "Jones") {
    items {
      Name
      Children(limit: 2) {
        Name
      }
    }
  }
}

1개 답변
2

I'm not an AppSync expert, but I am a DynamoDB one. Typically when integrating with DynamoDB the limit is placed when fetching the data, as the child records are within family items here, thats not possible. So it seems what you are trying to achieve is for AppSync to return only 2 children from the response from DynamoDB and I don't believe that logic exists.

Best just to grab 2 children in your middleware return and reduce what you return to the front send client.

profile pictureAWS
전문가
답변함 4달 전

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

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

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

관련 콘텐츠