Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

66
Vistas
How to restrict one type out of multiple types in graphql query?

Problem

I am implementing cursor-based pagination in graphql in AWS appsync schema. I want to restrict the type depending on query. For example, getBuildingsBySite should not allow any type other than Building. Currently, it allows all types in the Union. How can this be achieved?

    type Site {
      siteName: String
      address: String
      siteId: String!
      sitePicture: String
      siteImgUrl: String
    }

    type Floor {
      floorName: String
      accessPointsCount: Int
      unitsCount: Int
      wingName: String
      floorId: String!
    }

    type Building {
      buildingId: String!
      buildingName: String
      buildingAddress: String
      buildingImgUrl: String
      buildingImg: String
    }

    type PageInfo {
      hasNextPage: Boolean
      endCursor: Boolean
    }

    type Collection {
      edges: Edge
      pageInfo: PageInfo
    }

    type Edge {
      node: [Node]
      cursor: String
    }

    union Node = Site | Building | Floor

    type Query {
        getSites(first: Int, cursor: String): Collection
        getBuildingsBySite(first: Int, cursor: String, siteId: String!): Collection
        getFloorsByBuilding(first: Int, cursor: String, siteId: String!, buildingId: String!): Collection
    }

Query

 {
      getBuildingsBySite(first: 10, cursor: "xyz", siteId: "S1") {
        edges {
          node {
            ... on Site {
              siteName
              address
              address
            }

            ... on Building {
              buildingId
              buildingName
            }

            ... on Floor {
              floorId
              floorName
            }
          }
        }
      }
    }

If any better approach exists in AWS Appsync for pagination, please suggest it. Thanks

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos