Commit Graph

16 Commits

Author SHA1 Message Date
Sunli
c777150dcd Use value! instead of serde_json::json!. 2020-10-12 10:17:05 +08:00
Koxiaet
50009b66ce Rework errors
This completely overhauls the error system used in async-graphql.
- `Error` has been renamed to `ServerError` and `FieldError` has been
renamed to just `Error`. This is because `FieldError` is by far the most
common error that users will have to use so it makes sense to use the
most obvious error name. Also, the current name didn't make sense as it
was used for things other than field errors, such as the data callback
for websockets.
- `ServerError` has been made completely opaque. Before it was an enum
of all the possible errors, but now it just contains an error message,
the locations, the path and extensions. It is a shame that we lose
information, it makes more sense as _conceptually_ GraphQL does not
provide that information. It also frees us to change the internals of
async-graphql a lot more.
- The path of errors is no longer an opaque JSON value but a regular
type, `Vec<PathSegment>`. The type duplication of `PathSegment` and
`QueryPathSegment` is unfortunate, I plan to work on this in the future.
- Now that `ServerError` is opaque, `RuleError` has been removed from
the public API, making it simpler.
- Additionally `QueryError` has been completely removed. Instead the
error messages are constructed ad-hoc; I took care to never repeat an
error message.
- Instead of constructing field-not-found errors inside the
implementations of field resolvers they now return `Option`s, where a
`None` value is representative of the field not being found.
- As an unfortunate consequence of the last change, self-referential
types based on the output of a subscription resolver can no longer be
created. This does not mean anything for users, but causes lifetime
issues in the implementation of merged objects. I fixed it with a bit of
a hack, but this'll have to be looked into further.
- `InputValueError` now has a generic parameter - it's kind of weird but
it's necessary for ergonomics. It also improves error messages.
- The `ErrorExtensions` trait has been removed. I didn't think the
`extend` method was necessary since `From` impls exist. But the
ergonomics are still there with a new trait `ExtendError`, which
is implemented for both errors and results.
- `Response` now supports serializing multiple errors. This allows for
nice things like having multiple validation errors not be awkwardly
shoved into a single error.
- When an error occurs in execution, data is sent as `null`. This is
slightly more compliant with the spec but the algorithm described in
<https://spec.graphql.org/June2018/#sec-Errors-and-Non-Nullability> has
yet to be implemented.
2020-09-29 20:06:44 +01:00
Sunli
e645e9d999 Remove the GQL prefix of all macros. #208 2020-09-18 09:10:24 +08:00
Koxiaet
890b282dd9 Improve websockets 2020-09-17 19:22:54 +01:00
Sunli
492bba1cdd Move http::websocket::create and http::websocket::create_with_initializer function to http::WebSocketStream. 2020-09-15 20:07:59 +08:00
Sunli
86a6a34aac http::websocket::create function now returns the WebSocketStream type. 2020-09-15 11:19:00 +08:00
Koxiaet
9796364348 Move websockets to http module and fix doc tests 2020-09-13 07:40:34 +01:00
Sunli
24b80d52d3 Remove all attribute macros that can be replaced by derive. 2020-09-13 11:41:15 +08:00
Sunli
a4fdf6a38a Re-enable the test on websocket. 2020-09-11 16:41:56 +08:00
Sunli
f3c0d86f12 Continue to refactor. 2020-09-10 16:39:43 +08:00
Koxiaet
47259548c4 Support service parsing in async-graphql-parser
- Instead of adding a separate module `schema` like there was before,
since service parsing and executable parsing have a fair amount of
overlap I put them as two submodules `executable` and `service` in both
`parse` and `types`. Also, the grammar is unified under one `.pest`
file.
- Added const equivalents to `Value`, `Directive` etc
- Change the reexport `async_graphql::Value` from
`async_graphql_parser::types::Value` to
`async_graphql_parser::types::ConstValue` since in 99% of cases in this library
a const value is wanted instead of a value.
- Added consistent usage of executable/service instead of the ambiguous
query/schema.
- Some of the tests actually had invalid GraphQL so the new more correct
grammar made them fail, that was fixed.
- Added a `Name` newtype to refer to GraphQL names
(`[A-Za-z_][A-Za-z_0-9]*`) since they are used so frequently.
2020-09-08 09:21:27 +01:00
Koxiaet
02f7a5fbbc Remove dependency on serde_derive, satisfy Clippy, improve docs 2020-08-31 19:18:02 +01:00
Sunli
4e8bd65b34 Fix send data with 'complete' WebSocket message. #238 2020-08-14 15:21:10 +08:00
Sunli
aa3293b65c Add support for query execution over websocket. 2020-07-31 11:30:57 +08:00
Blaine Bublitz
c48f126fcd Use FieldResult for data(), add data_unchecked() for panic 2020-07-06 17:39:53 -07:00
sunli
220cd1e775 Report subscription stream errors to the client. 2020-05-03 16:02:46 +08:00