lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Apply schema manipulation on input field definitions

Open spawnia opened this issue 4 years ago • 3 comments

What problem does this feature proposal attempt to solve?

Lighthouse applies a process we call schema manipulation for some directives, allowing them to transform the GraphQL AST: https://github.com/nuwave/lighthouse/blob/301930b356faa63da681d564cbef41c7d312f2aa/src/Schema/AST/ASTBuilder.php#L133-L137

The directives @whereConditions and @orderBy implement the ArgManipulator interface. This is only called when they are defined directly on the args of a field.

While there is a directive interface for definitions that are directly applied on types (e.g. input Foo @example), we currently have no mechanism for traversing down into the fields of input types and apply transformation there.

Which possible solutions should be considered?

An implementation for this would entail:

  • Adding a new interface InputFieldManipulator
  • Add a method to ASTBuilder that applies it to input fields
  • Implement the interface for the ArgManipulator directives where it makes sense

spawnia avatar Jun 11 '20 16:06 spawnia

It would also allow us to make repeatable situations (like create/update/delete relationships) a little easier.I am trying to manipulate the input object to automagically create the create/update/delete relationship functionality, only to find out this does not work.

I can make a pull request so that we can at least create our own directives that can manipulate the AST.

henzeb avatar Nov 16 '20 10:11 henzeb

@henzeb that would be great. Let me know if you require further clarification for what needs to be done, I hope the issue description is clear enough.

spawnia avatar Nov 16 '20 11:11 spawnia

Great. Will look into it this weekend. only the third item is a little vague to me. 1 and 2 is all I need for my usecase.

henzeb avatar Nov 18 '20 08:11 henzeb