Sha256: abf3b5c2140e56de3e33a150695b1cf8019a71dac5cceb795c12d5121ba40b64

Contents?: true

Size: 1.49 KB

Versions: 168

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true
module GraphQL
  module InternalRepresentation
    module Print
      module_function

      def print(schema, query_string)
        query = GraphQL::Query.new(schema, query_string)
        print_node(query.irep_selection)
      end

      def print_node(node, indent: 0)
        padding = " " * indent
        typed_children_padding = " " * (indent + 2)
        query_str = "".dup

        if !node.definition
          op_node = node.ast_node
          name = op_node.name ? " " + op_node.name : ""
          op_type = op_node.operation_type
          query_str << "#{op_type}#{name}"
        else
          if node.name == node.definition_name
            query_str << "#{padding}#{node.name}"
          else
            query_str << "#{padding}#{node.name}: #{node.definition_name}"
          end

          args = node.ast_nodes.map { |n| n.arguments.map(&:to_query_string).join(",") }.uniq
          query_str << args.map { |a| "(#{a})"}.join("|")
        end

        if node.typed_children.any?
          query_str << " {\n"
          node.typed_children.each do |type, children|
            query_str << "#{typed_children_padding}... on #{type.name} {\n"
            children.each do |name, child|
              query_str << print_node(child, indent: indent + 4)
            end
            query_str << "#{typed_children_padding}}\n"
          end
          query_str << "#{padding}}\n"
        else
          query_str << "\n"
        end

        query_str
      end
    end
  end
end

Version data entries

168 entries across 168 versions & 2 rubygems

Version Path
graphql-1.13.23 lib/graphql/internal_representation/print.rb
graphql-1.13.22 lib/graphql/internal_representation/print.rb
graphql-1.13.21 lib/graphql/internal_representation/print.rb
graphql-1.13.20 lib/graphql/internal_representation/print.rb
graphql-1.13.19 lib/graphql/internal_representation/print.rb
graphql-1.13.18 lib/graphql/internal_representation/print.rb
graphql-1.13.17 lib/graphql/internal_representation/print.rb
graphql-1.13.16 lib/graphql/internal_representation/print.rb
graphql-1.13.15 lib/graphql/internal_representation/print.rb
graphql-1.13.14 lib/graphql/internal_representation/print.rb
graphql-1.13.13 lib/graphql/internal_representation/print.rb
graphql_cody-1.13.0 lib/graphql/internal_representation/print.rb
graphql-1.13.12 lib/graphql/internal_representation/print.rb
graphql-1.13.11 lib/graphql/internal_representation/print.rb
graphql-1.13.10 lib/graphql/internal_representation/print.rb
graphql-1.13.9 lib/graphql/internal_representation/print.rb
graphql-1.12.24 lib/graphql/internal_representation/print.rb
graphql-1.13.8 lib/graphql/internal_representation/print.rb
graphql-1.13.7 lib/graphql/internal_representation/print.rb
graphql-1.13.6 lib/graphql/internal_representation/print.rb