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
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
function | Render prop function as a child. function ( |
enum | Allows you to specify how you want your query to interact with the cached data.
|
number | Interval in milliseconds to poll for new data. Set to zero to avoid any kind of regular polling. |
REQUIREDstring|object | GraphQL query, either as a string or a GraphQL document parsed into an AST by the
|
boolean | When set to |
string[] | List containing unsafe experimental namespaces your query opts in to using. |
object | Object containing all of the variables your query needs to execute. |
Methods
NerdGraphQuery.query
function (props: Object Object containing the query options. Any NerdGraphQuery
prop is a valid option except children
and pollInterval
.
) => PromiseQueryResult
Type definitions
PromiseQueryResult
{error: ApolloClient.ApolloError, Runtime error with graphQLErrors
and networkError
properties.
data: Object, Object containing the result of your query.
fetchMore: function|null, If not null
, fetchMore
allows you to load more results for your query. New data is merged with previous data.
refetch: function, Refetch the query.
}
QueryResult
{loading: boolean, Indicates that the request is in flight.
error: ApolloClient.ApolloError, Runtime error with graphQLErrors
and networkError
properties.
data: Object, Object containing the result of your query.
fetchMore: function|null, If not null
, fetchMore
allows you to load more results for your query. New data is merged with previous data.
refetch: function, Refetch the query.
}