Postgraphile query argument error looking up related model

Postgraphile query argument error looking up related model


0

I have Postgraphile running and exploring the queries. Based on my schema.prisma, I expected to run a GraphQL query similar to the SQL query below. The SQL query is getting all active, unclaimed shifts that a worker is eligible for. How can I update the GraphQL query to filter Facility document requirements based on the active worker ID?

For a Worker to be eligible for a facility's shift:

The Facility must be active
The Shift must be active (i.e., not deleted)
The Worker must be active
The Shift must not be claimed by someone else
The Worker must have all of the facility's required documents
The professions between the Shift and Worker must match

SQL query

select * 
from "Shift" s 
join "Facility" f on s.facility_id = f.id 
  and f.is_active = true -- Facility active
join "Worker" w on w.id = 2
  and w.is_active = true
  and w.profession = s.profession -- Shift and Worker profession match
left join "DocumentWorker" dw on dw.worker_id = w.id -- Worker has document
left join "FacilityRequirement" fr on fr.facility_id = f.id 
  and fr.document_id = dw.document_id -- Facility requires document
where s.is_deleted = false -- Shift is not deleted and not claimed
  and s.worker_id is null 

I am unable to run this GraphQL query that I was expecting to be based on the GraphQL docs:

query GetEligibleShifts($workerId: ID!) {
  allShifts(
    condition: {
      isDeleted: false,   # Shift is not deleted
      workerId: null,     # Shift is not claimed by someone else
      facilityByFacilityId: { isActive: true },  # Facility is active
      profession: CNA      # Worker's profession matches the shift's profession
    }
  ) {
    nodes {
      id
      start
      end
      profession
      workerId
      workerByWorkerId(condition: { id: $workerId, isActive: true }) {
        id
        # Other fields from the Worker type
      }
      facilityByFacilityId {
        id
        name
        facilityRequirementsByFacilityId(condition: { documentId: { isNull: false } }) {
          nodes {
            id
            facilityId
            documentId
            # Other fields from the FacilityRequirement type
          }
        }
      }
    }
  }
}

{
  "errors": [
    {
      "message": "Field "facilityByFacilityId" is not defined by type "ShiftCondition".",
      "locations": [
        {
          "line": 6,
          "column": 7
        }
      ]
    },
    {
      "message": "Unknown argument "condition" on field "Shift.workerByWorkerId".",
      "locations": [
        {
          "line": 16,
          "column": 24
        }
      ]
    },
    {
      "message": "Int cannot represent non-integer value: {isNull: false}",
      "locations": [
        {
          "line": 23,
          "column": 67
        }
      ]
    }
  ]
}

schema.prisma

enum Profession {
  CNA
  LVN
  RN
}

model Worker {
  id         Int              @id @default(autoincrement())
  name       String
  is_active  Boolean          @default(false)
  profession Profession
  shifts     Shift[]
  documents  DocumentWorker[]
}

model Facility {
  id           Int                   @id @default(autoincrement())
  name         String
  is_active    Boolean               @default(false)
  requirements FacilityRequirement[]
  shifts       Shift[]
}

model Document {
  id           Int                   @id @default(autoincrement())
  name         String
  is_active    Boolean               @default(false)
  requirements FacilityRequirement[]
  workers      DocumentWorker[]
}

model FacilityRequirement {
  id          Int      @id @default(autoincrement())
  facility_id Int
  document_id Int
  facility    Facility @relation(fields: [facility_id], references: [id])
  document    Document @relation(fields: [document_id], references: [id])
}

model DocumentWorker {
  id          Int      @id @default(autoincrement())
  worker_id   Int
  document_id Int
  worker      Worker   @relation(fields: [worker_id], references: [id])
  document    Document @relation(fields: [document_id], references: [id])
}

model Shift {
  id          Int        @id @default(autoincrement())
  start       DateTime
  end         DateTime
  profession  Profession
  is_deleted  Boolean    @default(false)
  facility_id Int
  worker_id   Int?
  worker      Worker?    @relation(fields: [worker_id], references: [id])
  facility    Facility   @relation(fields: [facility_id], references: [id])
}


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *