thecodingmachine / graphqlite

Use PHP Attributes/Annotations to declare your GraphQL API

Home Page:https://graphqlite.thecodingmachine.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing `annotations` parameter in #[MagicField] and #[SourceField]

oprypkhantc opened this issue · comments

Both #[MagicField] and #[SourceField] accept annotations that should be passed through due to inability to specify the attributes directly on the field:

#[Type]
#[MagicField(attributes: ['annotations' => [new MyCustomMiddleware]], name: 'field')]
class MyType {}

All other properties of MagicField and SourceField can be specified directly, without using the "annotations API" (which is $attributes), so I believe them missing a array $annotations = [] parameter in the end is a bug:

#[Type]
#[MagicField(name: 'field', annotations: [new MyCustomMiddleware])]
class MyType {}

Confirm this is not the expected behaviour and I'll make a PR with a fix, thanks!

I'm not aware of any specific reason why that property isn't exposed in the constructor. I'm assuming it's related to the fact that these were Doctrine annotations before they were proper PHP attributes and, for some reason, those weren't migrated. Maybe because that property isn't a primitive like the others?

I think a PR should be fine here as long as we have test coverage.

Could be. I'll make a PR then. Thanks!