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

Setting default values to an Array on an input object #39

Open
jwoertink opened this issue Oct 27, 2022 · 1 comment
Open

Setting default values to an Array on an input object #39

jwoertink opened this issue Oct 27, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@jwoertink
Copy link

I have this input object that I wanted to have an optional array with a default value, but I get this error:

@[GraphQL::InputObject]
class GoalInput
  include GraphQL::InputObjectType

  getter title : String
  getter milestones : Array(String)

  @[GraphQL::Field]
  def initialize(
    @title : String,
    @milestones : Array(String) = [] of String,
  )
  end
end
There was a problem expanding macro 'values'

Code in lib/graphql/src/graphql/language/nodes.cr:149:7

 149 | values({name: String, type: Type, default_value: FValue, directives: Array(Directive), description: String?})
       ^
Called macro defined in lib/graphql/src/graphql/language/ast.cr:4:7

 4 | macro values(args)

Which expanded to:

 >  8 |           @name = name
 >  9 | @type = type
 > 10 | @default_value = default_value
                         ^------------
Error: instance variable '@default_value' of GraphQL::Language::InputValueDefinition must be GraphQL::Language::FValue, not Array(String)

Removing the default value off the array no longer produces the error.

@jgillich
Copy link
Member

Hmm, FValue is defined as:

alias FValue = String | Int32 | Float64 | Bool | Nil | AEnum | InputObject | Array(FValue) | Hash(String, FValue)

So we should be able to do this: https://play.crystal-lang.org/#/r/dyy2

😕

@jgillich jgillich added the bug Something isn't working label Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants