stackshareio/graphql-cache

Using graphql-cache with graphql-pundit

durcak opened this issue · 1 comments

How can I use graphql-cache gem, if I already have own Types::BaseField inheriting from GraphQL::Pundit::Field ? And Ruby has only single inheritance :(

Finaly I have found solution:

class Types::BaseField < GraphQL::Pundit::Field
  argument_class Types::BaseArgument

  current_user :current_user

  def initialize(*args, authorize: :false, policy: UserPolicy, cache: false, **kwargs, &block)
    @cache_config = cache

    super(*args, authorize!: authorize, policy: policy, **kwargs, &block)
  end

  def to_graphql
    field_defn = super # Returns a GraphQL::Field
    field_defn.metadata[:cache] = @cache_config
    field_defn
  end
end