Search for entities.
Usage
import { EntitySearchQuery } from 'nr1'
Examples
Declarative query
function render() { const filters = [ { type: EntitySearchQuery.FILTER_TYPE.TAG, value: { key: 'environment', value: 'production' }, }, ];
return ( <EntitySearchQuery filters={filters}> {({ loading, error, data, fetchMore }) => { if (loading) { return <Spinner />; }
if (error) { return 'Error!'; }
return ( <List items={data.entities} rowCount={data.count} rowHeight={20} onLoadMore={fetchMore} > {({ item }) => <ListItem key={item.guid}>{item.name}</ListItem>} </List> ); }} </EntitySearchQuery> );}
Fetch with sorting criteria
<EntitySearchQuery entityDomain="APM" sortType={[EntitySearchQuery.SORT_TYPE.ALERT_SEVERITY]}> {({ data, error, fetchMore }) => { if (error) { return 'Error!'; }
return ( <List items={data.entities} rowCount={data.count} rowHeight={20} onLoadMore={fetchMore} > {({ item }) => <ListItem key={item.guid}>{item.name}</ListItem>} </List> ); }}</EntitySearchQuery>
Imperative query
EntitySearchQuery.query({ filters: [ { type: EntitySearchQuery.FILTER_TYPE.TAG, value: { key: 'environment', value: 'production' }, }, ],}).then(({ data }) => console.log(data));
Fetch more results using imperative query
const filters = [ { type: EntitySearchQuery.FILTER_TYPE.TAG, value: { key: 'environment', value: 'production' }, },];
const firstPage = await EntitySearchQuery.query({ filters });
console.log('First page data', firstPage.data);
const cursor = firstPage.data.nextCursor;const secondPage = await EntitySearchQuery.query({ cursor, filters });
console.log('Second page data', secondPage.data);
// NOTE: To fetch multiple page results consecutively, use EntitySearchQuery// component's fetchMore approach.
Props
function | Render prop function as a child. function ( |
string | Domain of the entities you want to query. |
object | GraphQL fragment document parsed into an AST by
|
string[] | GUID of the entities to query. |
string | Type of the entities you want to query. |
enum | Allows you to specify how you want your query to interact with the cached data.
|
string|(shape|shape|shape)[] | Filters used to narrow down the entities.This is an array of filters, and there are 3 possible filters:
|
boolean | If |
boolean | If |
boolean | |
boolean | If |
number | Pagination, number of entities to fetch for on each page. |
string | Name or partial name of the entities to query. |
number | Interval in milliseconds to poll for new data. Set to zero to avoid any kind of regular polling. |
boolean | When set to |
DEPRECATED | Due November 1st, 2023The sortBy is deprecated, use sortType instead |
enum[] | Array of criteras used to sort the entity search results. <Array of |
Methods
EntitySearchQuery.query
function (props: Object Object containing the query options. Any EntitySearchQuery
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.
}