View Source API Reference jet_ext v0.1.0
Modules
Absinthe error handlers can handle more data types as an error when works
with JetExt.Absinthe.Middleware.HandleError
.
The default error handler for JetExt.Absinthe.Middleware.HandleError
that handles ecto
changeset as an error.
Absinthe Middleware to support more types of error.
使用方法
- 参考
JetExt.Absinthe.OneOf.Phase
的文档,将 phase 加入到 absinthe 的 phases 中 - 参考
JetExt.Absinthe.OneOf.SchemaProtoType
的文档,在你的 absinthe schema 引入:one_of
directive - 参考
JetExt.Absinthe.OneOf.Middleware.InputModifier
的文档,用:one_of
来定义你的 input_object JetExt.Absinthe.OneOf.Helpers
目前提供了一个fold_key_to_field/3
,一个使用案例参考 3 中的例子
使用方法
defmodule MyApp.GraphQL.Schema.Admin do
@moduledoc false
use Absinthe.Schema.Notation
use Absinthe.Relay.Schema.Notation, :modern
alias Absinthe.Blueprint.Input
alias JetExt.Absinthe.OneOf.Helpers
input_object :user_input do
# 首先启用 :one_of directive
directive :one_of
# 使用 Helpers 提供的 input_modifier
private(
:input_modifier,
:with,
{Helpers, :fold_key_to_field, [:__type__]}
)
field :plain_user, :plain_user_input
field :admin, :admin_input
end
input_object :plain_user_input do
field :username, non_null(:string)
end
input_object :admin_input do
field :role, non_null(:string)
end
object :mutations do
payload field(:create_user) do
input do
field :attributes, non_null(list_of(non_null(:user_input)))
end
output do
field :attributes, non_null(list_of(non_null(:user)))
end
# 在 input 使用了 one_of 后,再启用本 middleware
middleware JetExt.Absinthe.OneOf.Middleware.InputModifier
resolve &create_user/2
end
end
defp create_user(args, _resolution) do
IO.inspect(args)
# 前端会这样调用:
# mutation {
# createUser(input: {
# plainUser: { username: "foo" }
# }) {
# id
# }
# }
#
# 我们这里拿到的 args 是(注意 plain_user 是从驼峰转成了蛇底的):
# %{
# username: "foo",
# "__type__": "plain_user"
# }
end
end
``
Macros used to define Node-related schema entities
Used to extend a schema with Relay-specific macros and types.
Used to extend a module where Absinthe types are defined with Relay-specific macros and types.
Serialized object JSON value.
The UUID scalar type represents a version 4(random) UUID. Any binary not conforming to this format will be flagged.
This module is used to get environment variables.
Defining an Enum Ecto type.
The parameterized STI type.
Defines the STI like Ecto types.
Changeset utils for STI.
A behaviour module for implementing a STI Ecto type.
An Ecto type for URI (RFC 3986).
An Ecto type for URN (RFC 8141)
An Ecto type for PostgreSQL varchar with limit.
A Ecto Type for Version
that follows SemVer 2.0.
This module introduces some useful functions to Map
.
A plug for serving sdl file.
Define types that used in the jet projects.