Sha256: 7488596ad8ffa4c0d300272584d389a3e289e25f1cf67216de7f5abe26ee0f59
Contents?: true
Size: 844 Bytes
Versions: 10
Compression:
Stored size: 844 Bytes
Contents
module GraphQL module Language module DefinitionSlice extend self def slice(document, name) definitions = {} document.definitions.each { |d| definitions[d.name] = d } names = find_definition_dependencies(definitions, name) definitions = document.definitions.select { |d| names.include?(d.name) } Nodes::Document.new(definitions: definitions) end private def find_definition_dependencies(definitions, name) names = Set.new([name]) visitor = Visitor.new(definitions[name]) visitor[Nodes::FragmentSpread] << ->(node, parent) { if fragment = definitions[node.name] names.merge(find_definition_dependencies(definitions, fragment.name)) end } visitor.visit names end end end end
Version data entries
10 entries across 10 versions & 1 rubygems