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

New Relic SDK provides Query components based on ApolloClient's query components. These components are an abstraction layer making it easier to query NerdGraph without worrying about configuring Apollo Client and, for the most common use cases, without having to write GraphQL queries.

A generic NerdGraph Query component that allows you to query anything from NerdGraph.

### Usage

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

### Examples

#### Example 1

```jsx
function render() {
  const query = `
      query($id: Int!) {
          actor {
              account(id: $id) {
                  name
              }
          }
      }
  `;

  const variables = {
    id: 1,
  };

  return (
    <NerdGraphQuery query={query} variables={variables}>
      {({ loading, error, data }) => {
        if (loading) {
          return <Spinner />;
        }

        if (error) {
          return "Error!";
        }

        return <BlockText>{data.actor.account.name}</BlockText>;
      }}
    </NerdGraphQuery>
  );
}
```

### Props

| `children` function                      | Render prop function as a child.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fetchPolicyType` enum                   | Allows you to specify how you want your query to interact with the cached data. - `CACHE_AND_NETWORK`: The query returns your initial data from the cache if available. However, regardless of whether or not the full data is in your cache, the query always makes a request using your network interface and returns the updated data. This option is not available when using the static `query()` method of the component. - `CACHE_FIRST`: The query makes a request using your network interface **only** if the data for your query is not already in the cache. - `CACHE_ONLY`: The query **never** makes a request using your network interface. Instead it returns the data available in the cache. If the data for your query does not exist in the cache, then an error is thrown. - `NETWORK_ONLY`: The query **never** returns your initial data from the cache. Instead it **always** makes a request using your network interface. - `NO_CACHE`: The query **never** returns your initial data from the cache. Instead it **always** makes a request using your network interface. Unlike the `NETWORK_ONLY` policy, it does not write any data to the cache after the query completes. NerdGraphQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK, NerdGraphQuery.FETCH_POLICY_TYPE.CACHE_FIRST, NerdGraphQuery.FETCH_POLICY_TYPE.CACHE_ONLY, NerdGraphQuery.FETCH_POLICY_TYPE.NETWORK_ONLY, NerdGraphQuery.FETCH_POLICY_TYPE.NO_CACHE, |
| `pollInterval` number                    | Interval in milliseconds to poll for new data. Set to zero to avoid any kind of regular polling.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `query` REQUIREDstring\|object           | GraphQL query, either as a string or a GraphQL document parsed into an AST by the `gql` method of `nr1`. ````js import { ngql } from 'nr1';  const query = ngql`   {     actor {       user {         id         email         name       }     }   } `; ```  ````                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `skip` boolean                           | When set to `true`, the query will be skipped entirely from rendering.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `unsafeExperimentalNamespaces` string\[] | List containing unsafe [experimental namespaces](https://pages.datanerd.us/unified-api/nerd-graph-docs/graphql/schema_visibility.html#experimental-api-support) your query opts in to using.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `variables` object                       | Object containing all of the variables your query needs to execute.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

### Methods

### `NerdGraphQuery.query`

### Type definitions

