* Make the executor and validation APIs public to enable splitting parsing and execution into two stages
Based on https://github.com/graphql-rust/juniper/pull/773#issuecomment-703783048 and https://github.com/graphql-rust/juniper/pull/773#issuecomment-704009918
* Fix fmt warning for visit_all_rules
* Add `Definition` to the public API so it's available for the result of compilation
* Make OperationType public so that user land code can tell the difference between query/mutation and subscription
* Add integrations tests for execute_validated_query_async, visit_all_rules, get_operation, and resolve_validated_subscription
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
* Resolves#818. Updates Object key_value_list to use HashMap<String, Value<S>>. Updates test cases.
* Updates to use IndexMap. Reverts changes to test cases.
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
* Use working GraphQL Playground version
the linked file on jsDelivr doesn't work, as I detailed in this issue on the GraphQL Playground repo (https://github.com/graphql/graphql-playground/issues/1310). Going back to version 1.7.20 ensures the playground loads for now until they can publish a new version with a working middleware.js file.
* Add versions for css and favicon
* Update from 1.7.20 to 1.7.26
Using latest version that still works
Some crates need to rewrite values when they are released in other crates. It turns out, by default we use a general config _build/release.toml. So it turns out these local-to-the-crate release.tomls were not being used unless explicitly chosen in the local-to-the-crate Makefile.toml. This removes the dead release.tomls and overrides the ones that need to edit other crates on release.
* Mark `Arc` with `IsInputType` & `IsOutputType`.
We've just updated a service we work with to the latest release of
juniper (it's been on a fairly old master commit for some time). In
this service we have some fields that are contained within `Arc`s, which
I added support for in #479.
Since then it seems the new marker traits of `IsInputType` &
`IsOutputType` have been added, but they do not support `Arc`, leading
to:
```
error[E0277]: the trait bound `Arc<menu::Menu>: IsOutputType<__S>` is not satisfied
--> src/graphql.rs:36:1
|
36 | #[juniper::graphql_object(Context=Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IsOutputType<__S>` is not implemented for `Arc<menu::Menu>`
|
= note: required by `juniper::marker::IsOutputType::mark`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
```
This commit adds support for those, mirroring the support for `Box`.
I'm not sure if there's a good place to add a test for this
functionality so that regressions can be avoided in the future?
* Add Arc tests & FromInputValue for Arc<T>
- add associated type to IntoResolvable and IntoFieldResult traits allowing to name the GraphQLType being resolved
- relax Sized requirement on some IsInputType and IsOutputType impls
* Actix subscriptions tests
* Use LocalBoxFuture instead of async-trait
* expose-test-schema already includes serde_json
* Add anyhow to juniper dev-dependencies
* The HTTP test helpers are not needed for juniper tests
* juniper_actix does not need tokio in dev-dependencies
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
* Impl subscriptions for juniper_actix
* Add random_human example subscription
* Add actix_subscriptions example to CI
* fixup! Add random_human example subscription
* Migrate actix subscriptions to juniper_graphql_ws
* Simplify error handling
* Change unwrap to expect
* Close connection on server serialization error
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
* Update compile fail tests for latest Rust
The messages appear to have changed on nightly
* Fix tests depending on fixture data
* Fix more integration test paths
* Fix doc warnings
- generate always `::juniper::` crate path in proc macros and use `extern crate self` to make it work inside `juniper`
- add optional non-documented `internal` proc macro argument to proc macros, which allows double-underscored names and is used inside `juniper` only
- add object safe GraphQLValue, GraphQLValueAsync and GraphQLSubscriptionValue traits containing methods for value resolution
- refactor GraphQLType, GraphQLTypeAsync and GraphQLSubscriptionType traits to register and provide GraphQL type information only
- make GraphQLUnion trait generic over ScalarValue
- generate generic over ScalarValue impls of GraphQLUnion trait
- add codegen tests with a custom ScalarValue for union macros
- reimplement #[derive(GraphQLUnion)] macro to support:
- both structs and enums
- generics in type definition
- multiple #[graphql] attributes
- external resolver functions
- remove From trait impls generation for enum variants
- reimplement #[graphql_union] macro to support:
- traits
- generics in trait definition
- multiple attributes
- external resolver functions
- GraphQLType implemetation for a raw trait object
- GraphQLTypeAsync implemetation (#549)
- add marker::GraphQLUnion trait
- rewrite "2.5 Unions" section in Book (Juniper user documentation)
- rewrite `codegen` and `codegen_fail` integration tests for GraphQL unions
Additionally:
- re-export `futures` crate in `juniper` for convenient reuse in the generated code without requiring library user to provide `futures` crate by himself (#663)
- use unit type () as default context for EmptyMutation and EmptySubscriptions
- relax Sized trait bound on some GraphQLType and GraphQLTypeAsync definitions, implementations and usages
* Relax Default impl constraint
For EmptyMutation and EmptySubscription. The built-in derive
expects `T: Default`, which is not necessary for a PhantomData
wrapper.
* Add test
* Improve lookahead visibility for aliased fields
- Add a method to access the children of look ahead structs
- Make the behaviour around accessing aliased lookahead fields more consistent
* Deprecate old Lookahead methods for accessing child selections
* Support 'application/graphql' POST requests for 'juniper_warp'
* Add integration tests for 'application/graphql' POST requests and revive HttpIntegration test suite for 'juniper_warp'
* Support 'application/graphql' POST requests for 'juniper_hyper' and run its tests for both sync and async versions
* Run integration tests for both sync and async versions of 'juniper_warp' and update its CHANGELOG
* Support 'application/graphql' POST requests for 'juniper_iron'
* Fix 'application/graphql' POST requests support for 'juniper_actix'
* Support 'application/graphql' POST requests in 'juniper_rocket' and 'juniper_rocket_async'
* Upd juniper's CHANGELOG
* Implemented most test cases from the specification
* Unified error handling for all generators
- Removed proc-macro-error -> not required -> use syn::Error
- Everything below lib.rs uses proc_macro2::TokenStream
instead of proc_macro::TokenStream
- Replaced error handling in attribute parsers
* WIP better error messages for *all* macros
* Refactored GraphQLInputObject and minor tweaks
- removed support for Scalar within a string ("DefaultScalarValue")
- removed unraw function and replaced it with the built-in one
- added error messages and return types for all functions within utils
- added more constraints to fulfill the GraphQL spec
* Fixed test-cases which are not compliant with the specification
* Removed unused function
* Added constrains, updated error messages, added marker
* Added argument rename within impl_graphql and fixed `__` tests
* Formatted and cleanup
* Added GraphQLTypeAsync for input object
* Moved codegen tests to separate module
Nightly and stable produce different outputs, thus only test nightly.
* Added IsInputType/IsOutputType traits for type checking
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
Without this fix the panic looks like the following:
```rust
---- parser::tests::lexer::string_errors stdout ----
thread 'parser::tests::lexer::string_errors' panicked at 'byte index 4 is not a char boundary; it is inside 'ɠ' (bytes 3..5) of `"\uɠ^A`', src/libcore/str/mod.rs:2219:5
```
This was found via fuzzing with `cargo-fuzz`.
Fixes#571
Signed-off-by: andrisak <andrisak@gmail.com>
* Replaced the old macro with the new proc macro.
Updated documentation.
Signed-off-by: andrisak <andrisak@gmail.com>
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
* Updated implementation of derive enum
- allows context specification
- allows scalar specification
- shares code with derive object
* Added this feature to CHANGELOG
* Added matrix with supported macro attributes for enums
* Added case which checks for custom context
* GraphQLUnion now can use a different context per variant
* Moved context switch test for union into right folder
* Sync resolve expression has the same form as the other impls
* Disabled custom scalar on GraphQLEnum
* Fixed CHANGELOG
* Fixed support matrix of GraphQLEnum in the book
- scalar not supported!
- skip not supported!
* Added test case for "noasync" derive attribute
* Disallowed generics and lifetimes on GraphQLEnum
* Added error message for duplicate naming
* Added error message for empty variant
* Implemented device macro for GraphQLUnion's
* Updated PR link in CHNAGELOG
* Disabled documentation on enumeration fields
* Disabled skip on fields
* Changed implementation for std::convert::Into since skip is not possible
* Added documentation for GraphQLUnion
* Added tests for GraphQLUnion
* Fixed typos in error messages (as suggested by review)
* Fixed failing documentation example
* Utilized `resolver_code` in `util::GraphQLTypeDefinitionField`.
Simplifies code and provides the idea of using
`util::GraphQLTypeDefinitionField` for different types than objects.
* Removed wrong statement about skip annotation in docs.
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
* Add subscriptions support on GraphiQL
Addresses #501
BREAKING CHANGE: `juniper::http::graphiql::graphiql_source` now requires
a second parameter
BREAKING CHANGE: `juniper_hyper::graphiql` now requires
a second parameter
BREAKING CHANGE: `juniper_iron::GraphiQLHandler::new` now requires
a second parameter
BREAKING CHANGE: `juniper_rocket::graphiql_source` now requires
a second parameter
BREAKING CHANGE: `juniper_warp::graphiql_filter` now requires
a second parameter
* Add test where graphiql subscriptions endpoint is not None
I noticed that `juniper` fails to build if the `"expose-test-schema"` feature is enabled without also enabling `"serde_json"`. I guess it might make sense to add it as a dependency so people don't have to check this file to figure that out!
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
* Implement `std::error::Error` for all error types
* Fix copy-paste
* Implement `Display` for `Value`
This is required for implementing `Display` for `FieldError`
* Implement `std::error::Error` for `FieldError`
This required removing `impl From<T> for FieldError where T: Display`
because it would otherwise cause a conflicting implementation. That is
because `impl From<T> for T` already exists.
Instead I added `impl From<String> for FieldError` and `impl From<&str>
for FieldError` which should cover most use cases of the previous
`impl`. I also added `FieldError::from_error` so users can convert
from any error they may have.
* Bring back `impl<T: Display, S> From<T> for FieldError<S>`
We cannot have this and `impl<S> std::error::Error for FieldError<S>` so
we agreed this is more valuable. More context https://github.com/graphql-rust/juniper/pull/419
* Write errors without allocations
there is still some weirdness going on. Running async and
non-async tests in `integration_tests/*` works, but running it
from `integration_tests` does not.
* Validate variables of the executed operation only
* Use `unreachable!` in `validate_var_defs`.
Use `unreachable!` instead of `panic!` on invalid variable types,
since thay have already been checked during document validation.
* Fix formatting in `validation/input_value.rs`
The `uuid` maintainers have started releasing in the `0.8` version train. I've relaxed the version requirements on `juniper`'s dependencies to allow juniper users to specify a different version in their `Cargo.toml` and still have the integration work.
* Implement GraphQLTypeAsync for Arc
I'm building a GraphQL API using Juniper that proxies another GraphQL
API. It does a large fetch upfront from the underlying GraphQL API,
transforms it into a different format and then implements some
resolvers that do some further filtering.
One of these resolvers ends up looking like:
```
async fn items(&self, ...) -> Vec<Item> {
self.items.iter().filter(...).collect()
}
```
This causes us problems as we're returning owned Item's and Item is a
large nested structure that would be expensive to clone.
Our current work around was to put Item into an Arc, as Arc is
comparatively cheap to clone. So our method becomes:
```
async fn items(&self, ...) -> Vec<Arc<Item>> {
self.items.iter().filter(...).map(Arc::clone).collect()
}
```
However to support this we needed Arc to implement GraphQLTypeAsync.
This commit adds that support to juniper, by forwarding to the
GraphQLTypeAsync implementation for the contained type.
It's possible that we could have acheived something similar by adding
some lifetimes to our resolver and returning a reference, but using an
Arc was easier for us in this case. I'm not sure if there's any reason
why this would be a bad addition to Juniper overall?
* Move GraphQLTypeAsync for Arc<T> into pointers.rs
* Validate variables of the executed operation only
* Use `unreachable!` in `validate_var_defs`.
Use `unreachable!` instead of `panic!` on invalid variable types,
since thay have already been checked during document validation.
* Fix formatting in `validation/input_value.rs`
The `uuid` maintainers have started releasing in the `0.8` version train. I've relaxed the version requirements on `juniper`'s dependencies to allow juniper users to specify a different version in their `Cargo.toml` and still have the integration work.
The trait was introduced while introducing generic scalars, but is not
actually required or useful. It's functionality is fully covered by
methods on the `ScalarValue` trait.
It also forced a lof of for<'a> ScalarRefValue bounds all over the code,
complicating signatures a lot.
It is completely removed now.
* feat: Raw identifier support in object macro
This commit implements raw identifier (`r#name`) support
for field names (methods) and arguments in the `object` proc macro.
Eg:
```rust
impl T {
fn r#type(r#trait: String) -> bool {}
}
```
* Rebase onto master
* Fix merge [skip ci]
This commit implements raw identifier (`r#name`) support
for field names (methods) and arguments in the `object` proc macro.
Eg:
```rust
impl T {
fn r#type(r#trait: String) -> bool {}
}
```