class GraphQL::Client::QueryTypename::InsertTypenameVisitor

So, use the node mutation API instead.
and doesn’t expose writer methods for node attributes.
GraphQL 1.9 introduces a new visitor class

def add_typename(node, parent)

def add_typename(node, parent)
  type = @types[node]
  type = type && type.unwrap
  if (node.selections.any? && (type.nil? || type.kind.interface? || type.kind.union?)) ||
    (node.selections.none? && (type && type.kind.object?))
    names = QueryTypename.node_flatten_selections(node.selections).map { |s| s.respond_to?(:name) ? s.name : nil }
    names = Set.new(names.compact)
    if names.include?("__typename")
      yield(node, parent)
    else
      node_with_typename = node.merge(selections: [GraphQL::Language::Nodes::Field.new(name: "__typename")] + node.selections)
      yield(node_with_typename, parent)
    end
  else
    yield(node, parent)
  end
end

def initialize(document, types:)

def initialize(document, types:)
  @types = types
  super(document)
end

def on_field(node, parent)

def on_field(node, parent)
  add_typename(node, parent) { |n, p| super(n, p) }
end

def on_fragment_definition(node, parent)

def on_fragment_definition(node, parent)
  add_typename(node, parent) { |n, p| super(n, p) }
end

def on_operation_definition(node, parent)

def on_operation_definition(node, parent)
  add_typename(node, parent) { |n, p| super(n, p) }
end