Queries
When a GraphQL statement is run at the system level, rather than against a particular resource, the first thing the query must do is select the resource(s) of interest. The logic of this follows the FHIR search API, but reimplements in a GraphQL centric way.
There are two (2) ways to query, for a single resource, and a list of resources. For a single resource, the client names the type of the resource, and provides an id:
{ patient (id: "7d79bddd-dc3c-41c7-afb7-902451ff8ab4") { id, active } }
The output from this is a single Patient resource:
{ "data" : { "Patient" { "id" : "7d79bddd-dc3c-41c7-afb7-902451ff8ab4", "active" : "true" } } }
Alternatively, the client can ask for a list of resources by pluralizing the resource in the query. The query option supports search parameters where as the single resource query does not. These queries also support paging and the pageInfo type as many resources may be returned.
{ patients (active: true, count: 10) { edges { node { id, active } } pageInfo { hasNextPage continuationToken } } }
Include
It is possible to include resources that are referenced by a resource (similar to a SQL join). In the following example, the PractitionerRole resource references a practitioner, we can retrieve the name and any other fields we wish to from the referenced practitioner.
{ practitionerRoles (active: true ) { edges { node { id, active, practitioner { resource { ... on Practitioner { id name } } } } } } pageInfo { hasNextPage continuationToken } } }
Reverse Include
It's also possible to include resources that reference a resource. An example of this use is to look up PractitionerRoles, and also retrieve all the Group resources that reference the PractitionerRole. As per the capability statement this is an actual supported reverse reference in Directory (e.g. Group.member). In GraphQL this is implemented as a GraphQL field on the PractitionerRole resource with a special resolver. These fields simply replace the decimal in the FHIR field specification with "As". So in the case of PractitionerRole, Group.member references the PractitionerRole, therefore there is a GraphQL field on PractitionerRole called GroupAsMember.
{ practitionerRoles (active: true ) { edges { node { id, active, groupAsMember { id name member { entity { reference } } } } } pageInfo { hasNextPage continuationToken } } }
For detailed GraphQL examples please refer to the GraphQL Schema Definition (GID-2510465)