graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Extend field directives utils to support argument directives

Open nicolaslt opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

I find getFieldsWithDirectives very useful, if only due to the directive value parser.

I now have a use case which would benefit from the same help but applied to argument directives.

Describe the solution you'd like

As a first pass, I think it would make sense to expose a getArgumentsWithDirectives function, which follows a similar signature to the existing fields function, eg:

function getArgumentsWithDirectives(
  args: readonly ConstArgumentNode[]
) : Record<string /* argument name */, DirectiveUsage[]> {
}

Describe alternatives you've considered On the simpler-change side of the spectrum: exporting the directive argument value parser, along the reduce function that creates the return signature

On the other hand, a slightly more complex change would save the need to list all fields on my end, if that new helper was working on the DocumentNode instead of the fields args

function getFieldsWithArgumentsDirectives(
  doc: DocumentNode
) : Record<string /* ${type}.${field} */, Record<string /* argument name */, DirectiveUsage[]>> {
}

// OR

function getFieldsWithArgumentsDirectives(
  doc: DocumentNode
) : Record<string /* ${type}.${field} */, { name: string /* argument name */, directives:DirectiveUsage[]}[]> {
}

nicolaslt avatar Aug 05 '22 15:08 nicolaslt

We'd love to accept a PR for this feature request :)

ardatan avatar Aug 05 '22 15:08 ardatan

Nice! I'll get to it in the next couple of weeks.

Did you have any thoughts on the alternatives?

Instinctively those signatures feel a bit clunky if we try to answer "Give me all arguments with directives X for this field", especially if the directive usage is nested under input types. I might submit a different feature request if a design cristalizes in my head.

nicolaslt avatar Aug 06 '22 08:08 nicolaslt

This can probably be closed now, the PR was merged :)

nicolaslt avatar Sep 27 '22 08:09 nicolaslt