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
preguntada hace 4 meses206 visualizaciones
1 Respuesta
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
EXPERTO
respondido hace 4 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas