Sha256: f82747207e677d9304cc5d19c974b5632380df015365fe0e73e144c4e4796624

Contents?: true

Size: 899 Bytes

Versions: 6

Compression:

Stored size: 899 Bytes

Contents

module GraphQL
  module Sugar
    module Function
      def self.included(base)
        base.extend ClassMethods
        base.class_eval do
          attr_reader :object
          attr_reader :params
          attr_reader :context
        end
      end

      module ClassMethods
        # Workaround:
        # A `GraphQL::Function` is supposed to be a 'reusable container for field logic'.
        # However, extended Field DSL (specified using `GraphQL::Field.accepts_definitions(...)`)
        # is not available within Functions. Therefore, re-defining it here.
        def parameter(name, *args, **kwargs, &block)
          kwargs[:as] ||= name.to_s.underscore.to_sym
          argument(name, *args, **kwargs, &block)
        end
      end

      def call(obj, args, ctx)
        @object = obj
        @params = args.to_h.deep_symbolize_keys
        @context = ctx
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
graphql-sugar-0.1.6 lib/graphql/sugar/function.rb
graphql-sugar-0.1.5 lib/graphql/sugar/function.rb
graphql-sugar-0.1.4 lib/graphql/sugar/function.rb
graphql-sugar-0.1.3 lib/graphql/sugar/function.rb
graphql-sugar-0.1.2 lib/graphql/sugar/function.rb
graphql-sugar-0.1.1 lib/graphql/sugar/function.rb