rmosolgo / graphql-ruby

Ruby implementation of GraphQL
http://graphql-ruby.org
MIT License
5.37k stars 1.38k forks source link

Custom directives have no effect #2194

Closed tall-dan closed 5 years ago

tall-dan commented 5 years ago

Problem Adding a custom directive makes it available on the SDL, but the directive has no effect on output

Versions

Schema

class MySchema < GraphQL::Schema
  use GraphQL::Batch
  query Types::QueryType
  mutation Types::MutationType

  directive(GraphQL::Schema::Directive::Transform)
end

module Types
   class QueryType < GraphQL::Schema::Object
     graphql_name 'Query'
     field :events, Types::EventType.connection_type, null: false, description: 'The events for a client',
                                                      resolver: Resolvers::EventsResolver
   end
end

module Types
  class EventType < GraphQL::Schema::Object
    field :id, GraphQL::Types::UUID, null: false
    field :slug, String, null: true, description: 'An external identifier for the event'
    field :location, String, null: true, description: 'Location of the event'
  end
end

The directive, GraphQL::Schema::Directive::Transform is what comes included in the gem, seen here. However, the resolve function implemented by that class doesn't seem to be getting called - I've put a binding.pry within, and it never gets hit. When using the transform directive, my data is not transformed:

image

I've been digging through source code, and I've only been able to find one place that implements directives: GraphQL::Execution::DirectiveChecks. This only deals with inclusion / exclusion.

Am I missing something here, or should the case statement in that module be doing more?

swalkinshaw commented 5 years ago

Are you using the new interpreter? I think that's a requirement.

ie: use GraphQL::Execution::Interpreter on your schema

edit: i'm going by this: https://github.com/rmosolgo/graphql-ruby/blob/a4624789f2f1d13acde4ab8b28e2d8056c54b91b/spec/graphql/schema/directive/transform_spec.rb#L19-L20

tall-dan commented 5 years ago

Oh good catch, thank you!