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

Emit individual warnings for Schema errors #1203

Open
numso opened this issue Oct 27, 2022 · 0 comments
Open

Emit individual warnings for Schema errors #1203

numso opened this issue Oct 27, 2022 · 0 comments

Comments

@numso
Copy link

numso commented Oct 27, 2022

Hello!

Today when there are mistakes in a schema, all of the error messages are combined into one big message and raised in an Absinthe.Schema.Error. The diagnostics emitted by Elixir point to the user's Schema module. It's not too hard to follow that and find where the actual errors are coming from but it is a little inconvenient.

image

image

It would be nice if the diagnostics included the locations of where those errors originated. Tools built to read those diagnostics would be more beneficial without needing to do any special parsing for errors emitted by Absinthe. It could enable something like this in the editor:

image

We can get that to happen if we loop over and IO.warn/2 those errors before raising. Something like the following code. I'm unfamiliar with a lot of the internal Absinthe code so this snippet is probably incomplete.

{:error, errors, _} ->
raise Absinthe.Schema.Error, phase_errors: List.wrap(errors)

-      {:error, errors, _} ->
-        raise Absinthe.Schema.Error, phase_errors: List.wrap(errors)
+      {:error, errors, _} ->
+        errors
+        |> List.wrap()
+        |> Enum.each(fn %{message: message, locations: locations} ->
+          %{line: line, file: file} = List.last(locations)
+          IO.warn(message, file: file, line: line)
+        end)
+
+        raise Absinthe.Schema.Error, phase_errors: List.wrap(errors)

Is this desired behavior? If so would we want to leave the raised error message as it is or change it to something shorter like "There were problems with your schema. View the previously emitted warnings"?

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

No branches or pull requests

1 participant