Commit Graph

340 Commits

Author SHA1 Message Date
Miaxos
3f227217ae feat: add derived on simple objects 2021-10-25 10:56:33 +00:00
Miaxos
02009c401b feat: add derived field for complex object 2021-10-22 13:08:49 +00:00
smihica
7d9de1c0f8 Supported CharsMinLength and CharsMaxLength to count chars 2021-10-14 00:43:14 +09:00
smihica
4c3e5905a7 Revert "Supported multibyte string in StringMinLength and StringMaxLength to count chars, not byte len."
This reverts commit b4116cdcaa.
2021-10-14 00:33:20 +09:00
smihica
b4116cdcaa Supported multibyte string in StringMinLength and StringMaxLength to count chars, not byte len. 2021-10-13 15:16:32 +09:00
Sunli
9e69b40987 Add concrete names support for Object macro. #633 2021-09-24 21:00:17 +08:00
Sunli
d724507458 Implement GraphQL enum to Value conversion. #617 2021-09-17 09:02:09 +08:00
Sunli
243e1d323a Add support for graphql-ws pings. #635 2021-09-16 21:10:39 +08:00
Miaxos
4e86d9f17c fix: add test case for serializing issue 2021-08-18 14:22:17 +00:00
Sunli
c4cfa24e41 Clippy clean 2021-07-31 23:54:16 +08:00
Sunli
28d22dbe32 Add support for the list operator to the input value validator. #579 2021-07-20 15:16:34 +08:00
Sunli
1468cc91bb Implemented OutputType for Bytes. #569 2021-07-18 21:42:39 +08:00
Yin Jifeng
580a593fa0 Allow field visible to support paths 2021-07-18 20:16:39 +08:00
Sunli
d116dc2950 Make Schema::execute return HTTP headers when an error occurs. #572 2021-07-16 07:47:43 +08:00
Sunli
80da563b24 Update guard test 2021-07-15 08:09:29 +08:00
Rodgers
abb59b9e3f Add test for is_valid_with_extensions 2021-07-08 22:06:13 +07:00
Sunli
afecc99085 Add concrete type support for complex object. 2021-07-04 14:05:08 +08:00
Julien Nicoulaud
32d75ec4c9
#550: add unit test for generic Object/Simple/ComplexObject 2021-07-03 18:00:16 +02:00
Sunli
7cb30db2f2 Fix the bug that MergedObject may cause panic. #539 2021-06-21 09:48:19 +08:00
Sunli
f5e3329e86 Implement InputType and OutputType for [T; N] array. 2021-06-17 10:39:27 +08:00
Sunli
19669c11f0 Add serial attribute for MergedObject macro. #539 2021-06-16 15:08:33 +08:00
Sunli
eecf709a2c Add serial attribute for SimpleObject and Object macros. #539 2021-06-15 08:53:26 +08:00
Sunli
8888897c51 Add the operation_name to Extension::execute method. 2021-06-10 10:17:33 +08:00
Sunli
4c98ad2c92 Allow field guards to support paths. #536 2021-06-08 19:42:53 +08:00
Sunli
6dcb15c945 Update test 2021-06-08 19:04:06 +08:00
Sunli
553bf37abe Rework error propagation. #531 2021-06-08 10:05:30 +08:00
Sunli
e86e642d5a Update tests 2021-06-07 14:12:28 +08:00
Sunli
dfe8245894 Add support for returning multiple resolver errors. #531 2021-06-07 14:03:36 +08:00
Sunli
cdd13ea1be Fix the problem that the ComplexObject macro cannot work due to the secret attribute. 2021-04-23 10:25:00 +08:00
Sunli
5831449e07 Add test for drop subscription stream on unsubscribe. 2021-04-13 11:26:55 +08:00
Sunli
5d6b870969 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
22a5e71215 Improve Extensions. 2021-04-05 12:21:02 +08:00
Sunli
7000651b88 Rework Extension 2021-04-04 14:37:41 +08:00
Sunli
f62843cbd3 Add Request::disable_introspection method. #456 2021-03-30 11:59:57 +08:00
Sunli
cc937b70b5 Rework Extension & TracingExtension & OpenTelemetryExtension 2021-03-26 12:03:10 +08:00
Sunli
e991ffb814 Fix internal context missing when there's no connection_init frame. #451 2021-03-24 17:24:12 +08:00
Sunli
bec0fc18a9 Add ComplexObject macro. #355 2021-03-18 10:13:46 +08:00
Sunli
5c644de219 Switch the async runtime used for testing to Tokio. 2021-03-12 12:47:24 +08:00
Taiki Endo
6ddbc52641 Support generics in Subscription types 2021-03-09 22:21:56 +09:00
Sunli
1e6ae23cd8 Add test for Federation entity lookup with DataLoader. 2021-03-06 08:21:44 +08:00
Sunli
69341df41e Moved Variables from async_graphql::context::Variables to
`async_graphql::Variables`.
2021-02-28 09:37:42 +08:00
Sunli
baa837f2ca Allow the deprecation attribute to have no reason. 2021-02-27 11:59:58 +08:00
Sunli
1dd3c7589f Clippy clean 2021-02-26 20:05:09 +08:00
Sunli
14a88cfa19 Add support for Federation nested keys. 2021-02-21 23:06:26 +08:00
Sunli
550ecd9660 Fixed GraphQL over WebSocket Protocol does not support ConnectionError events. #406 2021-02-06 11:02:41 +08:00
Sunli
43a8ad6859 Supports async websocket initializer. #393 2021-01-16 16:37:20 +08:00
Sunli
a0ded06da8 Fix a bug that cause generic InputObject and SimpleObject is incorrect name. #387 2021-01-14 19:20:28 +08:00
Sunli
7bda6333da Add support for generic SimpleObject. #387 2021-01-14 13:16:30 +08:00
Sunli
95e372e0d3 Add Send + Sync constraints for InputType, OutputType and SubscriptionType. 2021-01-14 12:41:59 +08:00
Sunli
ac620c1eea Add support for generic InputObject. #387 2021-01-14 11:27:15 +08:00
Sunli
4d6fd5b539 Clippy clean 2021-01-11 09:01:28 +08:00
Sunli
20e5732525 Implements InputType for Box<T> and Arc<T>. #382 2021-01-10 13:48:18 +08:00
Sunli
c8f5e3de36 Fix #[Object] macro panic with default u32. #361 2020-12-28 18:39:17 +08:00
Aaron Hill
cea22da228
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
ec82e64a39 Improve depth and complex. 2020-12-18 18:56:28 +08:00
Sunli
8979620181 Remove async-channel and async-mutex from dependencies. 2020-12-17 10:05:32 +08:00
Sunli
f59c287ba0 Add the skip attribute to the InputObject fields. 2020-12-15 20:29:59 +08:00
Sunli
e29b7a3627 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
7796b8c248 Add tests for graphql-ws. 2020-12-04 16:44:48 +08:00
Sunli
30dffdd47f Merge branch 'master' into pr/350 2020-12-04 12:17:23 +08:00
Sunli
c9790087c5 Add websocket subprotocol for actix-web. 2020-12-04 12:13:52 +08:00
Sunli
1e21e29fd9 Fix the problem that the fields of the list are not merged correctly.#345 2020-11-27 10:26:23 +08:00
Sunli
778c950f47 Fix async_graphql::Object does not work when inside macro after rust 1.48.0 2020-11-22 09:53:18 +08:00
Sunli
cc793e080a Merge branch 'master' of github.com:async-graphql/async-graphql 2020-11-04 10:26:04 +08:00
Sunli
599b5f1c47 Fix the problem that Description derived macro do not support generic objects. 2020-11-04 10:25:30 +08:00
Sunli
7c62b10ebc Fix #333 2020-11-03 18:16:55 +08:00
Sunli
89ab0c799f Fix the problem of scalar macro. 2020-11-03 13:50:22 +08:00
Sunli
d4e26192ce Fix interface downcasting. #330 2020-10-31 08:58:54 +08:00
Sunli
a43432d530 Add test for SchemaBuilder::override_description. #327 2020-10-27 20:47:24 +08:00
Sunli
770ed31508 Add use_type_description attribute for derive macros Object, Scalar and Subscription. 2020-10-26 21:34:05 +08:00
Sunli
fc35787885 Add interface to implement another interface. #322 2020-10-24 09:08:18 +08:00
Sunli
8edd59ffdb 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
776aadf169 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
7510741311 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
807bad2a72 Fix macro hygiene 2020-10-16 20:21:46 +01:00
Koxiaet
68381cfc65 Make macros hygienic 2020-10-16 11:37:59 +01:00
Koxiaet
db312a372d Replace futures with futures_util 2020-10-16 07:49:22 +01:00
Sunli
b054f1bf9f Fix can no longer derive Union for union types with lifetimes. #311 2020-10-15 08:53:17 +08:00
Sunli
bc5cf2f2a2 Configurable case conversion. 2020-10-14 19:16:10 +08:00
Sunli
53ef84c5e3 Fix a bug in the validator. 2020-10-14 10:54:46 +08:00
Sunli
b1ecc6b8a9 2.0.1 2020-10-14 10:25:41 +08:00
Sunli
184f8b169d Update docs 2020-10-13 10:19:30 +08:00
Sunli
b0ceb58163 Use value! instead of serde_json::json!. 2020-10-12 10:17:05 +08:00
Sunli
2ca10e0ded Add parse_value and from_value funcntions. 2020-10-11 20:24:31 +08:00
Sunli
10cd868f4c Some improvements. 2020-10-10 16:28:07 +08:00
AurelienFT
e7b4ad8f2f
Rework guard (#296)
Rework guard #293
2020-10-06 17:16:51 +08:00
Sunli
e263c755e2 Restore the original error extension implementation. 2020-10-02 14:56:10 +08:00
Koxiaet
b61088089b Fix compilation and tests 2020-09-30 19:40:17 +01:00
Koxiaet
ab82460b81 Merge master 2020-09-30 18:24:24 +01:00
Koxiaet
2ddaaaa07f 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
8c5d8f0324 Rework async-graphql-derive. #288 2020-09-29 16:06:10 +08:00
Sunli
c460431715 Add feature to flatten nested GraphQL unions. #286 2020-09-28 11:13:46 +08:00
Sunli
2fc4750122 Add remote attribute for Enum macro. #276 2020-09-27 18:19:11 +08:00
Sunli
9b4fc7d922 Make Object and Subscription macros support #cfg(...) attribute. #281 2020-09-27 10:20:20 +08:00
Sunli
9333583483 Improve the error message of Tracing extension. 2020-09-26 12:35:28 +08:00
Sunli
897a3b9bb0 Add test code for generic object. #274 2020-09-23 14:39:18 +08:00
Sunli
5bfb992ad7 Fix enum strings in query variables are not converted to proper enums. #270 2020-09-20 13:28:18 +08:00
Sunli
322e296a24 Remove the GQL prefix of all macros. #208 2020-09-18 09:10:24 +08:00
Koxiaet
5cf527aeef Merge branch 'master' of github.com-koxiaet:async-graphql/async-graphql into master 2020-09-17 19:23:15 +01:00
Koxiaet
88be6bca61 Improve websockets 2020-09-17 19:22:54 +01:00
Sunli
acc1a6f515 Add support for batch queries. 2020-09-17 19:54:12 +08:00
Sunli
c3d70b0553 Add test for ErrorExtensions. 2020-09-17 08:47:41 +08:00
Sunli
509c92a11f Move http::websocket::create and http::websocket::create_with_initializer function to http::WebSocketStream. 2020-09-15 20:07:59 +08:00
Sunli
059128e9c5 http::websocket::create function now returns the WebSocketStream type. 2020-09-15 11:19:00 +08:00
Sunli
3233f3638c 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
d67a511a07 2.0.0-alpha.5 2020-09-14 09:46:22 +08:00
Koxiaet
d404e756bc 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
863d57a4b0 Remove SimpleBroker 2020-09-13 10:47:28 +01:00
Koxiaet
55753983a9 Move websockets to http module and fix doc tests 2020-09-13 07:40:34 +01:00
Sunli
f530d01bf4 Remove all attribute macros that can be replaced by derive. 2020-09-13 11:41:15 +08:00
Koxiaet
8796c5e1a7 Replace http::GQLRequest with Request 2020-09-12 17:07:46 +01:00
Koxiaet
1aa36819eb Create resolver_utils 2020-09-12 10:29:52 +01:00
Sunli
a93b91ae2d Re-enable the test on websocket. 2020-09-11 16:41:56 +08:00
Sunli
3e01ef0be7 Fix tests 2020-09-11 16:05:21 +08:00
Sunli
faac753096 Add transports::websocket module. 2020-09-11 15:54:56 +08:00
Sunli
553e6ffd53 Remove unnecessary Result on Schema::execute_stream function. 2020-09-11 10:47:55 +08:00
Sunli
c88747dfe4 Make all tests passed (async-graphql). 2020-09-10 19:35:48 +08:00
Sunli
7a90069cad Continue to refactor. 2020-09-10 16:39:43 +08:00
Koxiaet
c42aa55625 Rustfmt 2020-09-08 09:30:29 +01:00
Koxiaet
ed5acdcf18 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
9ad4e8c1a8
Merge branch 'master' into master 2020-09-06 07:20:18 +01:00
Koxiaet
3bf5f3a16c Rustfmt 2020-09-06 07:16:36 +01:00
Koxiaet
e3e58d261d Rewrite async-graphql-parser 2020-09-06 06:38:31 +01:00
Sunli
f87435b96c Add test for multiple flatten attribute of InputObject. 2020-09-04 14:14:48 +08:00
Sunli
366c7c03da Add flatten type field support for input objects. #255 2020-09-03 20:00:33 +08:00
Sunli
d04b5b675f Fix the test code and add docs. 2020-09-01 09:10:12 +08:00
Koxiaet
945cd72869 Remove dependency on serde_derive, satisfy Clippy, improve docs 2020-08-31 19:18:02 +01:00
Sunli
80b2ff00c5 Implements Default for Schema. 2020-08-28 14:19:35 +08:00
Sunli
7fef4e3dca Merge subscriptions #243 2020-08-27 15:35:48 +08:00
Sunli
01e3e85684 Add support for mut field args. 2020-08-17 21:48:53 +08:00
Sunli
fe336dd4d0 Fix send data with 'complete' WebSocket message. #238 2020-08-14 15:21:10 +08:00
Sunli
db8eef875c Update test for MergedObject. 2020-08-11 09:37:33 +08:00
Sunli
d280a13b70 Add derive macro GQLMergeObject. #231 2020-08-10 14:11:46 +08:00
Sunli
d7248e149f Add Default impl for MergedObject. #231 2020-08-10 10:47:30 +08:00
Sunli
dd7c64fc7a Add MergedObject type. #231 2020-08-09 15:03:10 +08:00
Sunli
a193a8e51a Add directive @ifdef 2020-08-06 14:52:54 +08:00
Sunli
b67278eeec Add support for query execution over websocket. 2020-07-31 11:30:57 +08:00
Sunli
3d7594bac1 Removes code about streaming requests. 2020-07-31 10:10:03 +08:00
Sunli
3395c00603 Replace Value::Int and Value::Float with Value::Number. 2020-07-29 09:42:52 +08:00
Sunli
8992b681dc Fix input validator is ignored when using variable #207 2020-07-11 10:05:30 +08:00
Sunli
9510160432 Add OutputJson type #203 2020-07-08 14:44:57 +08:00
Blaine Bublitz
6ed3909a9a Use FieldResult for data(), add data_unchecked() for panic 2020-07-06 17:39:53 -07:00
Sunli
98e431fed0 Correct handling of raw identifiers #195 2020-07-02 10:25:20 +08:00
Blaine Bublitz
1c861ee80b Fix issue with unwrapping derive attributes 2020-06-25 13:54:13 -07:00
Sunli
c8409e1a00 Remove ref attribute for SimpleObject fields, and add owned attribute. 2020-06-23 14:42:57 +08:00
Sunli
cda4498979 Remove all datasource-related code and update the documentation. 2020-06-15 14:17:19 +08:00
Sunli
c05127bb3e Remove connection::DataSource 2020-06-15 12:06:15 +08:00
Bryan Burgers
81c7683e4d 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
b605846822 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
f59d9f080f Add tests for feature attribute 2020-06-06 11:49:29 +08:00