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

Feature: ability to attach custom attributes to field definitions.

Open Warxcell opened this issue 1 year ago • 3 comments

Hey, I'm writing custom Executor, optimized for my needs (basically I need per coordinate cache) - so my idea is to attach custom cache resolver which will be called prior original one to check from cache. The issue is that it's very hard to do that - because I need to fork basically whole lib - it would be awesome if it's possible to attach custom attributes to field definition so I can check them later in my custom Executor.

Or even better - if we can incorporate that cache into ReferenceExecutor ?

What do you think?

Warxcell avatar Feb 16 '25 21:02 Warxcell

it would be awesome if it's possible to attach custom attributes to field definition

You can, the array $config passed in \GraphQL\Type\Definition\FieldDefinition::__construct is stored in a public property unchanged.

I don't really understand what else you are describing.

spawnia avatar Feb 17 '25 10:02 spawnia

Its fine, but there are 2 issues

  1. That array is not transferred during SchemaExtend - everything else besided known props for the graphql are lost.
  2. The config itself is strongly typed with specific keys - so phpstan will complain that custom indexes doesn't exists.

Warxcell avatar Feb 17 '25 12:02 Warxcell

Perhaps you can propose a pull request to fix 1.? And in regards to 2., strong typing won't be possible either way - you can ignore PHPStan errors though.

spawnia avatar Feb 17 '25 16:02 spawnia