• /
  • Log in
  • Free account

AccountsQuery

Get the list of all the accounts the user is authorized to view.

Usage

import { AccountsQuery } from 'nr1'

Examples

Declarative query

1
<AccountsQuery>
2
{({ loading, error, data }) => {
3
if (loading) {
4
return <Spinner />;
5
}
6
7
if (error) {
8
return 'Error!';
9
}
10
11
return (
12
<List items={data} rowHeight={20}>
13
{({ item }) => (
14
<ListItem key={item.id}>
15
{item.id} - {item.name}
16
</ListItem>
17
)}
18
</List>
19
);
20
}}
21
</AccountsQuery>;

Imperative query

1
AccountsQuery.query().then(({ data }) => console.log(data));

Props

childrenfunction

Render prop function as a child.

function (
queryResult: {Object //

Results of the query.

) => undefined
fetchPolicyTypeenum
DEFAULT
AccountsQuery.FETCH_POLICY_TYPE.CACHE_FIRST

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
AccountsQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK,
AccountsQuery.FETCH_POLICY_TYPE.CACHE_FIRST,
AccountsQuery.FETCH_POLICY_TYPE.CACHE_ONLY,
AccountsQuery.FETCH_POLICY_TYPE.NETWORK_ONLY,
AccountsQuery.FETCH_POLICY_TYPE.NO_CACHE,
>
pollIntervalnumber
DEFAULT
0

Interval in milliseconds to poll for new data.

Methods

AccountsQuery.render

function () => undefined

AccountsQuery.query

A static method to use AccountsQuery as a Promise instead of as a React component.

function (
props: Object //

Object containing the query options. Any AccountsQuery prop is valid as an option except children and pollInterval.

) => {Object}

Type definitions

PromiseQueryResult

{
loading: boolean, //

Indicates that the request is in flight.

data: Object, //

An object containing the result of your query.

}
Create issueEdit page
Copyright © 2021 New Relic Inc.