Sha256: 22cc0237d04b0895fe838b7e9381552dcbb6ad5681582ac6283d8e9ea0bd90e2

Contents?: true

Size: 982 Bytes

Versions: 6

Compression:

Stored size: 982 Bytes

Contents

# frozen_string_literal: true

module Rails
  module GraphQL
    # = GraphQL Cached Directive
    #
    # Indicates that the request has hard cached operations that need to be
    # collected
    class Directive::CachedDirective < Directive
      placed_on :query

      desc 'Indicates that there are hard cached operations.'

      argument :id, :ID, null: false, desc: <<~DESC
        The unique identifier of the cached operation.
      DESC

      on(:attach) do |source, request|
        source.data.selection = nil
        # TODO: Add the request name back
        # source.instance_variable_set(:@name, 'here')

        # TODO: Add the arguments and variables
        field = request.build(Request::Component::Field, source, nil, { name: 'a', alias: 'b' })
        field.assing_to(ApplicationSchema[:query][:a])
        field.check_authorization!

        source.instance_variable_set(:@selection, { 'b' => field })
        # puts source.inspect
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails-graphql-1.0.2 lib/rails/graphql/directive/cached_directive.rb
rails-graphql-1.0.1 lib/rails/graphql/directive/cached_directive.rb
rails-graphql-1.0.0 lib/rails/graphql/directive/cached_directive.rb
rails-graphql-1.0.0.rc2 lib/rails/graphql/directive/cached_directive.rb
rails-graphql-1.0.0.rc1 lib/rails/graphql/directive/cached_directive.rb
rails-graphql-1.0.0.beta lib/rails/graphql/directive/cached_directive.rb