Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!