core.medplumclient.graphql | Medplum

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

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.

See the FHIR GraphQL documentation for FHIR specific details.