Skip to content

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

@jwoertink

Description

@jwoertink

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions