Sha256: 63687fc3bf71744844edd0a7252ec8d5db40427b98f05d191cb417f2190a1a11

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 KB

Contents

module GraphitiGraphQL
  module GraphitiSchema
    class Sideload
      attr_reader :config, :schema
      attr_accessor :name

      def initialize(schema, config)
        @config = config
        @schema = schema
      end

      def graphql_class_name
        if type == :polymorphic_belongs_to
          parent_resource.graphql_class_name
        else
          resource.graphql_class_name
        end
      end

      def to_many?
        [:has_many, :many_to_many].include?(type)
      end

      def type
        config[:type].to_sym
      end

      def resource_name
        config[:resource]
      end

      def resource
        schema.get_resource(resource_name)
      end

      def remote?
        resources = child_resources? ? child_resources : [resource]
        resources.any?(&:remote?)
      end

      def parent_resource
        schema.get_resource(config[:parent_resource])
      end

      def child_resources?
        !!config[:resources]
      end

      def child_resources
        config[:resources].map do |name|
          schema.get_resource(name)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
graphiti_graphql-0.1.17 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.16 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.15 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.14 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.12 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.11 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.10 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.9 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.8 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.7 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.6 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.5 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.4 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.3 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.2 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.1 lib/graphiti_graphql/graphiti_schema/sideload.rb
graphiti_graphql-0.1.0 lib/graphiti_graphql/graphiti_schema/sideload.rb