Skip to content

imolorhe/absinthe_plug

 
 

Repository files navigation

Absinthe Plug

Build StatusLicense

Plug support for Absinthe, the GraphQL toolkit for Elixir.

Please see the website at http://absinthe-graphql.org.

Installation

Install from Hex.pm:

def deps do
  [{:absinthe_plug, "~> 1.4.0"}]
end

If using Elixir < 1.4 (or manually managing applications), make sure to add it to your applications configuration in mix.exs:

def application do
  [applications: [:absinthe_plug]]
end

Absinthe.Plug also requires a JSON codec. Jason and Poison work out of the box.

def deps do
  [
    ...,
    {:absinthe_plug, "~> 1.4.0"},
    {:jason, "~> 1.1.0"}
  ]
end

Usage

Basic Usage:

plug Plug.Parsers,
  parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser],
  pass: ["*/*"],
  json_decoder: Jason

plug Absinthe.Plug,
  schema: MyAppWeb.Schema

If you want Absinthe.Plug to serve only a particular route, configure your router like:

plug Plug.Parsers,
  parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser],
  pass: ["*/*"],
  json_decoder: Jason

forward "/api",
  to: Absinthe.Plug,
  init_opts: [schema: MyAppWeb.Schema]

For more information, see the API documentation for Absinthe.Plug.

Phoenix.Router

If you are using Phoenix.Router, forward expects different arguments:

Plug.Router

forward "/graphiql",
  to: Absinthe.Plug.GraphiQL,
  init_opts: [
    schema: MyAppWeb.Schema,
    interface: :simple
  ]

Phoenix.Router

forward "/graphiql",
  Absinthe.Plug.GraphiQL,
  schema: MyAppWeb.Schema,
  interface: :simple

For more information see Phoenix.Router.forward/4.

GraphiQL

To add support for a GraphiQL interface, add a configuration for Absinthe.Plug.GraphiQL:

forward "/graphiql",
  to: Absinthe.Plug.GraphiQL,
  init_opts: [schema: MyAppWeb.Schema]

See the API documentation for Absinthe.Plug.GraphiQL for more information.

Documentation

See HexDocs.

More Help

Related Projects

See the project list at http://absinthe-graphql.org/projects.

License

See LICENSE.md.

About

Plug support for Absinthe, the GraphQL toolkit for Elixir

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 93.8%
  • HTML 6.2%