absinthe_plug v1.3.0-beta.1 Absinthe.Plug
A plug for using Absinthe (GraphQL).
Usage
In your router:
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser],
pass: ["*/*"],
json_decoder: Poison
plug Absinthe.Plug,
schema: MyApp.Schema
If you want only Absinthe.Plug
to serve a particular route, configure your
router like:
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json, Absinthe.Plug.Parser],
pass: ["*/*"],
json_decoder: Poison
forward "/api", Absinthe.Plug,
schema: MyApp.Schema
See the documentation on Absinthe.Plug.init/1
and the Absinthe.Plug.opts
type for information on the available options.
To add support for a GraphiQL interface, add a configuration for
Absinthe.Plug.GraphiQL
:
forward "/graphiql",
Absinthe.Plug.GraphiQL,
schema: MyApp.Schema,
Included GraphQL Types
This package includes additional types for use in Absinthe GraphQL schema and type modules.
See the documentation on Absinthe.Plug.Types
for more information.
More Information
For more on configuring Absinthe.Plug
and how GraphQL requests are made,
see the guide at
http://absinthe-graphql.org.
Summary
Types
:adapter
— (Optional) Absinthe adapter to use (default:Absinthe.Adapter.LanguageConventions
).:context
— (Optional) Initial value for the Absinthe context, available to resolvers. (default:%{}
).:no_query_message
— (Optional) Message to return to the client if no query is provided (default: “No query document supplied”).:json_codec
— (Optional) Amodule
or{module, Keyword.t}
dictating which JSON codec should be used (default:Poison
). The codec module should implementencode!/2
(e.g.,module.encode!(body, opts)
).:pipeline
— (Optional){module, atom}
reference to a 2-arity function that will be called to generate the processing pipeline. (default:{Absinthe.Plug, :default_pipeline}
).:document_providers
— (Optional) A{module, atom}
reference to a 1-arity function that will be called to determine the document providers that will be used to process the request. (default:{Absinthe.Plug, :default_document_providers}
, which configuresAbsinthe.Plug.DocumentProvider.Default
as the lone document provider). A simple list of document providers can also be given. SeeAbsinthe.Plug.DocumentProvider
for more information about document providers, their role in procesing requests, and how you can define and configure your own.:schema
— (Required, if not handled by Mix.Config) The Absinthe schema to use. If a module name is not provided,Application.get_env(:absinthe, :schema)
will be attempt to find one
Functions
Parses, validates, resolves, and executes the given Graphql Document
The default list of document providers that are enabled
The default pipeline used to process GraphQL documents
Serve an Absinthe GraphQL schema with the specified options
Types
opts() :: [schema: module, adapter: module, context: map, json_codec: module | {module, Keyword.t}, pipeline: {module, atom}, no_query_message: String.t, document_providers: [Absinthe.Plug.DocumentProvider.t, ...] | Absinthe.Plug.DocumentProvider.t | {module, atom}, analyze_complexity: boolean, max_complexity: non_neg_integer | :infinity]
:adapter
— (Optional) Absinthe adapter to use (default:Absinthe.Adapter.LanguageConventions
).:context
— (Optional) Initial value for the Absinthe context, available to resolvers. (default:%{}
).:no_query_message
— (Optional) Message to return to the client if no query is provided (default: “No query document supplied”).:json_codec
— (Optional) Amodule
or{module, Keyword.t}
dictating which JSON codec should be used (default:Poison
). The codec module should implementencode!/2
(e.g.,module.encode!(body, opts)
).:pipeline
— (Optional){module, atom}
reference to a 2-arity function that will be called to generate the processing pipeline. (default:{Absinthe.Plug, :default_pipeline}
).:document_providers
— (Optional) A{module, atom}
reference to a 1-arity function that will be called to determine the document providers that will be used to process the request. (default:{Absinthe.Plug, :default_document_providers}
, which configuresAbsinthe.Plug.DocumentProvider.Default
as the lone document provider). A simple list of document providers can also be given. SeeAbsinthe.Plug.DocumentProvider
for more information about document providers, their role in procesing requests, and how you can define and configure your own.:schema
— (Required, if not handled by Mix.Config) The Absinthe schema to use. If a module name is not provided,Application.get_env(:absinthe, :schema)
will be attempt to find one.
Functions
Parses, validates, resolves, and executes the given Graphql Document
The default list of document providers that are enabled.
This consists of a single document provider, Absinthe.Plug.DocumentProvider.Default
, which
supports ad hoc GraphQL documents provided directly within the request.
For more information about document providers, see Absinthe.Plug.DocumentProvider
.
The default pipeline used to process GraphQL documents.
This consists of Absinthe’s default pipeline (as returned by Absinthe.Pipeline.for_document/1
),
with the Absinthe.Plug.Validation.HTTPMethod
phase inserted to ensure that the correct
HTTP verb is being used for the GraphQL operation type.