Sha256: 9916e480b9ebbae47e519a6fbc072e0ee7a23e5cc184055cb043ed14d8ec4332

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

module GraphitiGql
  class Schema
    class Query
      def initialize(resources, existing_query: nil)
        @resources = resources
        @query_class = Class.new(existing_query || Schema.base_object)
        @query_class.graphql_name "Query"
      end

      def build
        @resources.each { |resource| ResourceType.new(resource).build }
        define_entrypoints
        add_value_objects
        add_relationships
        @query_class
      end

      private

      def registry
        Registry.instance
      end

      def define_entrypoints
        registry.resource_types.each do |registered|
          if registered[:resource].graphql_entrypoint
            Fields::Index.new(registered).apply(@query_class)
            Fields::Show.new(registered).apply(@query_class)
          end
        end
      end

      def add_relationships
        registry.resource_types.each do |registered|
          resource, type = registered[:resource], registered[:type]
          ResourceType.add_relationships(resource, type)
        end
      end

      def add_value_objects
        registry.resource_types.each do |registered|
          resource, type = registered[:resource], registered[:type]
          ResourceType.add_value_objects(resource, type)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphiti_gql-0.2.31 lib/graphiti_gql/schema/query.rb
graphiti_gql-0.2.30 lib/graphiti_gql/schema/query.rb
graphiti_gql-0.2.29 lib/graphiti_gql/schema/query.rb
graphiti_gql-0.2.28 lib/graphiti_gql/schema/query.rb
graphiti_gql-0.2.27 lib/graphiti_gql/schema/query.rb
graphiti_gql-0.2.26 lib/graphiti_gql/schema/query.rb
graphiti_gql-0.2.25 lib/graphiti_gql/schema/query.rb
graphiti_gql-0.2.24 lib/graphiti_gql/schema/query.rb