Search for entities.
Usage
import { EntitySearchQuery } from 'nr1'
Examples
Declarative query
1function render() {2 const filters = [3 {4 type: EntitySearchQuery.FILTER_TYPE.TAG,5 value: { key: 'environment', value: 'production' },6 },7 ];89 return (10 <EntitySearchQuery filters={filters}>11 {({ loading, error, data, fetchMore }) => {12 if (loading) {13 return <Spinner />;14 }1516 if (error) {17 return 'Error!';18 }1920 return (21 <List22 items={data.entities}23 rowCount={data.count}24 rowHeight={20}25 onLoadMore={fetchMore}26 >27 {({ item }) => <ListItem key={item.guid}>{item.name}</ListItem>}28 </List>29 );30 }}31 </EntitySearchQuery>32 );33}
Fetch with sorting criteria
1<EntitySearchQuery2 entityDomain="APM"3 sortBy={[EntitySearchQuery.SORT_TYPE.ALERT_SEVERITY]}4>5 {({ data, error, fetchMore }) => {6 if (error) {7 return 'Error!';8 }910 return (11 <List12 items={data.entities}13 rowCount={data.count}14 rowHeight={20}15 onLoadMore={fetchMore}16 >17 {({ item }) => <ListItem key={item.guid}>{item.name}</ListItem>}18 </List>19 );20 }}21</EntitySearchQuery>;
Imperative query
1EntitySearchQuery.query({2 filters: [3 {4 type: EntitySearchQuery.FILTER_TYPE.TAG,5 value: { key: 'environment', value: 'production' },6 },7 ],8}).then(({ data }) => console.log(data));
Fetch more results using imperative query
1const filters = [2 {3 type: EntitySearchQuery.FILTER_TYPE.TAG,4 value: { key: 'environment', value: 'production' },5 },6];78const firstPage = await EntitySearchQuery.query({ filters });910console.log('First page data', firstPage.data);1112const cursor = firstPage.data.nextCursor;13const secondPage = await EntitySearchQuery.query({ cursor, filters });1415console.log('Second page data', secondPage.data);1617// NOTE: To fetch multiple page results consecutively, use EntitySearchQuery18// component's fetchMore approach.
Props
Render prop function as a child.
function (queryResult: {Object // Results of the query.
) => undefined
Domain of the entities you want to query.
GraphQL fragment document parsed into an AST by graphql-tag
.
The Query components return the most commonly used fields available on an entity. You can use this prop when you want to request additional fields for the entities returned by your query.
The fragment should be named EntityFragmentExtension
and apply to the
EntityOutline
type.
Example 1
1const entityFragmentExtension = ngql`2 fragment EntityFragmentExtension on EntityOutline {3 indexedAt4 guid5 }6`;
GUID of the entities to query.
Type of the entities you want to query.
EntitySearchQuery .FETCH_POLICY_TYPE .CACHE_AND_NETWORK
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 staticquery()
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 theNETWORK_ONLY
policy, it does not write any data to the cache after the query completes.
<One ofEntitySearchQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK,EntitySearchQuery.FETCH_POLICY_TYPE.CACHE_FIRST,EntitySearchQuery.FETCH_POLICY_TYPE.CACHE_ONLY,EntitySearchQuery.FETCH_POLICY_TYPE.NETWORK_ONLY,EntitySearchQuery.FETCH_POLICY_TYPE.NO_CACHE,>
Filters used to narrow down the entities.
This is an array of filters, and there are 3 possible filters:
SearchQueryFilter:
Object<type: string = "searchQuery", value: string>
EntityTypeFilter:
Object<type: string = "entityType", Object<domain: string, type: string>>
TagFilter:
Object<type: string = "tag", Object<key: string, value: string>>
Example 1
1const filters = [2 {3 type: 'searchQuery',4 value: 'foo',5 },6 {7 type: 'entityType',8 value: { domain: 'APM', type: 'APPLICATION' },9 },10 {11 type: 'tag',12 value: { key: 'environment', value: 'production' },13 },14 {15 type: 'tag',16 value: { key: 'team', value: 'bar' },17 },18];
false
If true
, the query response includes the total count of entities
for each domain and type.
true
If true
, the query response includes entities.
false
false
If true
, the returned entities include their tags.
Name or partial name of the entities to query.
0
Interval in milliseconds to poll for new data.
Array of criteras used to sort the entity search results.
<Array of<One ofEntitySearchQuery.SORT_TYPE.ALERT_SEVERITY,EntitySearchQuery.SORT_TYPE.DOMAIN,EntitySearchQuery.SORT_TYPE.MOST_RELEVANT,EntitySearchQuery.SORT_TYPE.NAME,EntitySearchQuery.SORT_TYPE.REPORTING,EntitySearchQuery.SORT_TYPE.TYPE,>
>
Methods
EntitySearchQuery.render
function () => undefined
EntitySearchQuery.query
function () => undefined