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

fix: RecursiveTypeMapper returns exception which can't be handled by StandardServer #646

Merged
merged 4 commits into from
Feb 11, 2024

Conversation

fogrye
Copy link
Contributor

@fogrye fogrye commented Jan 3, 2024

RecursiveTypeMapper throws CannotMapTypeException when fails to find class by name. This exception goes through the GraphQl executor instead of catching and wrapping into ExecutionResult. Non wrapped exception does not trigger HttpCodeDecider. Schema test trust more to input than configuration which is not optimal, great possibility to improve configuration validation.

Fixes: #336

…StandardServer

RecursiveTypeMapper throws CannotMapTypeException when fails to find class by name. This exception goes through the GraphQl executor instead of catching and wrapping into ExecutionResult. Non wrapped exception does not trigger HttpCodeDecider.
Schema test trust more to input than configuration which is not optimal, great possibility to improve configuration validation.

Fixes: thecodingmachine#336
@oojacoboo
Copy link
Collaborator

Thanks for this @fogrye. That skipped test - can we get that resolved? What's the issue with it? I'm not seeing where it's using a request in that test either.

@fogrye
Copy link
Contributor Author

fogrye commented Jan 3, 2024

@oojacoboo it meant to fail when test query request entity which isn't presented because of bad config but after fix stoped. Now doTestSchema throws unexpected exception because $result->toArray() returns array without data key but with errors.

I see there only option for rewrite: check that with bad config (like not existing folder) nothing happens or new exception been thrown.

@oojacoboo
Copy link
Collaborator

Can we still use CannotMapTypeException and set the Error from the createLocatedError as the previous exception value? Maybe by adding a new method like CannotMapTypeException::createFromLocatedError?

@fogrye
Copy link
Contributor Author

fogrye commented Jan 3, 2024

@oojacoboo unfortunately no, GraphQL\Server\Helper is too strict about types.

@oojacoboo
Copy link
Collaborator

Why can't/shouldn't CannotMapTypeException just extend GraphQL\Error\Error?

@fogrye
Copy link
Contributor Author

fogrye commented Jan 3, 2024

@oojacoboo I see the point in keeping everything clean and consistent but here is some problems:

  1. If CannotMapTypeException becomes a child of Error all errors it constructs becomes "soft" and handled which is a big change.
  2. All exceptions in CannotMapTypeException some way referred to dev's mistake while in case of RecursiveTypeMapper it's end of execution which deserves some "special attention".
  3. Also CannotMapTypeException has nothing to take from it's possible parent and this extend just a bad inheritance.

Of course it's up to you to decide about such things as I'm newbie here but I would wish to clean up mappings a little including rethinking about how they trigger errors. Like, as an example, currently there is no way to throw error with reference to place in gql request because mapper which triggers them know nothing about which node it's processing.

@oojacoboo
Copy link
Collaborator

Good points @fogrye. Let's find a way to preserve that test. Maybe it makes sense to create a new Exception class for this scenario, then we can expect that Exception in that test commented out?

I agree that some improvements could be made on the mappings. If you want to submit a PR that takes a shot at this, that'd certainly be appreciated.

@oojacoboo
Copy link
Collaborator

@fogrye just a reminder on this. It'd be nice to get this merged in before it gets stale. We need tests though.

@fogrye
Copy link
Contributor Author

fogrye commented Feb 5, 2024

@oojacoboo had a busy time lately, will try to make it for tests soon.

tests/SchemaFactoryTest.php Outdated Show resolved Hide resolved
src/Mappers/RecursiveTypeMapper.php Show resolved Hide resolved
@oojacoboo
Copy link
Collaborator

@fogrye thanks for this - couple small code style changes and I think it's ready to merge :)

@oojacoboo oojacoboo merged commit 8c97363 into thecodingmachine:master Feb 11, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

graphql api returns 500 http codes on unknown types
2 participants