• /
  • Log in
  • Free account

EntitySearchQuery

Search for entities.

Usage

import { EntitySearchQuery } from 'nr1'

Examples

Declarative query

1
function render() {
2
const filters = [
3
{
4
type: EntitySearchQuery.FILTER_TYPE.TAG,
5
value: { key: 'environment', value: 'production' },
6
},
7
];
8
9
return (
10
<EntitySearchQuery filters={filters}>
11
{({ loading, error, data, fetchMore }) => {
12
if (loading) {
13
return <Spinner />;
14
}
15
16
if (error) {
17
return 'Error!';
18
}
19
20
return (
21
<List
22
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
<EntitySearchQuery
2
entityDomain="APM"
3
sortBy={[EntitySearchQuery.SORT_TYPE.ALERT_SEVERITY]}
4
>
5
{({ data, error, fetchMore }) => {
6
if (error) {
7
return 'Error!';
8
}
9
10
return (
11
<List
12
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

1
EntitySearchQuery.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

1
const filters = [
2
{
3
type: EntitySearchQuery.FILTER_TYPE.TAG,
4
value: { key: 'environment', value: 'production' },
5
},
6
];
7
8
const firstPage = await EntitySearchQuery.query({ filters });
9
10
console.log('First page data', firstPage.data);
11
12
const cursor = firstPage.data.nextCursor;
13
const secondPage = await EntitySearchQuery.query({ cursor, filters });
14
15
console.log('Second page data', secondPage.data);
16
17
// NOTE: To fetch multiple page results consecutively, use EntitySearchQuery
18
// component's fetchMore approach.

Props

childrenfunction

Render prop function as a child.

function (
queryResult: {Object //

Results of the query.

) => undefined
entityDomainstring

Domain of the entities you want to query.

entityFragmentExtensionobject

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

1
const entityFragmentExtension = ngql`
2
fragment EntityFragmentExtension on EntityOutline {
3
indexedAt
4
guid
5
}
6
`;
entityGuidsstring[]

GUID of the entities to query.

entityTypestring

Type of the entities you want to query.

fetchPolicyTypeenum
DEFAULT
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 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
EntitySearchQuery.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,
>
filtersstring|(shape|shape|shape)[]

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

1
const 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
];
includeCountboolean
DEFAULT
false

If true, the query response includes the total count of entities for each domain and type.

includeResultsboolean
DEFAULT
true

If true, the query response includes entities.

includeSummaryMetricsboolean
DEFAULT
false
includeTagsboolean
DEFAULT
false

If true, the returned entities include their tags.

namestring

Name or partial name of the entities to query.

pollIntervalnumber
DEFAULT
0

Interval in milliseconds to poll for new data.

sortByenum[]

Array of criteras used to sort the entity search results.

<Array of
<One of
EntitySearchQuery.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
Create issueEdit page
Copyright © 2021 New Relic Inc.