ngrx-entity-relationship has a set of helper functions to convert existing selectors into GraphQL queries.
Imagine we have a selector that selects a user, its company and the address of the company:
And we want to build a GraphQL query that fetches a user, its company and the address of the company:
ORM selectors by
ngrx-entity-relationship have information about relationships,
but do not know about normal fields such as
To solve this,
ngrx-entity-relationship provides a meta key called
which is an array of strings (entity keys).
Therefore, to solve the issue we need to fill the
gqlFields in every selector.
To do that, we need to go the place where the factory functions are defined and add meta information about GraphQL.
Don't forget to include fields for ids.
Profit, now we can use this selector to generate a GraphQL query via
toGraphQL helper functions.
The result will be
If we want, we can combine these three queries into a single query.
In order to do that we need to use
toGraphQL again, but with aliases:
It will generate: