• EnglishEspañol日本語한국어Português
  • Log inStart now

AccountStorageQuery

Query NerdStorage for account scoped data.

It is possible to retrieve an entire collection or a single document.

Usage

import { AccountStorageQuery } from 'nr1'

Examples

Query collection

<AccountStorageQuery accountId={1} collection="foo">
{({ loading, error, data }) => {
if (loading) {
return <Spinner />;
}
if (error) {
return 'Error!';
}
return <pre>{JSON.stringify(data, null, 4)}</pre>;
}}
</AccountStorageQuery>

Query document

<AccountStorageQuery accountId={1} collection="foo" documentId="bar">
{({ loading, error, data }) => {
if (loading) {
return <Spinner />;
}
if (error) {
return 'Error!';
}
return <pre>{JSON.stringify(data, null, 4)}</pre>;
}}
</AccountStorageQuery>

Imperative query

AccountStorageQuery.query({
accountId: 1,
collection: 'myCollection',
documentId: 'myDocumentId',
}).then(({ data }) => console.log(data));

Props

accountId

REQUIRED
number

Account identifier.

children

function

Render prop function as a child.

function (
queryResult: QueryResult

Results of the query.

) => React.ReactNode

collection

REQUIRED
string

Collection name.

documentId

string

Document identifier to operate in. When omitted the whole collection is returned.

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.

    <One of

    AccountStorageQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK, AccountStorageQuery.FETCH_POLICY_TYPE.CACHE_FIRST, AccountStorageQuery.FETCH_POLICY_TYPE.CACHE_ONLY, AccountStorageQuery.FETCH_POLICY_TYPE.NETWORK_ONLY, AccountStorageQuery.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.

skip

boolean

When set to true, the query will be skipped entirely from rendering.

Methods

AccountStorageQuery.query

function (
props: Object

An object containing the query options. Any AccountStorageQuery 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.

}
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.