## MedplumClient.graphql() method

Executes a GraphQL query.

**Signature:**

```typescript
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](/content/docs/sdk/core.medplumrequestoptions) | _(Optional)_ Optional fetch options. |

**Returns:**

Promise<any>

The GraphQL result.

## Example 1

Example:

```typescript
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:

```typescript
const result = await medplum.graphql(

`query GetPatientById($patientId: ID!) {

Patient(id: $patientId) {

resourceType

id

name {

given

family

}

}

}`,

'GetPatientById',

{ patientId: '123' }

);
```

See the [GraphQL documentation](https://graphql.org/learn/) for more details.

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

- [MedplumClient.graphql() method](/content/docs/sdk/core.medplumclient.graphql#medplumclientgraphql-method/index.html)
- [Parameters](/content/docs/sdk/core.medplumclient.graphql#parameters/index.html)
- [Example 1](/content/docs/sdk/core.medplumclient.graphql#example-1/index.html)
- [Example 2](/content/docs/sdk/core.medplumclient.graphql#example-2/index.html)
