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 réponse
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
répondu il y a 4 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions