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 Answer
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
EXPERT
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions