Query, Mutation, Subscription services

Additional API to use GraphQL in Angular

If you're familiar with the library, you already know the Apollo service.
It is a regular Angular service, pretty much the only one you need to use.

The API is straightforward, query and watchQuery methods for Queries, mutate and subscribe accordingly for Mutations and Subscriptions. There is more than that but if you don't do anything advanced that's all you really need.

We decided to introduce a new approach of working with GraphQL in Angular.

There are now 3 new APIs: Query, Mutation and Subscription. Each of them allows to define the shape of a result & variables.
The only thing you need to do is to set the document property. That’s it, you use it as a regular Angular service.

In this approach GraphQL Documents are first-class citizens, you think about the query, for example, as a main subject.

The best part about the new API is that you don't have to create those services, there's a tool that does it for you.
To read more about it, go to "Code Generation" section

Query

To get started with the new API, let's see how you define queries with it.

You create a service and extend it with a Query class from apollo-angular. Only thing you need to set is a document property.