Skip to main content

FHIR GraphQL API Implementation Guide

Architectural Alignment​

Our implementation maintains strict compliance with HL7 FHIR's GraphQL specification while introducing targeted enhancements for developer experience and performance optimization.


Core Query Patterns​

Entity Access Methods​

# Single resource fetch
query {
Patient(id: "3fa85f64-5717-4562-b3fc-2c963f66afa6") {
name { given family }
}
}

# Basic collection retrieval
query {
PatientList(name: "Smith") {
id
birthDate
}
}

# Paginated results
query {
PatientConnection(count: 50, active: "true") {
pagesize
next
edges {
resource {
... on Patient {
identifier { system value }
}
}
}
}
}

Implementation Notes:

  • PatientList: a single bounded page, up to count results (default 10, max 1000). No cursor and no offset — offset is rejected outright, not silently ignored, because this server pages by continuation token. There is no way to see a second page of a PatientList.
  • PatientConnection: cursor-based pagination via the cursor argument and the response's next field. Use it for anything that might need more than one page.
  • count bounds how many rows you may see, not how many rows matched or exist. A response with fewer edges than the count you asked for is not a signal that the data is exhausted — see Pagination System before writing any loop that stops on a short page.
  • Search parameters mirror FHIR's standard search criteria for each resource type

Mutation Framework​

Standard Operations​

mutation {
PatientCreate(resource: { name: [{ given: "Joe", family: "Smith" }] }) {
id
meta { lastUpdated }
}
}

mutation {
PatientUpdate(id: "123", resource: { active: false }) {
active
}
}

mutation {
PatientDelete(id: "456") {
id
reference
}
}

PatientUpdate and PatientCreate return the updated/created Patient directly — there is no success/resource wrapper. PatientDelete returns a bare reference (id, reference), not the deleted resource.

Key Design Decisions:

  • Delete operations return resource references for audit trail verification
  • A mutation either returns its resource or raises a GraphQL error — there is no separate success/failure field
  • Error conditions return granular exception details while preserving FHIR error formats

Search Implementation Details​

Parameter Encoding​

# OR within a single parameter: comma-separate the values, not &
query {
ObservationConnection(
code: "http://loinc.org|8310-5,http://loinc.org|8867-4"
) {
edges { resource { ... on Observation { valueQuantity { value } } } }
}
}

# Modifier syntax
query {
ConditionList(onset_date: "ge2023-01-01") {
recordedDate
}
}

Pagination System​

Cursor Mechanics​

A *Connection response has exactly three fields: pagesize (echoes the count you requested), next (a cursor, or null), and edges (the rows). There is no pageInfo, no totalCount, no hasNextPage — none of those fields exist, on any resource. HL7's GraphQL binding defines count as the total number of matching resources, but the only total this server could compute is counted before your own authorization check runs — publishing it, under count, totalCount, or any other name, would tell you how much data other roles or other tenants hold. So no total is served, by any name.

# Initial page request
query {
MedicationRequestConnection(count: 25, status: "active") {
pagesize
next
edges { resource { ... on MedicationRequest { dosageInstruction } } }
}
}

# Subsequent page request — pass the previous response's `next` back as `cursor`
query {
MedicationRequestConnection(cursor: "eW91ci1j...ursorLTAwMQ==", status: "active") {
next
edges { resource { ... on MedicationRequest { authoredOn } } }
}
}

Keep paging until next comes back null — and even then, read that as "no more results for you," not "no more data exists." next is null in two different situations: there genuinely is no further page, or a row on the page you just received was withheld from you by an authorization check. The two look identical from the client.

A short page is never a signal that the data is exhausted, on its own or in combination with anything else. Rows are filtered for your authorization after the server picks the page, so count bounds how many results you may see, not how many rows matched or exist. If even one row on a page was withheld from you, next comes back null on that same response — pagination silently stops there for you, even if later pages hold rows you're entitled to see. A page with a non-null next only happens when nothing on it was withheld. Loop on next, never on edges.length versus count.

Cursor Features:

  • Opaque string — do not parse it or construct one by hand
  • Minted for the caller who received it; not meaningful to any other caller
  • Server-side state management for consistent result ordering

Type System Strategy​

FHIR Type Implementation​

# Quantity inheritance example
fragment QuantityDetails on Quantity {
value
unit
system
code
}

query {
Observation(id: "bp") {
valueQuantity { ...QuantityDetails }
}
}

Design Rationale:

  • Flattened type hierarchy reduces schema complexity
  • Shared structures maintain FHIR compatibility
  • Type extensions possible through custom scalar fields
  • Schema introspection fully supported for discovery