absinthe
absinthe copied to clipboard
Macro-schema argument default values are not rendered in SDL
Macro-schema default values are not rendered in SDL, this can be seen here https://github.com/absinthe-graphql/absinthe/blob/master/test/absinthe/schema/sdl_render_test.exs#L191 and the SDL without the default here https://github.com/absinthe-graphql/absinthe/blob/master/test/absinthe/schema/sdl_render_test.exs#L244
For SDL schema's it does work. This is because SDL's schema's populate the default_value_blueprint
and the default_value
fields on the%Absinthe.Blueprint.Schema.InputValueDefinition{}
struct. The macro-schema only populates the default_value
fields. The SDL rendered expects the default_value_print
to be present to render the default value for an argument.
I think we could add a schema phase to populate the default_value_blueprint
when it's nil
, i.e. when it is a macro schema. The SDL renderer will render the defaults correctly then.
Also, note that the default values are not validated currently, arg :public, :boolean, default_value: "some value"
will not error during schema compilation.
@benwilson512 Thoughts on this issue?
FYI a little related - there's been other conversation about default_value / nil: https://github.com/absinthe-graphql/absinthe/issues/656
This still seems to be an issue. Simple example:
field :pets, list_of(:pet) do
arg :kind, :string, default_value: "dog"
resolve &Resolvers.Pet.list_pets/2
end
mix absinthe.schema.sdl
Results in:
pets(kind: String): [Pet]
While it should be:
pets(kind: String = "dog"): [Pet]
The JSON schema generated with mix absinthe.schema.json
includes the default value, Graphiql displays it, but the generated SDL schema does not.