absinthe-graphql / absinthe

The GraphQL toolkit for Elixir
http://absinthe-graphql.org
Other
4.27k stars 525 forks source link

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

Open IAmThermite opened 1 year ago

IAmThermite commented 1 year ago

Environment

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 commented 3 months ago

@benwilson512 Any updates on this one?