Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/absinthe-graphql/absinthe_plug
Plug support for Absinthe, the GraphQL toolkit for Elixir
https://github.com/absinthe-graphql/absinthe_plug
absinthe absinthe-graphql graphiql graphql phoenix plug
Last synced: 3 days ago
JSON representation
Plug support for Absinthe, the GraphQL toolkit for Elixir
- Host: GitHub
- URL: https://github.com/absinthe-graphql/absinthe_plug
- Owner: absinthe-graphql
- License: mit
- Created: 2015-12-30T00:20:11.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T20:58:19.000Z (6 months ago)
- Last Synced: 2025-01-04T13:06:34.552Z (7 days ago)
- Topics: absinthe, absinthe-graphql, graphiql, graphql, phoenix, plug
- Language: Elixir
- Homepage: https://hex.pm/packages/absinthe_plug
- Size: 491 KB
- Stars: 260
- Watchers: 16
- Forks: 167
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Plug support for Absinthe. (Framework Components)
- fucking-awesome-elixir - absinthe_plug - Plug support for Absinthe. (Framework Components)
- awesome-elixir - absinthe_plug - Plug support for Absinthe. (Framework Components)
README
# Absinthe.Plug
[![Build Status](https://github.com/absinthe-graphql/absinthe_plug/workflows/CI/badge.svg)](https://github.com/absinthe-graphql/absinthe_plug/actions?query=workflow%3ACI)
[![Version](https://img.shields.io/hexpm/v/absinthe_plug.svg)](https://hex.pm/packages/absinthe_plug)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/absinthe_plug/)
[![Download](https://img.shields.io/hexpm/dt/absinthe_plug.svg)](https://hex.pm/packages/absinthe_plug)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Last Updated](https://img.shields.io/github/last-commit/absinthe-graphql/absinthe_plug.svg)](https://github.com/absinthe-graphql/absinthe_plug/commits/master)[Plug](https://hex.pm/packages/plug) support for [Absinthe](https://hex.pm/packages/absinthe),
the GraphQL toolkit for Elixir.Please see the website at [http://absinthe-graphql.org](http://absinthe-graphql.org).
## Installation
Install from [Hex.pm](https://hex.pm/packages/absinthe_plug):
```elixir
def deps do
[{:absinthe_plug, "~> 1.5"}]
end
```Note: Absinthe.Plug requires Elixir 1.10 or higher.
`Absinthe.Plug` also requires a JSON codec. `Jason` and `Poison` work out of the box.
```elixir
def deps do
[
...,
{:absinthe_plug, "~> 1.5"},
{:jason, "~> 1.0"}
]
end
```## Upgrading
See [CHANGELOG](./CHANGELOG.md) for upgrade steps between versions.
You may want to look for the specific upgrade guide in the [Absinthe documentation](https://hexdocs.pm/absinthe).
## Documentation
See "Usage," below, for basic usage information and links to specific resources.
- [Absinthe.Plug hexdocs](https://hexdocs.pm/absinthe_plug).
- For the tutorial, guides, and general information about Absinthe-related
projects, see [http://absinthe-graphql.org](http://absinthe-graphql.org).## Related Projects
See the [GitHub organization](https://github.com/absinthe-graphql).
## Usage
In your `MyAppWeb.Router` module add:
```elixir
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser],
pass: ["*/*"],
json_decoder: Jasonplug Absinthe.Plug,
schema: MyAppWeb.Schema
```If you want `Absinthe.Plug` to serve only a particular route, configure your
`MyAppWeb.Router` like:```elixir
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser],
pass: ["*/*"],
json_decoder: Jasonforward "/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](https://hexdocs.pm/phoenix/Phoenix.Router.html), `forward` expects different arguments:
#### Plug.Router
```elixir
forward "/graphiql",
to: Absinthe.Plug.GraphiQL,
init_opts: [
schema: MyAppWeb.Schema,
interface: :simple
]
```#### Phoenix.Router
```elixir
forward "/graphiql",
Absinthe.Plug.GraphiQL,
schema: MyAppWeb.Schema,
interface: :simple
```For more information see [Phoenix.Router.forward/4](https://hexdocs.pm/phoenix/Phoenix.Router.html#forward/4).
## GraphiQL
To add support for a GraphiQL interface, add a configuration for
`Absinthe.Plug.GraphiQL`:```elixir
forward "/graphiql",
to: Absinthe.Plug.GraphiQL,
init_opts: [schema: MyAppWeb.Schema]
```See the API documentation for `Absinthe.Plug.GraphiQL` for more information.
## Community
The project is under constant improvement by a growing list of
contributors, and your feedback is important. Please join us in Slack
(`#absinthe-graphql` under the Elixir Slack account) or the Elixir Forum
(tagged `absinthe`).Please remember that all interactions in our official spaces follow
our [Code of Conduct](./CODE_OF_CONDUCT.md).## Contributing
Please follow [contribution guide](./CONTRIBUTING.md).
## License
See [LICENSE.md](./LICENSE.md).