Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhelpful error message when a query is defined twice #322

Open
lexmes opened this issue Jan 15, 2021 · 7 comments
Open

Unhelpful error message when a query is defined twice #322

lexmes opened this issue Jan 15, 2021 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@lexmes
Copy link
Contributor

lexmes commented Jan 15, 2021

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.

@moufmouf
Copy link
Member

Interesting!
Do you think you could write an integration test to showcase the problem?

For instance by duplicating this test (

public function testInputOutputNameConflict(): void
{
$arrayAdapter = new ArrayAdapter();
$arrayAdapter->setLogger(new ExceptionLogger());
$schemaFactory = new SchemaFactory(new Psr16Cache($arrayAdapter), new BasicAutoWiringContainer(new EmptyContainer()));
$schemaFactory->addControllerNamespace('TheCodingMachine\\GraphQLite\\Fixtures\\InputOutputNameConflict\\Controllers');
$schemaFactory->addTypeNamespace('TheCodingMachine\\GraphQLite\\Fixtures\\InputOutputNameConflict\\Types');
$schema = $schemaFactory->createSchema();
$this->expectException(CannotMapTypeException::class);
$this->expectExceptionMessage('For parameter $inAndOut, in TheCodingMachine\\GraphQLite\\Fixtures\\InputOutputNameConflict\\Controllers\\InAndOutController::testInAndOut, type "InAndOut" must be an input type (if you declared an input type with the name "InAndOut", make sure that there are no output type with the same name as this is forbidden by the GraphQL spec).');
$schema->validate();
}
) and creating a new namespace with both controllers?

@lexmes
Copy link
Contributor Author

lexmes commented Jan 21, 2021

Yep, will give it a go :)

lexmes added a commit to lexmes/graphqlite that referenced this issue Mar 3, 2021
@lexmes
Copy link
Contributor Author

lexmes commented Mar 3, 2021

I've tried to recreate the issue here: lexmes@49274e3

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?

@oojacoboo
Copy link
Collaborator

oojacoboo commented Mar 29, 2021

@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.

@oojacoboo oojacoboo added the help wanted Extra attention is needed label Mar 29, 2021
@aszenz
Copy link
Contributor

aszenz commented Apr 29, 2022

I have seen some errors from asserts in development, it's usually when queries/fields/names are duplicated

@oojacoboo
Copy link
Collaborator

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.

@oojacoboo
Copy link
Collaborator

@lexmes can you create a PR for this please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants