Automatically detect which fields we need for GraphQL
This was spun off from https://gitlab.com/gitlab-org/gitlab-triage/-/merge_requests/203#note_561811492
It would be nice if we don't have to specify which fields we need with https://gitlab.com/gitlab-org/gitlab-triage/-/issues/231 and auto-detect fields and request those for us.
https://gitlab.com/gitlab-org/gitlab-triage/-/issues/231 would still be useful for power GraphQL users, but for most cases auto-detecting will be easier to use.
This can be done with a ResourceFieldsRecorder
pretending to be a Resource
passed down to the policy, something like:
class ResourceFieldsRecorder
attr_reader :fields
def initialize
@fields = Set.new
end
def [](name)
fields << name
"dummy #{name}"
end
def title
self[:title]
end
end
And we'll know which fields this policy needs:
recorder = ResourceFieldsRecorder.new
policy = RulePolicy.new(resource_type, rule, [recorder], network)
Action.process(
policy: policy,
network: network,
dry: options.dry_run)
# ...
recorder.fields # => now we can convert this to be GraphQL query