Apollo is a feature rich GQL client, APW implements an Apollo GraphQL Network Layer for it over Phoenix Channels allowing you to re-use a single bidirectional connection for executing your queries and mutations, the backend can send new data via subscriptions, and the Apollo client can update its internal store and update your views accordingly.
0.6.0, all Apollo operations are supported: queries, mutations, watchQueries (pooling) and
Using the Apollo Client, queries and mutations resolve to promises, and watchQueries and subscriptions resolve to observables.
See the Apollo client documentation for more info on how to invoke your GQL backend.
npm install --save apollo-phoenix-websocket
Just import the
createNetworkInterface from APW and use it to create an ApolloClient.
networkInterface function takes an options object, the only required
uri which specifies your endpoint websocket address.
// Nothing to configure if you are using an Absinthe backend// Otherwise take a look at the Options section.const networkInterface =const apollo = networkInterface
Most likely, (as you are looking for a phoenix-websocket transport) you might be using the Absinthe library to implement your Elixir GQL server. APW is configured by default to work out of the box with an Absinthe backend.
But if need araises, you can supply some advanced options to customize how it works. Here's is a commented example of the options that you can set for APW, with their respective default values:
You can use middlewares with
use just like with
the standard apollo network interface. For example, a middleware can set authorization token on every request.
You can use afterwares with
useAfter just like the standard
apollo network interface. An example use-case is for error handling:
Absinthe is an amazing project (kudos to @benwilson512 et al.). It's actually very simple to create a GQL backend with it.
Take a look at the following places for more information: