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
      }
    }
  }
}

KapKerm
已提问 4 个月前206 查看次数
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 个月前

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

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

回答问题的准则

相关内容