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

mix absinthe.schema.sdl does not include default_values #1222

Open
IAmThermite opened this issue Jan 19, 2023 · 1 comment
Open

mix absinthe.schema.sdl does not include default_values #1222

IAmThermite opened this issue Jan 19, 2023 · 1 comment

Comments

@IAmThermite
Copy link

IAmThermite commented Jan 19, 2023

Environment

  • Elixir version (elixir -v): Elixir 1.13.4 (compiled with Erlang/OTP 24)
  • Absinthe version (mix deps | grep absinthe): master
  • Client Framework and version (Relay, Apollo, etc): N/A

Expected behavior

When generating SDL via mix absinthe.schema.sdl --schema ... Absinthe does not include any fields or input args etc. with the default_value keyword. With the test Absinthe schema below, the task outputs:

Task output:

schema {
  mutation: RootMutationType
  query: RootQueryType
}

type RootMutationType {
  createItem(input: TestInput!, other: String = "other"): String
}

type RootQueryType {
  item(show: Boolean = true): String
}

input TestInput {
  value: String! = "test"
}

Test absinthe schema:

defmodule MyTestSchema do
  use Absinthe.Schema

  query do
    field :item, :string do
      arg :show, :boolean, default_value: true
    end
  end

  mutation do
    field :create_item, :string do
      arg :input, non_null(:test_input)
      arg :other, :string, default_value: "other"
    end
  end

  input_object :test_input do
    field :value, non_null(:string), default_value: "test"
  end
end

The absinthe.schema.json does however have the default values in it

Actual behavior

The generator returns

schema {
  mutation: RootMutationType
  query: RootQueryType
}

input TestInput {
  value: String!
}

type RootMutationType {
  createItem(input: TestInput!, other: String): String
}

type RootQueryType {
  item(show: Boolean): String
}

Relevant Schema/Middleware Code

Test schema I used

defmodule MyTestSchema do
  use Absinthe.Schema

  query do
    field :item, :string do
      arg :show, :boolean, default_value: true
    end
  end

  mutation do
    field :create_item, :string do
      arg :input, non_null(:test_input)
      arg :other, :string, default_value: "other"
    end
  end

  input_object :test_input do
    field :value, non_null(:string), default_value: "test"
  end
end

This test I wrote for test/mix/tasks/absinthe.schema.sdl_test.exs fails but I would expect the strings to all be present.

test "with a default input" do
  argv = ["ouput.graphql", "--schema", "#{MyTestSchema}"]
  opts = Task.parse_options(argv)

  {:ok, schema} = Task.generate_schema(opts)
  assert schema =~ "value: String! = \"test\""
  assert schema =~ "other: String = \"other\""
  assert schema =~ "show: Boolean = true"
end
@dimamik
Copy link

dimamik commented Jun 4, 2024

@benwilson512 Any updates on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants