README.md (3890B)
1 # Absinthe.Plug 2 3 [![Build Status](https://github.com/absinthe-graphql/absinthe_plug/workflows/CI/badge.svg)](https://github.com/absinthe-graphql/absinthe_plug/actions?query=workflow%3ACI) 4 [![Version](https://img.shields.io/hexpm/v/absinthe_plug.svg)](https://hex.pm/packages/absinthe_plug) 5 [![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/absinthe_plug/) 6 [![Download](https://img.shields.io/hexpm/dt/absinthe_plug.svg)](https://hex.pm/packages/absinthe_plug) 7 [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) 8 [![Last Updated](https://img.shields.io/github/last-commit/absinthe-graphql/absinthe_plug.svg)](https://github.com/absinthe-graphql/absinthe_plug/commits/master) 9 10 [Plug](https://hex.pm/packages/plug) support for [Absinthe](https://hex.pm/packages/absinthe), 11 the GraphQL toolkit for Elixir. 12 13 Please see the website at [http://absinthe-graphql.org](http://absinthe-graphql.org). 14 15 ## Installation 16 17 Install from [Hex.pm](https://hex.pm/packages/absinthe_plug): 18 19 ```elixir 20 def deps do 21 [{:absinthe_plug, "~> 1.5"}] 22 end 23 ``` 24 25 Note: Absinthe.Plug requires Elixir 1.10 or higher. 26 27 `Absinthe.Plug` also requires a JSON codec. `Jason` and `Poison` work out of the box. 28 29 ```elixir 30 def deps do 31 [ 32 ..., 33 {:absinthe_plug, "~> 1.5"}, 34 {:jason, "~> 1.0"} 35 ] 36 end 37 ``` 38 39 ## Upgrading 40 41 See [CHANGELOG](./CHANGELOG.md) for upgrade steps between versions. 42 43 You may want to look for the specific upgrade guide in the [Absinthe documentation](https://hexdocs.pm/absinthe). 44 45 ## Documentation 46 47 See "Usage," below, for basic usage information and links to specific resources. 48 49 - [Absinthe.Plug hexdocs](https://hexdocs.pm/absinthe_plug). 50 - For the tutorial, guides, and general information about Absinthe-related 51 projects, see [http://absinthe-graphql.org](http://absinthe-graphql.org). 52 53 ## Related Projects 54 55 See the [GitHub organization](https://github.com/absinthe-graphql). 56 57 ## Usage 58 59 In your `MyAppWeb.Router` module add: 60 61 ```elixir 62 plug Plug.Parsers, 63 parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser], 64 pass: ["*/*"], 65 json_decoder: Jason 66 67 plug Absinthe.Plug, 68 schema: MyAppWeb.Schema 69 ``` 70 71 If you want `Absinthe.Plug` to serve only a particular route, configure your 72 `MyAppWeb.Router` like: 73 74 ```elixir 75 plug Plug.Parsers, 76 parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser], 77 pass: ["*/*"], 78 json_decoder: Jason 79 80 forward "/api", 81 to: Absinthe.Plug, 82 init_opts: [schema: MyAppWeb.Schema] 83 ``` 84 85 For more information, see the API documentation for `Absinthe.Plug`. 86 87 ### Phoenix.Router 88 89 If you are using [Phoenix.Router](https://hexdocs.pm/phoenix/Phoenix.Router.html), `forward` expects different arguments: 90 91 #### Plug.Router 92 93 ```elixir 94 forward "/graphiql", 95 to: Absinthe.Plug.GraphiQL, 96 init_opts: [ 97 schema: MyAppWeb.Schema, 98 interface: :simple 99 ] 100 ``` 101 102 #### Phoenix.Router 103 104 ```elixir 105 forward "/graphiql", 106 Absinthe.Plug.GraphiQL, 107 schema: MyAppWeb.Schema, 108 interface: :simple 109 ``` 110 111 For more information see [Phoenix.Router.forward/4](https://hexdocs.pm/phoenix/Phoenix.Router.html#forward/4). 112 113 114 ## GraphiQL 115 116 To add support for a GraphiQL interface, add a configuration for 117 `Absinthe.Plug.GraphiQL`: 118 119 ```elixir 120 forward "/graphiql", 121 to: Absinthe.Plug.GraphiQL, 122 init_opts: [schema: MyAppWeb.Schema] 123 ``` 124 125 See the API documentation for `Absinthe.Plug.GraphiQL` for more information. 126 127 ## Community 128 129 The project is under constant improvement by a growing list of 130 contributors, and your feedback is important. Please join us in Slack 131 (`#absinthe-graphql` under the Elixir Slack account) or the Elixir Forum 132 (tagged `absinthe`). 133 134 Please remember that all interactions in our official spaces follow 135 our [Code of Conduct](./CODE_OF_CONDUCT.md). 136 137 ## Contributing 138 139 Please follow [contribution guide](./CONTRIBUTING.md). 140 141 ## License 142 143 See [LICENSE.md](./LICENSE.md).