Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow input object to be required #18

Open
wants to merge 1 commit into
base: reorg
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/blunt_absinthe/lib/blunt/absinthe/field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ defmodule Blunt.Absinthe.Field do
def args(:absinthe_mutation, message_module, opts) do
input_object = Keyword.get(opts, :input_object, false)
input_object? = Keyword.get(opts, :input_object?, false)
required? = Keyword.get(opts, :required, false)

case input_object || input_object? do
true ->
field_name = :"#{Field.name(message_module, opts)}_input"
[quote(do: arg(:input, unquote(field_name)))]

if required? do
[quote(do: arg(:input, non_null(unquote(field_name))))]
else
[quote(do: arg(:input, unquote(field_name)))]
end

false ->
Args.from_message_fields(message_module, opts)
Expand Down
6 changes: 6 additions & 0 deletions apps/blunt_absinthe/test/blunt/absinthe/mutation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ defmodule Blunt.Absinthe.MutationTest do
} = fields
end

test "mutation input argument required" do
assert sdl = Absinthe.Schema.to_sdl(Schema)

assert sdl =~ "updatePersonRequired(input: UpdatePersonRequiredInput!): Person"
end

test "derive object" do
assert %Object{fields: fields} = Absinthe.Schema.lookup_type(Schema, :dog)
assert %{name: %{type: :string}} = fields
Expand Down
2 changes: 2 additions & 0 deletions apps/blunt_absinthe/test/support/schema_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ defmodule Blunt.Absinthe.Test.SchemaTypes do
end

derive_mutation_input(UpdatePerson, arg_types: [gender: :gender])
derive_mutation_input(UpdatePerson, as: :update_person_required, arg_types: [gender: :gender])

object :person_mutations do
derive_mutation CreatePerson, :person, arg_types: [gender: :gender]
derive_mutation UpdatePerson, :person, input_object: true
derive_mutation UpdatePerson, :person, as: :update_person_required, input_object: true, required: true
end
end