I am trying to search the Ruby GraphQL query document for the node related to the particular field.
https://graphql-ruby.org/api-doc/2.0.20/GraphQL/Language/Nodes.html
I've been looking through the above API docs to find something to help but couldn't find a function to help search through the nodes.
I could have sworn that before the weekend I had been able to use something like the following:
context.query.document.node('myField')
But today it seems like I must have imagined that.
I'm doing it know with a manual search function (probably could be better):
# query_nodes = context.query.document.children
def find_my_field(query_nodes)
return_value = nil
query_nodes.each do |node|
my_field = node.children.find { |field| field.name == 'myField' }
if my_field.nil?
return_value = find_my_field(node.children)
else
return_value = my_field
break
end
end
return_value
end
Is there a way to simply query for the node like in my first example?