• /
  • Log in
  • Free account

NerdGraphQuery

New Relic One 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

import { NerdGraphQuery } from 'nr1'

Examples

Example 1

1
function render() {
2
const query = `
3
query($id: Int!) {
4
actor {
5
account(id: $id) {
6
name
7
}
8
}
9
}
10
`;
11
12
const variables = {
13
id: 1,
14
};
15
16
return (
17
<NerdGraphQuery query={query} variables={variables}>
18
{({ loading, error, data }) => {
19
if (loading) {
20
return <Spinner />;
21
}
22
23
if (error) {
24
return 'Error!';
25
}
26
27
return <BlockText>{data.actor.account.name}</BlockText>;
28
}}
29
</NerdGraphQuery>
30
);
31
}

Props

childrenfunction

Render prop function as a child.

function (
queryResult: {Object //

Results of the query.

) => undefined
fetchPolicyTypeenum
DEFAULT
NerdGraphQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK

Fetch policy to be used for the query.

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.

<One of
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,
>
pollIntervalnumber
DEFAULT
0

Interval in milliseconds to poll for new data.

queryrequiredstring|object

GraphQL query, either as a string or a GraphQL document parsed into an AST by the gql method of nr1.

Example 1

1
import { ngql } from 'nr1';
2
3
const query = ngql`
4
{
5
actor {
6
user {
7
id
8
email
9
name
10
}
11
}
12
}
13
`;
variablesobject

Object containing all the variables your query needs to execute.

Methods

NerdGraphQuery.render

function () => undefined

NerdGraphQuery.query

function () => undefined
Create issueEdit page
Copyright © 2021 New Relic Inc.