Skip to content

marocchino/absinthe_phoenix

 
 

Repository files navigation

Absinthe.Phoenix

Hex pmLicense Build Status

This package integrates Absinthe subscriptions with Phoenix, so that you can use subscriptions via websockets.

For getting started guides on subscriptions see: https://hexdocs.pm/absinthe/subscriptions.html

For getting started guides on server side rendering see: https://hexdocs.pm/absinthe/subscriptions.html

Installation

Install from Hex.pm:

For Phoenix 1.4, see the v1.5 branch: https://github.com/absinthe-graphql/absinthe_phoenix/tree/v1.5

Phoenix 1.5

def deps do
  [{:absinthe_phoenix, "~> 2.0.0"}]
end

You need to have a working phoenix pubsub configured. Here is what the default looks like if you create a new phoenix project:

config :my_app, MyAppWeb.Endpoint,
  # ... other config
  pubsub_server: MyApp.PubSub

In your application supervisor add a line AFTER your existing endpoint supervision line:

[
  # other children ...
  MyAppWeb.Endpoint, # this line should already exist
  {Absinthe.Subscription, MyAppWeb.Endpoint}, # add this line
  # other children ...
]

Where MyAppWeb.Endpoint is the name of your application's phoenix endpoint.

In your MyAppWeb.Endpoint module add:

use Absinthe.Phoenix.Endpoint

In your socket add:

use Absinthe.Phoenix.Socket,
  schema: MyAppWeb.Schema

Where MyAppWeb.Schema is the name of your Absinthe schema module.

That is all that's required for setup on the server.

For client side guidance see the guides.

GraphiQL Usage

From within GraphiQL: To use Absinthe.Phoenix from within GraphiQL, you need to tell GraphiQL about your websocket endpoint.

forward "/graphiql", Absinthe.Plug.GraphiQL,
  schema: MyAppWeb.Schema,
  socket: MyAppWeb.UserSocket

License

See LICENSE.md.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%