graphqlite
graphqlite copied to clipboard
Unhelpful error message when a query is defined twice
Lets assume we have to following setup:
class ControllerA {
/**
* @Query()
* @returns string[]
*/
allPosts() : array;
}
...
class ControllerB {
/**
* @Query()
* @returns string[]
*/
allPosts() : array;
}
Right now the error message that i get is: assert($firstDuplicate instanceof FieldDefinition). Thats not very helpful. I would suggest something along the lines of cannot redeclare query "allPosts" in controller "<FQDN>\ControllerB" as it was already defined in <FQDN>\ControllerA.
I don't know if its my setup that is causing this error. But even then its not very helpful.
The error is generated in AggregateControllerQueryProvider.php:98.
Interesting! Do you think you could write an integration test to showcase the problem?
For instance by duplicating this test (https://github.com/thecodingmachine/graphqlite/blob/c6177437bdac274fff975757cb04a0896015cb4d/tests/Integration/EndToEndTest.php#L1533-L1547) and creating a new namespace with both controllers?
Yep, will give it a go :)
I've tried to recreate the issue here: https://github.com/lexmes/graphqlite/commit/49274e38dc6136bae8921df2567e3029fec6a2cd
But the error message there is correct. Can you think of any Circumstance under which the assert($firstDuplicate instanceof FieldDefinition) expression in https://github.com/lexmes/graphqlite/blob/master/src/AggregateControllerQueryProvider.php#L98 will yield false?
@lexmes I'm assuming you confirmed that assertions are enabled in the environment in which you tested? That's a PHP config setting. I not really sure that we should be using assert in this particular case.
I have seen some errors from asserts in development, it's usually when queries/fields/names are duplicated
Assert can be problematic b/c it doesn't provide any context to the assertion. And you took the time to write it. Just take a few seconds more to throw an exception with an intelligible message that helps the developer, or yourself later on.
@lexmes can you create a PR for this please.