---
title: NrqlQuery
source: https://docs.newrelic.com/docs/new-relic-solutions/build-nr-ui/sdk-component/query-and-storage/NrqlQuery
---

Fetch data to CDS via a NRQL query.

The component can return data in a format compatible with the Chart component.

### Usage

```jsx
import { NrqlQuery } from 'nr1'
```

### Examples

#### Transform data

```jsx
<NrqlQuery
  accountIds={[1]}
  query="SELECT count(*) FROM `Synthetics` SINCE 1 DAY AGO TIMESERIES AUTO FACET jobType"
>
  {({ data }) => {
    if (data) {
      // change colors to a nice pink.
      data.forEach(({ metadata }) => (metadata.color = "#F00BA5"));
    }

    return <LineChart data={data} />;
  }}
</NrqlQuery>;
```

#### Polling data

```jsx
<NrqlQuery
  pollInterval={2000}
  accountIds={[1]}
  query="SELECT count(*) FROM `Synthetics` SINCE 1 DAY AGO TIMESERIES AUTO FACET jobType"
>
  {({ data }) => {
    return <LineChart data={data} />;
  }}
</NrqlQuery>
```

#### Auto polling

```jsx
<NrqlQuery
  pollInterval={NrqlQuery.AUTO_POLL_INTERVAL}
  accountIds={[1]}
  query="SELECT count(*) FROM `Synthetics` SINCE 1 DAY AGO TIMESERIES AUTO FACET jobType"
>
  {({ data }) => {
    return <LineChart data={data} />;
  }}
</NrqlQuery>
```

### Props

| `accountId` DEPRECATED number   | > #### ⚠️ DUE NOVEMBER 1ST, 2022 > > The `accountId` prop is deprecated, use `accountIds` prop instead. Identifier of the account to execute the NRQL query against.                                                                                                                                                                                                                                                                                |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `accountIds` REQUIRED number\[] | Identifiers of accounts to execute the NRQL query against.                                                                                                                                                                                                                                                                                                                                                                                          |
| `children` function             | Render prop function as a child.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `formatType` enum               | Format of the response. NrqlQuery.FORMAT_TYPE.CHART, NrqlQuery.FORMAT_TYPE.RAW,                                                                                                                                                                                                                                                                                                                                                                     |
| `offset` number                 | Offset to apply to the computed begin_time and end_time, in epoch milliseconds. This offset is only applied when the query is open ended, that is:1. end_time is not specified, and 2. duration is specified.If these conditions are met and an offset value is present, the effective end_time will be set to offset milliseconds ending now, while the effective begin_time will be set to (offset + duration) milliseconds before that end_time. |
| `pollInterval` number\|enum     | Interval in millisecond to poll for new data or automatically set based on response data's metadata.                                                                                                                                                                                                                                                                                                                                                |
| `query` REQUIREDstring          | NRQL query. See [NRQL documentation for reference](https://docs.newrelic.com/docs/nrql/get-started/introduction-nrql-new-relics-query-language/).                                                                                                                                                                                                                                                                                                   |
| `skip` boolean                  | When set to `true`, the query will be skipped entirely from rendering.                                                                                                                                                                                                                                                                                                                                                                              |
| `timeRange` shape               | Time range to scope NRQL query time range. When only duration is provided it uses duration to query from NOW back until DURATION (aka Open ended query). When begin_time and end_time are provided it uses them to query SINCE begin_time UNTIL end_time (aka Closed query). shape `begin_time` number `duration` number `end_time` number                                                                                                          |

### Methods

### `NrqlQuery.query`

### Type definitions
