github-community-projects / github-community-projects/graphql-client
[Bug] Network errors are discarded.
- Vorherrschende Sprache
- Ruby
- Sterne
- 78
- Forks
- 228
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
If there's an HTTP error, calls to `GraphQL::Client` can return this:
```
KeyError: key not found: "data" (KeyError)
```
E.g., when I try the example in the readme to `https://example.com/graphql`, I expect some kind of network or HTTP error. Instead, I get the above `KeyError`.
I got this when making changes to my infrastructure. It made it very hard to debug problems.
----
I looked at `load_schema`, and found:
```
pry(main)> GraphQL::Client.load_schema(HTTP)
KeyError: key not found: "data" (KeyError)
from gems/3.4.0/gems/graphql-2.5.2/lib/graphql/schema/loader.rb:17:in 'Hash#fetch'
```
The `load_schema` call turns into `load_schema(dump_schema(HTTP))`. `dump_schema` seems to return full error info. So, between those two function calls, the information is lost:
```
[pry(main)> GraphQL::Client.dump_schema(HTTP)
=> {"errors" => [{"message" => "403 Forbidden"}]}
```
This happens other places that call `execute`, I believe, like `.query()`.
----
In my opinion, the core problem is, the library uses fp-style `Either` error returns. However, Ruby doesn't have a way (like Rust or Haskell do) to enforce the handling of the error case. And so, it's possible to simply not handle them appropriately, like here.
Either-style API:
https://github.com/github-community-projects/graphql-client/blob/aff58829ea27c7e59213756aab0bdfdb0e03941a/lib/graphql/client/http.rb#L62-L63
IMO, the fix is to use Ruby's Exception/Error facility so that library clients can meaningfully handle errors.
Beitragsleitfaden
Rechercherichtung
Beginne mit lib/graphql/client/http.rb rund um die Rückgabe im Either-Stil und mit lib/graphql/schema/loader.rb, wo load_schema dump_schema verwendet. Verfolge den Fehlerpfad durch load_schema und die anderen genannten execute-Aufrufer, einschließlich query(), und überprüfe anschließend, dass HTTP- oder GraphQL-Fehler weiterhin verfügbar bleiben, anstatt zu einem KeyError zu werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- ruby
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100