GraphQL Subscriptions

toGraphQL is not enough to generate a subscription query. ngrx-entity-relationship provides a helper function called toSubscription to solve the issue.

For example

const query = toSubscription(
toGraphQL('users', action.selector),
);

will generate

subscription {
users {
id
# ...
}
}

With Apollo service, it can be used like that

apollo.subscribe({
query: gql(
toSubscription(
toGraphQL('users', action.selector),
),
),
}).subscribe(update => {
// magic is here.
});
Last updated on by MG