absinthe icon indicating copy to clipboard operation
absinthe copied to clipboard

Macro-schema argument default values are not rendered in SDL

Open maartenvanvliet opened this issue 4 years ago • 3 comments

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.

maartenvanvliet avatar Jan 16 '21 09:01 maartenvanvliet

@benwilson512 Thoughts on this issue?

binaryseed avatar Jan 20 '21 03:01 binaryseed

FYI a little related - there's been other conversation about default_value / nil: https://github.com/absinthe-graphql/absinthe/issues/656

binaryseed avatar Jan 20 '21 03:01 binaryseed

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.

woylie avatar Aug 04 '21 23:08 woylie