Query NerdStorage for entity scoped data.
Retrieve an entire collection or a single document.
Usage
import { EntityStorageQuery } from 'nr1'
Examples
Query collection
<EntityStorageQuery entityGuid="MTIzNDU2fEZPT3xCQVJ8OTg3NjU0Mzcz" collection="foo"> {({ loading, error, data }) => { if (loading) { return <Spinner />; }
if (error) { return 'Error!'; }
return <pre>{JSON.stringify(data, null, 4)}</pre>; }}</EntityStorageQuery>
Query document
<EntityStorageQuery entityGuid="MTIzNDU2fEZPT3xCQVJ8OTg3NjU0Mzcz" collection="foo" documentId="bar"> {({ loading, error, data }) => { if (loading) { return <Spinner />; }
if (error) { return 'Error!'; }
return <pre>{JSON.stringify(data, null, 4)}</pre>; }}</EntityStorageQuery>
Imperative query
EntityStorageQuery.query({ entityGuid: 'MTIzNDU2fEZPT3xCQVJ8OTg3NjU0Mzcz', collection: 'myCollection', documentId: 'myDocumentId',}).then(({ data }) => console.log(data));
Props
function | Render prop function as a child. function ( |
REQUIREDstring | Collection name. |
string | Document identifier to operate in. When omitted the whole collection is returned. |
REQUIREDstring | GUID of the entity in which the collection is operated. |
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. |
boolean | Establishes whether the data needs to be scoped by actor or not; that is, whether the data read or saved is common to everybody having access to the object, or it is exclusive of the user.An object (entity or account) can have both "global" data and "scoped" data, and the data read will depend on the status of the flag. |
boolean | When set to |
Methods
EntityStorageQuery.query
function (props: Object An object containing the query options. Any EntityStorageQuery
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.
}