Skip to main content

core.medplumclient.graphql

Home > @medplum/core > MedplumClient > graphql

MedplumClient.graphql() method

Executes a GraphQL query.

Signature:

graphql(query: string, operationName?: string | null, variables?: any, options?: MedplumRequestOptions): Promise<any>;

Parameters

Parameter

Type

Description

query

string

The GraphQL query.

operationName

string | null

(Optional) Optional GraphQL operation name.

variables

any

(Optional) Optional GraphQL variables.

options

MedplumRequestOptions

(Optional) Optional fetch options.

Returns:

Promise<any>

The GraphQL result.

Example 1

Example:

const result = await medplum.graphql(`{
Patient(id: "123") {
resourceType
id
name {
given
family
}
}
}`);

Example 2

Advanced queries such as named operations and variable substitution are supported:

const result = await medplum.graphql(
`query GetPatientById($patientId: ID!) {
Patient(id: $patientId) {
resourceType
id
name {
given
family
}
}
}`,
'GetPatientById',
{ patientId: '123' }
);

See the GraphQL documentation for more details: https://graphql.org/learn/

See the FHIR GraphQL documentation for FHIR specific details: https://www.hl7.org/fhir/graphql.html