• /
  • Log in
  • Free account

EntitiesByNameQuery

Query entities by their name.

Usage

import { EntitiesByNameQuery } from 'nr1'

Examples

Declarative query

1
<EntitiesByNameQuery name="abc1-prod-metrics">
2
{({ loading, error, data, fetchMore }) => {
3
if (error) {
4
return 'Error!';
5
}
6
7
return (
8
<List
9
items={data.entities}
10
rowCount={data.count}
11
rowHeight={20}
12
onLoadMore={fetchMore}
13
>
14
{({ item }) => <ListItem key={item.guid}>{item.name}</ListItem>}
15
</List>
16
);
17
}}
18
</EntitiesByNameQuery>;

Imperative query

1
EntitiesByNameQuery.query({
2
name: 'abc1-prod-metrics',
3
}).then(({ data }) => console.log(data));

Fetch more results using imperative query

1
const name = 'abc1-prod-metrics';
2
const firstPage = await EntitiesByNameQuery.query({ name });
3
4
console.log('First page data', firstPage.data);
5
6
const cursor = firstPage.data.nextCursor;
7
const secondPage = await EntitiesByNameQuery.query({ cursor, name });
8
9
console.log('Second page data', secondPage.data);
10
11
// NOTE: To fetch multiple page results consecutively, use EntitiesByNameQuery
12
// component's fetchMore approach.

Props

childrenfunction

Render prop function as a child.

function (
queryResult: {Object //

Results of the query.

) => undefined
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
`;
fetchPolicyTypeenum
DEFAULT
EntitiesByNameQuery.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
EntitiesByNameQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK,
EntitiesByNameQuery.FETCH_POLICY_TYPE.CACHE_FIRST,
EntitiesByNameQuery.FETCH_POLICY_TYPE.CACHE_ONLY,
EntitiesByNameQuery.FETCH_POLICY_TYPE.NETWORK_ONLY,
EntitiesByNameQuery.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
];
includeSummaryMetricsboolean
DEFAULT
false
includeTagsboolean
DEFAULT
false

If true, the returned entities include their tags.

namerequiredstring

Name or partial name of the entities to query.

pollIntervalnumber
DEFAULT
0

Interval in milliseconds to poll for new data.

Methods

EntitiesByNameQuery.render

function () => undefined

EntitiesByNameQuery.query

A static method to use EntitiesByNameQuery as a Promise instead of as a React component.

function (
props: Object //

An object containing the query options. Any EntitiesByNameQuery prop is a valid option except children and pollInterval.

) => {Object}

Type definitions

PromiseQueryResult

{
loading: boolean, //

Indicates that the request is in flight.

data: Object, //

An object containing the result of your query.

}
Create issueEdit page
Copyright © 2021 New Relic Inc.