Skip to content

Coercion error path. - #1195

Merged
spawnia merged 8 commits into
webonyx:masterfrom
Warxcell:coercion_error_path
Jul 17, 2022
Merged

spawnia merged 8 commits into
webonyx:masterfrom
Warxcell:coercion_error_path

Conversation

@Warxcell

@Warxcell Warxcell commented Jul 7, 2022

Copy link
Copy Markdown
Contributor

I know that's not best place to put it, I'm looking for more elegant solution.

The idea is to have path of error in structured way, so we can format it to the frontend - and frontend can locate the error easier - otherwise frontend should parse strings to locate the error.

@spawnia

spawnia commented Jul 7, 2022

Copy link
Copy Markdown
Collaborator

I do not understand what this is trying to achieve. Please add a test that illustrates the effect of this change.

@spawnia
spawnia marked this pull request as draft July 7, 2022 09:13
@Warxcell

Warxcell commented Jul 7, 2022 •

Copy link
Copy Markdown
Contributor Author

The idea is client to avoid parsing strings from error message like that
image

But directly receive path as array.

@spawnia

spawnia commented Jul 7, 2022

Copy link
Copy Markdown
Collaborator

We will implement nothing that breaks or extends the error format specified in the GraphQL specification, see https://spec.graphql.org/draft#sec-Errors. I think what you are trying to do will require an addition to extensions.

@Warxcell

Warxcell commented Jul 7, 2022 •

Copy link
Copy Markdown
Contributor Author

That's fine, I'm just looking a way to inject this into exception - so it could be used by our custom formatter. Otherwise I should preg_match from error message, before I can add it to extensions.

That's why the first sentence is I know that's not best place to put it, I'm looking for more elegant solution.

Comment thread src/Utils/Value.php Resolved
@spawnia

spawnia commented Jul 7, 2022

Copy link
Copy Markdown
Collaborator

Otherwise I should preg_match from error message

That might be the easiest. Alternatively, I could see wrapping the $originalError with an exception such as CoercionError and expose structured data there - or perhaps have CoercionError extend Error.

@Warxcell

Warxcell commented Jul 8, 2022 •

Copy link
Copy Markdown
Contributor Author

Sounds perfect to me. I'm fine with either way. Just tell me what's preferred approach and I can start working on it.

@spawnia

spawnia commented Jul 8, 2022

Copy link
Copy Markdown
Collaborator

Let's go with class CoercionError extends Error and reduce the number of nested exceptions.

@Warxcell
Warxcell requested a review from spawnia July 8, 2022 09:24
Comment thread src/Error/CoercionError.php Resolved
Comment thread src/Utils/Value.php Resolved
Comment thread src/Error/CoercionError.php Resolved
Comment thread tests/Utils/CoerceValueTest.php Resolved
Comment thread tests/Utils/CoerceValueTest.php Resolved
@Warxcell
Warxcell force-pushed the coercion_error_path branch 4 times, most recently from 5b495eb to d655922 Compare July 8, 2022 11:58
@Warxcell
Warxcell requested a review from spawnia July 8, 2022 11:58
@Warxcell
Warxcell force-pushed the coercion_error_path branch from d655922 to 58fc6bc Compare July 8, 2022 12:00
Comment thread tests/Utils/CoerceValueTest.php Resolved
Comment thread tests/Utils/CoerceValueTest.php Resolved
Comment thread tests/Utils/CoerceValueTest.php Resolved
Comment thread tests/Utils/CoerceValueTest.php Resolved
@Warxcell
Warxcell requested a review from spawnia July 10, 2022 05:20
@Warxcell
Warxcell marked this pull request as ready for review July 10, 2022 05:21
@spawnia
spawnia merged commit 07ddf15 into webonyx:master Jul 17, 2022
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.

2 participants