graphql-ruby icon indicating copy to clipboard operation
graphql-ruby copied to clipboard

Definitions for Custom Directives on ENUM_VALUE not being dumped in IDL (Bug?)

Open JELaVallee opened this issue 3 years ago • 4 comments

Describe the bug

When creating a Custom Directive that has a location of only ENUM_VALUE and applying it to the value of a GraphQL::Types::Enum derived definition, the output of GraphQL::Schema.to_definition is omitting the definition of the Custom Directive, but properly dumps the Custom Directive annotation on the EnumValue definition.

See this spec addition on my fork for an example of a failing scenario.

Gonna dig deeper into this with some pry'ing too... See if I can isolate where the node-traversal fails either in the Language or Schema parsing.

Also, is this the expected behavior and we're just missing something? Have not had the need to bind the Directive definition to the Schema to get it to show up in the IDL before, for Directives that have other locations such as FIELD or TYPE_DEFINITION.

Versions

graphql version: 2.0.26 rails (or other framework): 7.0.7.2

GraphQL schema

Expecting this IDL output:

directive @customEnumValueDirective(fakeArgument: String!) on ENUM_VALUE

enum FakeEnum {
  VALUE1
  VALUE2 @customEnumValueDirective(fakeArgument: "Value1 is better...")
}

type Query {
  fakeQueryField: FakeEnum!
}

From this definition:

class EnumValueDirectiveSchema < GraphQL::Schema
  class CustomEnumValueDirective < GraphQL::Schema::Directive
    locations GraphQL::Schema::Directive::ENUM_VALUE

    argument :fake_argument, String, required: true
  end

  class FakeEnum < GraphQL::Schema::Enum
    value "VALUE1"
    value "VALUE2" do
      directive CustomEnumValueDirective, fake_argument: "Value1 is better..."
    end
  end

  class Query < GraphQL::Schema::Object
    field :fake_query_field, FakeEnum, null: false
  end

  query(Query)
  # directive(CustomEnumValueDirective)  # <-- Fails if this is not included
end

GraphQL query N/A

Steps to reproduce

rake test TEST=spec/graphql/language/document_from_schema_definition_spec.rb on this fork/branch to see failure with above examples.

Expected behavior

Expected the Custom Directive definition to be in the dumped IDL output without having to directly include it in the Schema definition.

Actual behavior

Only appears to output the Custom Directive definition if it's directly added to the Schema definition.

Additional context N/A

JELaVallee avatar Aug 23 '23 00:08 JELaVallee

@rmosolgo Just added a fix for this here... Small addition and doesn't appear to break any other specs.

Happy to create a PR if this looks up to snuff... Was wondering if spec/graphql/schema/addition_spec.rb should be where this is tested? That said, the test in document_from_schema_definition_spec.rb covers this scenario reasonably well.

Nothing more fun than debugging a recursive visitor... Watches and breaks all over the places. 😂

JELaVallee avatar Aug 23 '23 13:08 JELaVallee

Thanks for the detailed report! I bet this was just overlooked from the beginning. That fix looks good to me -- a PR would be great! I'm not worried about where the test case is, I think the one you added looks good :+1:

rmosolgo avatar Aug 24 '23 14:08 rmosolgo

Excellent! Will have the PR up shortly...

JELaVallee avatar Aug 24 '23 15:08 JELaVallee

Fixed by #4596

rmosolgo avatar Aug 28 '23 14:08 rmosolgo