Commit Graph

333 Commits

Author SHA1 Message Date
Sunli
024a143f11 Add support for graphql-ws pings. #635 2021-09-16 21:10:39 +08:00
Miaxos
b55c432886 fix: add test case for serializing issue 2021-08-18 14:22:17 +00:00
Sunli
c80687af80 Clippy clean 2021-07-31 23:54:16 +08:00
Sunli
230eb847d8 Add support for the list operator to the input value validator. #579 2021-07-20 15:16:34 +08:00
Sunli
ecf8890e7e Implemented OutputType for Bytes. #569 2021-07-18 21:42:39 +08:00
Yin Jifeng
7e21cfa944 Allow field visible to support paths 2021-07-18 20:16:39 +08:00
Sunli
8f8fe3e46d Make Schema::execute return HTTP headers when an error occurs. #572 2021-07-16 07:47:43 +08:00
Sunli
528a908f95 Update guard test 2021-07-15 08:09:29 +08:00
Rodgers
0ed7384cbf Add test for is_valid_with_extensions 2021-07-08 22:06:13 +07:00
Sunli
2ffbfe7440 Add concrete type support for complex object. 2021-07-04 14:05:08 +08:00
Julien Nicoulaud
8c9bf0f04c #550: add unit test for generic Object/Simple/ComplexObject 2021-07-03 18:00:16 +02:00
Sunli
c367f15b05 Fix the bug that MergedObject may cause panic. #539 2021-06-21 09:48:19 +08:00
Sunli
543ce408b0 Implement InputType and OutputType for [T; N] array. 2021-06-17 10:39:27 +08:00
Sunli
5691f6ca71 Add serial attribute for MergedObject macro. #539 2021-06-16 15:08:33 +08:00
Sunli
b7b9abf40d Add serial attribute for SimpleObject and Object macros. #539 2021-06-15 08:53:26 +08:00
Sunli
f992e8ab94 Add the operation_name to Extension::execute method. 2021-06-10 10:17:33 +08:00
Sunli
9a7cfb72f5 Allow field guards to support paths. #536 2021-06-08 19:42:53 +08:00
Sunli
412f78211f Update test 2021-06-08 19:04:06 +08:00
Sunli
e7382bf549 Rework error propagation. #531 2021-06-08 10:05:30 +08:00
Sunli
59ee28b634 Update tests 2021-06-07 14:12:28 +08:00
Sunli
f8021c0fb5 Add support for returning multiple resolver errors. #531 2021-06-07 14:03:36 +08:00
Sunli
bdeeff328a Fix the problem that the ComplexObject macro cannot work due to the secret attribute. 2021-04-23 10:25:00 +08:00
Sunli
6651e86c4c Add test for drop subscription stream on unsubscribe. 2021-04-13 11:26:55 +08:00
Sunli
572f907df7 Now when the resolver returns the Result type, E can be all types that implement Into<async_graphql::Error>. 2021-04-09 15:04:01 +08:00
Sunli
81e053811b Improve Extensions. 2021-04-05 12:21:02 +08:00
Sunli
824356d118 Rework Extension 2021-04-04 14:37:41 +08:00
Sunli
e899885aa8 Add Request::disable_introspection method. #456 2021-03-30 11:59:57 +08:00
Sunli
05911f3516 Rework Extension & TracingExtension & OpenTelemetryExtension 2021-03-26 12:03:10 +08:00
Sunli
c2c2868b64 Fix internal context missing when there's no connection_init frame. #451 2021-03-24 17:24:12 +08:00
Sunli
15036be792 Add ComplexObject macro. #355 2021-03-18 10:13:46 +08:00
Sunli
4f47703118 Switch the async runtime used for testing to Tokio. 2021-03-12 12:47:24 +08:00
Taiki Endo
2bff2ad9dc Support generics in Subscription types 2021-03-09 22:21:56 +09:00
Sunli
88232deb62 Add test for Federation entity lookup with DataLoader. 2021-03-06 08:21:44 +08:00
Sunli
4f2ea5ed50 Moved Variables from async_graphql::context::Variables to
`async_graphql::Variables`.
2021-02-28 09:37:42 +08:00
Sunli
4ebe0dd4cd Allow the deprecation attribute to have no reason. 2021-02-27 11:59:58 +08:00
Sunli
144ddb752c Clippy clean 2021-02-26 20:05:09 +08:00
Sunli
5c66a9cdda Add support for Federation nested keys. 2021-02-21 23:06:26 +08:00
Sunli
2d7627cd39 Fixed GraphQL over WebSocket Protocol does not support ConnectionError events. #406 2021-02-06 11:02:41 +08:00
Sunli
b98e35995d Supports async websocket initializer. #393 2021-01-16 16:37:20 +08:00
Sunli
9c6fe67a23 Fix a bug that cause generic InputObject and SimpleObject is incorrect name. #387 2021-01-14 19:20:28 +08:00
Sunli
85a0ab0da1 Add support for generic SimpleObject. #387 2021-01-14 13:16:30 +08:00
Sunli
b054fc0704 Add Send + Sync constraints for InputType, OutputType and SubscriptionType. 2021-01-14 12:41:59 +08:00
Sunli
74657c6242 Add support for generic InputObject. #387 2021-01-14 11:27:15 +08:00
Sunli
5f2e0ae50d Clippy clean 2021-01-11 09:01:28 +08:00
Sunli
099415fd42 Implements InputType for Box<T> and Arc<T>. #382 2021-01-10 13:48:18 +08:00
Sunli
8f32e8e81e Fix #[Object] macro panic with default u32. #361 2020-12-28 18:39:17 +08:00
Aaron Hill
d8780bd720 Strip r# prefix when constructing getter ident
When calling `to_string()` on an identifier, the returned string will
have an `r#` prefix if the original identifer was a raw identifier. This
prefix needs to be removed if the identifier is interpolated into
another identifier (e.g. `__some_prefix__r#other_ident`) in order for
the new identifier to be valid.

This issue was previously masked due to the fact that the relevant test
uses `r#i32`. It's possible to use `i32` as a normal (non-raw) ident -
due to a bug in rustc, this means that the user-supplied `r#` prefix
will be lost when calling `to_string()`. This bug will eventually be
fixed, causing `to_string()` to start returning `r#i32` instead of
`i32`.

This commit strips the `r#` prefix (if present) from an identifier
before using it to construct a new identifier. The relevant test is
updated to use `r#match`, which actually requires the `r#` prefix to be
a valid identifier. This causes the test to fail without this patch on
current versions of Rust.
2020-12-20 19:08:22 -05:00
Sunli
bf9e3ec578 Improve depth and complex. 2020-12-18 18:56:28 +08:00
Sunli
c6d8df0bdb Remove async-channel and async-mutex from dependencies. 2020-12-17 10:05:32 +08:00
Sunli
fe24247c9d Add the skip attribute to the InputObject fields. 2020-12-15 20:29:59 +08:00
Sunli
ba23761cb4 Add visible attributes on types, fields, and parameters, allowing some content to be hidden based on conditions. 2020-12-12 16:23:53 +08:00
Sunli
b3bd8603e3 Add tests for graphql-ws. 2020-12-04 16:44:48 +08:00
Sunli
46d01db40f Merge branch 'master' into pr/350 2020-12-04 12:17:23 +08:00
Sunli
4b00f9393a Add websocket subprotocol for actix-web. 2020-12-04 12:13:52 +08:00
Sunli
9b10ebeab5 Fix the problem that the fields of the list are not merged correctly.#345 2020-11-27 10:26:23 +08:00
Sunli
12b3b0ee46 Fix async_graphql::Object does not work when inside macro after rust 1.48.0 2020-11-22 09:53:18 +08:00
Sunli
456f776fdb Merge branch 'master' of github.com:async-graphql/async-graphql 2020-11-04 10:26:04 +08:00
Sunli
194a2ff100 Fix the problem that Description derived macro do not support generic objects. 2020-11-04 10:25:30 +08:00
Sunli
bcf85fce51 Fix #333 2020-11-03 18:16:55 +08:00
Sunli
03144a47b9 Fix the problem of scalar macro. 2020-11-03 13:50:22 +08:00
Sunli
734b43b613 Fix interface downcasting. #330 2020-10-31 08:58:54 +08:00
Sunli
8d2c8f9bcc Add test for SchemaBuilder::override_description. #327 2020-10-27 20:47:24 +08:00
Sunli
320d9eef50 Add use_type_description attribute for derive macros Object, Scalar and Subscription. 2020-10-26 21:34:05 +08:00
Sunli
33697ea19f Add interface to implement another interface. #322 2020-10-24 09:08:18 +08:00
Sunli
4880c687ca Fix the problem that the Registry::create_dummy_type function may overwrite the keys of the registered type. #316 2020-10-20 19:55:10 +08:00
Sunli
e3d693da28 Add entity lookup support for MergedObject.
Add some GraphQL specification constraints for all derived macros.

Use `Registry::create_dummy_type` to create a merged type.
2020-10-20 11:49:31 +08:00
Sunli
83a0028085 Fix the bug that ʻExtension::prepare_request` cannot get the correct request data through the context.
Add test code for extension.
2020-10-18 11:24:16 +08:00
Koxiaet
a79ee02958 Fix macro hygiene 2020-10-16 20:21:46 +01:00
Koxiaet
79ad5540a1 Make macros hygienic 2020-10-16 11:37:59 +01:00
Koxiaet
12fe7445c7 Replace futures with futures_util 2020-10-16 07:49:22 +01:00
Sunli
4fa4b25ce4 Fix can no longer derive Union for union types with lifetimes. #311 2020-10-15 08:53:17 +08:00
Sunli
f9f60d31ec Configurable case conversion. 2020-10-14 19:16:10 +08:00
Sunli
2d0c192df8 Fix a bug in the validator. 2020-10-14 10:54:46 +08:00
Sunli
715d39b50c 2.0.1 2020-10-14 10:25:41 +08:00
Sunli
6958202238 Update docs 2020-10-13 10:19:30 +08:00
Sunli
c777150dcd Use value! instead of serde_json::json!. 2020-10-12 10:17:05 +08:00
Sunli
e056edbaa0 Add parse_value and from_value funcntions. 2020-10-11 20:24:31 +08:00
Sunli
87ba51fdd0 Some improvements. 2020-10-10 16:28:07 +08:00
AurelienFT
53eab09f19 Rework guard (#296)
Rework guard #293
2020-10-06 17:16:51 +08:00
Sunli
be2b39e486 Restore the original error extension implementation. 2020-10-02 14:56:10 +08:00
Koxiaet
4b20a21783 Fix compilation and tests 2020-09-30 19:40:17 +01:00
Koxiaet
768b666acd Merge master 2020-09-30 18:24:24 +01: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
e60864a18d Rework async-graphql-derive. #288 2020-09-29 16:06:10 +08:00
Sunli
bff5e97def Add feature to flatten nested GraphQL unions. #286 2020-09-28 11:13:46 +08:00
Sunli
a725594cd1 Add remote attribute for Enum macro. #276 2020-09-27 18:19:11 +08:00
Sunli
7d3eb9b62c Make Object and Subscription macros support #cfg(...) attribute. #281 2020-09-27 10:20:20 +08:00
Sunli
5c293ffdc2 Improve the error message of Tracing extension. 2020-09-26 12:35:28 +08:00
Sunli
5cb507ed90 Add test code for generic object. #274 2020-09-23 14:39:18 +08:00
Sunli
20d240df47 Fix enum strings in query variables are not converted to proper enums. #270 2020-09-20 13:28:18 +08:00
Sunli
e645e9d999 Remove the GQL prefix of all macros. #208 2020-09-18 09:10:24 +08:00
Koxiaet
d52268523f Merge branch 'master' of github.com-koxiaet:async-graphql/async-graphql into master 2020-09-17 19:23:15 +01:00
Koxiaet
890b282dd9 Improve websockets 2020-09-17 19:22:54 +01:00
Sunli
76257403e2 Add support for batch queries. 2020-09-17 19:54:12 +08:00
Sunli
70556af838 Add test for ErrorExtensions. 2020-09-17 08:47:41 +08: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
Sunli
42817a3aa6 Implement Type for more stdlib collection types #189
Implement InputValueType/OutputValueType for HashSet<T>/BTreeSet<T>/VecDeque<T>/LinkedList<T>
Implement ScalarType for char/NonZero*/HashMap<String,T>/BTreeMap<String, T>
2020-09-14 20:06:44 +08:00
Sunli
5bb705bdf3 2.0.0-alpha.5 2020-09-14 09:46:22 +08:00
Koxiaet
6e628031bf Rework subscriptions
The main change in this commit is changing the return type of
SubscriptionType::create_stream from
Future<Result<Stream<Result<Response>>>> to just Stream<Result<Json>>. I
also allowed the returned stream to borrow from self and context.
2020-09-13 18:52:36 +01:00
Koxiaet
367076cd66 Remove SimpleBroker 2020-09-13 10:47:28 +01: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
Koxiaet
dcc7d1be14 Replace http::GQLRequest with Request 2020-09-12 17:07:46 +01:00
Koxiaet
35e74a4e17 Create resolver_utils 2020-09-12 10:29:52 +01:00
Sunli
a4fdf6a38a Re-enable the test on websocket. 2020-09-11 16:41:56 +08:00
Sunli
c129079f69 Fix tests 2020-09-11 16:05:21 +08:00
Sunli
049b652dd6 Add transports::websocket module. 2020-09-11 15:54:56 +08:00
Sunli
35f17a389c Remove unnecessary Result on Schema::execute_stream function. 2020-09-11 10:47:55 +08:00
Sunli
91c75ced2a Make all tests passed (async-graphql). 2020-09-10 19:35:48 +08:00
Sunli
f3c0d86f12 Continue to refactor. 2020-09-10 16:39:43 +08:00
Koxiaet
04c898ef01 Rustfmt 2020-09-08 09:30:29 +01: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
1c26ff124f Merge branch 'master' into master 2020-09-06 07:20:18 +01:00
Koxiaet
c055736101 Rustfmt 2020-09-06 07:16:36 +01:00
Koxiaet
81d85c2535 Rewrite async-graphql-parser 2020-09-06 06:38:31 +01:00
Sunli
b4997e4b27 Add test for multiple flatten attribute of InputObject. 2020-09-04 14:14:48 +08:00
Sunli
78a1a33cda Add flatten type field support for input objects. #255 2020-09-03 20:00:33 +08:00
Sunli
769bffcbf2 Fix the test code and add docs. 2020-09-01 09:10:12 +08:00
Koxiaet
02f7a5fbbc Remove dependency on serde_derive, satisfy Clippy, improve docs 2020-08-31 19:18:02 +01:00
Sunli
6a38057a22 Implements Default for Schema. 2020-08-28 14:19:35 +08:00
Sunli
c35eecd90d Merge subscriptions #243 2020-08-27 15:35:48 +08:00
Sunli
a0148675c8 Add support for mut field args. 2020-08-17 21:48:53 +08:00
Sunli
4e8bd65b34 Fix send data with 'complete' WebSocket message. #238 2020-08-14 15:21:10 +08:00
Sunli
caedc4d783 Update test for MergedObject. 2020-08-11 09:37:33 +08:00
Sunli
2a62c56104 Add derive macro GQLMergeObject. #231 2020-08-10 14:11:46 +08:00
Sunli
b0403f4e99 Add Default impl for MergedObject. #231 2020-08-10 10:47:30 +08:00
Sunli
4b6bb38e83 Add MergedObject type. #231 2020-08-09 15:03:10 +08:00
Sunli
47174966fb Add directive @ifdef 2020-08-06 14:52:54 +08:00
Sunli
aa3293b65c Add support for query execution over websocket. 2020-07-31 11:30:57 +08:00
Sunli
2cf350a5c8 Removes code about streaming requests. 2020-07-31 10:10:03 +08:00
Sunli
2dc61013be Replace Value::Int and Value::Float with Value::Number. 2020-07-29 09:42:52 +08:00
Sunli
909ae5e64d Fix input validator is ignored when using variable #207 2020-07-11 10:05:30 +08:00
Sunli
2dde8b4aa6 Add OutputJson type #203 2020-07-08 14:44:57 +08:00
Blaine Bublitz
c48f126fcd Use FieldResult for data(), add data_unchecked() for panic 2020-07-06 17:39:53 -07:00
Sunli
d03e939394 Correct handling of raw identifiers #195 2020-07-02 10:25:20 +08:00
Blaine Bublitz
0fde868459 Fix issue with unwrapping derive attributes 2020-06-25 13:54:13 -07:00
Sunli
eb7a72aac6 Remove ref attribute for SimpleObject fields, and add owned attribute. 2020-06-23 14:42:57 +08:00
Sunli
665b337bf2 Remove all datasource-related code and update the documentation. 2020-06-15 14:17:19 +08:00
Sunli
1b8de3b433 Remove connection::DataSource 2020-06-15 12:06:15 +08:00
Bryan Burgers
e21f2e6316 Allow vars to be missing when def is nullable
Allow variables to be missing when the associated variable definition is
nullable (in which case we use `null` as the default).

This fixes queries like

```graphql
query Test($var: Int) {
    test(var: $var)
}
```

```json
{}
```

which appear to be allowed according to the GraphQL spec.
2020-06-11 10:00:47 -05:00
Sunli
82eefd67fd Add GQLEnum, GQLInputObject, GQLSimpleObject macros. #164
use `proc_macro_derive` to solve the problem that Enum, InputObject, and SimpleObject do not support the #cfg attribute.
2020-06-11 11:23:23 +08:00
Sunli
edec696610 Add tests for feature attribute 2020-06-06 11:49:29 +08:00
Sunli
96f7d38c8a Update PostGuard tests 2020-06-03 16:56:15 +08:00
Sunli
746544412b Add PostGuard. #129 2020-06-03 14:50:06 +08:00
Sunli
2452a44484 Add connection::query function 2020-06-02 17:43:13 +08:00
Kevin Schoonover
9b114cf616 Add input validator tests + fix clippy errors 2020-06-01 16:42:13 -05:00
Sunli
267620d08e Fix incorrect variable substitution. #126 2020-05-31 11:54:07 +08:00
Sunli
9a97ac443f Update connection tests 2020-05-29 11:12:43 +08:00
Sunli
6cc92458e1 Add Connection::try_append and Connection::try_append_stream 2020-05-29 09:24:31 +08:00