Commit graph

102 commits

Author SHA1 Message Date
ilslv
d0b56f9222
Implement #[derive(GraphQLInterface)] to use structs as GraphQL interfaces (#1026)
- support `#[graphql_interface]` on structs
2022-04-01 21:10:45 +03:00
ilslv
5bbc73ad89
Redesign #[derive(ScalarValue)] macro to derive ScalarValue on enums (#1025) 2022-03-03 15:49:35 +02:00
ilslv
0ebd19af5a
Redesign #[derive(GraphQLScalar)] and #[graphql_scalar] macros (#1017)
- `#[derive(GraphQLScalar)]`:
    - support generic scalars
    - support structs with single named field
    - support for overriding resolvers
- `#[graphql_scalar]`:
    - support `transparent` argument

Co-authored-by: Kai Ren <tyranron@gmail.com>
2022-02-28 11:34:38 +02:00
ilslv
63198cdfcb
Redesign #[graphql_scalar] macro (#1014, #1000)
- support generic scalars
- make it applicable to type aliases and struct/enums/unions
2022-02-24 17:12:17 +02:00
ilslv
1aa1000c3b
Redesign #[graphql_interface] macro (#1009, #1000, #814)
- remove support for `#[graphql_interface(dyn)]`
- describe all interface trait methods with type's fields or impl block instead of `#[graphql_interface]` attribute on `impl Trait`
- forbid default impls on non-skipped trait methods
- support additional nullable arguments on implementer
- support returning sub-type on implementer
2022-01-26 20:58:53 +02:00
ilslv
f504da6d15
Fix juniper_codegen_tests assertions (#1007) 2021-12-20 14:50:49 +02:00
ilslv
847d09fb5e
Support @specifiedBy(url: "...") directive via specified_by_url attribute argument in #[graphql_scalar] and #[derive(GraphQLScalarValue)] macros (#1003, #1000)
- support `isRepeatable` field on directives
- support `__Schema.description`, `__Type.specifiedByURL` and `__Directive.isRepeatable` fields in introspection
2021-12-20 13:36:27 +02:00
Kai Ren
46be97ada4
Refactor FromInputValue to return Result instead of Option (#987)
- propagate `FromInputValue` conversion errors during validation
- replace panics with errors during resolving

Co-authored-by: ilslv <ilya.solovyiov@gmail.com>
2021-12-14 19:30:27 +02:00
ilslv
e264cf509d
Forbid __typename on subscription root (#1001, #1000) 2021-12-13 14:27:14 +02:00
Kai Ren
acde85a814
Implement graphql_input_value! and graphql_vars! macros (#996, #503)
- add `From` impls to `InputValue` mirroring `Value` impls to provide better support for `Option` handling
- support expressions in `graphql_value!` macro
- use `null` in addition to `None` to create `Value::Null` in `graphql_value!` macro to mirror `serde_json::json!`
- use macros for `InputValue` and `Variables` construction in tests

Co-authored-by: Ilya Solovyiov <ilya.solovyiov@gmail.com>
2021-11-26 18:53:56 +02:00
Kai Ren
f66296d618
Replace ScalarValue::Visitor with DeserializeOwned requirement (#985)
- remove `Serialize` impl from `#[derive(GraphQLScalarValue)]` macro expansion
2021-10-11 21:53:04 +03:00
nickelc
b9257ef7d4
Fix Clippy warnings (#980) 2021-09-12 20:38:41 +03:00
tyranron
74afe4c04a
Use graphql_value!() macro in tests asap 2021-08-13 02:12:01 +03:00
Kai Ren
a3fda7363d
Rework codegen for GraphQL objects and subscriptions (#971, #421)
- preserve and reuse defined impl blocks in #[graphql_object] and #[graphql_subscription] macros expansion
- allow renaming `ScalarValue` type parameter in expanded code via `scalar = S: ScalarValue` syntax

Additionally:
- rename `rename` attribute's argument to `rename_all`
- support `rename_all` in #[graphql_interface] macro
2021-08-11 17:41:49 +03:00
Kai Ren
39d1e43420
Allow using Rust arrays as GraphQL lists (#918) (#966)
* Provide impls for arrays

* Remove redundant Default bound

* Recheck other places of mem::transmute usage

* Fix missing marker impls

* Extend GraphQL list validation with optional expected size

* Improve input object codegen

* Cover arrays with tests

* Add CHANGELOG entry

* Consider panic safety in FromInputValue implementation for array

* Tune up codegen failure tests
2021-07-23 14:51:47 -10:00
tyranron
8a90f867d4
Expose GraphQLRequest fields (#750) 2021-07-21 20:45:01 +03:00
tyranron
d211f4a8ef
Ensure operation roots resolve their __typename (#372) 2021-07-21 19:14:13 +03:00
tyranron
ad64025572
Strip redundant fields in codegen producing warnings 2021-07-21 18:16:29 +03:00
Kai Ren
7597523720
Allow spreading interface fragments on unions and other interfaces (#965, #798) 2021-07-19 14:06:47 +03:00
Jordão Rodrigues Oliveira Rosario
739cc3bfc2
Upgraded tokio, warp, hyper and actix (#912)
* Upgraded tokio, warp, hyper and actix

* Code formatting

* actix-web temporary version fix specification

* Error handling fix on juniper_rocket

Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2021-06-28 20:22:45 -10:00
Idan Mintz
d4fda786ba
Fixes panic when spreading untyped union fragment. (#946)
* Fixes panic when spreading untyped union fragment.

closes #945

* Fix ci breakage with explicit lifetime annotation in juniper_rocket_async
2021-06-14 00:52:41 -07:00
Christian Legnitto
84a07c4a93
Re-record fixtures for latest nightly error messages (#941) 2021-06-06 15:57:14 -07:00
ihor-rud
d3896bd33c
Fix using graphql_scalar proc macro inside a macro (#933) 2021-06-06 15:05:53 -07:00
xDarksome
f04434416b
Fix subscription error extensions (#927) 2021-05-11 10:43:52 +03:00
ArsileLuci
dc99ae70b8
Fix fields on interface not being resolved when used with fragments (#923, #922) 2021-04-30 15:13:54 +03:00
tyranron
106e322f68
Catch up codegen failure tests with latest nightly Rust 2021-04-29 14:06:32 +03:00
Tilman Roeder
5ae930bfc7
Fixes Issue 914 (#915)
* Add failing tests

* Fix failing test

* cargo fmt
2021-04-17 13:29:08 -10:00
Jerel Unruh
c78045c167
Make the executor and validation APIs public to enable split parsing and execution (#874)
* 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>
2021-04-02 19:13:06 -10:00
Tilman Roeder
e7f7e7bff3
Fragment spreads in Interface types (#907)
* Add failing test

* Fix fragment spread on interface

* Cargo fmt

* Add test and fix for sync version

* Cargo fmt
2021-04-02 09:34:52 -10:00
abrackx
f5ce9f2d79
Switch to HashMap for the internal representation of object fields (#872)
* 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>
2021-02-28 18:10:53 -10:00
Kai Ren
4682fe2f4e
Add missing marker trait impls for container types (#847) 2021-01-15 07:31:50 -10:00
Graeme Coupar
fe86dbb782
Mark Arc with IsInputType & IsOutputType. (#822)
* 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>
2020-12-11 16:30:41 -10:00
Zak
4ffd276a5b
Allow raw identifier for field arguments in #[graphql_object] macro (#812, #786) 2020-11-26 12:46:06 +02:00
Jonas Meurer
cb6d89f4c7
Allow different Scalar for GraphQLScalarValue (#807)
* allow setting scalar in macro

* rustfmt

* added changes to changelog

* added test cases
2020-11-15 17:15:55 -10:00
Kai Ren
3472fe6d10
Fix attributes naming on fields and arguments for interfaces and unions (#806)
Additionally:
- revive macros/tests/object
- revive executor_tests/interfaces_unions
2020-11-14 15:41:01 +02:00
Kai Ren
a4871887bb
Default to generic ScalarValue in #[graphql_object] macro (#779)
* Change codegen ScalarValue defaults for #[graphql_object] macro

* Fix integration tests

* Fix codegen failure tests

* Fix 'juniper' crate tests

* Fix integration crates tests

* Fix 'juniper_benchmarks' crate

* Fix examples

* Fix Book

* Fix

* Add CHANGELOG entry

* Some Book corrections

* Fix

* Bootstrap coercion machinery

* Reimpl coercion

* Correct tests, vol.1

* Correct tests, vol.2

* Correct tests, vol.3

* Correct tests, vol.4

* Correct tests, vol.5

* Fix coercion for subscriptions

* README fixes

Co-authored-by: Christian Legnitto <christian@legnitto.com>
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-11-06 18:15:18 -08:00
Lucas Pickering
200896053a
Fix #500 (crash from look_ahead on nested fragments) (#800) 2020-11-04 15:11:25 -08:00
David Pedersen
eca049ac28
Implement IntoFieldError for Infallible (#796)
Makes it possible to use `Result<T, Infallible>` as your return type
from resolvers, which can be handy sometimes.
2020-10-29 06:39:59 -07:00
Chris
cd66bdb450
Add ability to distinguish between implicit and explicit null (#795)
* add Nullable to distinguish between implicit and explicit null

* cargo fmt

* add page to book

* address comment
2020-10-23 19:21:37 -04:00
tyranron
61d1365b15
Test GraphQL scalar implementation using custom ScalarValue (#791) 2020-10-23 12:22:37 +02:00
Kai Ren
421b343398
Remove redundant extern crate usages (#790)
Additionally:
- remove obsolete benches in benches/ dir
- restore benches in juniper/benches/ dir
2020-10-19 19:42:27 +03:00
Igor Pashev
c964fd805c
Allow disabling case conversion (#765) 2020-10-13 12:34:36 -04:00
Kai Ren
cbf16c5a33
Make interfaces great again! (#682)
* Bootstrap

* Upd

* Bootstrap macro

* Revert stuff

* Correct PoC to compile

* Bootstrap #[graphql_interface] expansion

* Bootstrap #[graphql_interface] meta parsing

* Bootstrap #[graphql_interface] very basic code generation [skip ci]

* Upd trait code generation and fix keywords usage [skip ci]

* Expand trait impls [skip ci]

* Tune up objects [skip ci]

* Finally! Complies at least... [skip ci]

* Parse meta for fields and its arguments [skip ci]

- also, refactor and bikeshed new macros code

* Impl filling fields meta and bootstrap field resolution [skip ci]

* Poking with fields resolution [skip ci]

* Solve Rust's teen async HRTB problems [skip ci]

* Start parsing trait methods [skip ci]

* Finish parsing fields from trait methods [skip ci]

* Autodetect trait asyncness and allow to specify it [skip ci]

* Allow to autogenerate trait object alias via attribute

* Support generics in trait definition and asyncify them correctly

* Temporary disable explicit async

* Cover arguments and custom names/descriptions in tests

* Re-enable tests with explicit async and fix the codegen to satisfy it

* Check implementers are registered in schema and vice versa

* Check argument camelCases

* Test argument defaults, and allow Into coercions for them

* Re-enable markers

* Re-enable markers and relax Sized requirement on IsInputType/IsOutputType marker traits

* Revert 'juniper_actix' fmt

* Fix missing marks for object

* Fix subscriptions marks

* Deduce result type correctly via traits

* Final fixes

* Fmt

* Restore marks checking

* Support custom ScalarValue

* Cover deprecations with tests

* Impl dowcasting via methods

* Impl dowcasting via external functions

* Support custom context, vol. 1

* Support custom context, vol. 2

* Cover fallible field with test

* Impl explicit generic ScalarValue, vol.1

* Impl explicit generic ScalarValue, vol.2

* Allow passing executor into methods

* Generating enum, vol.1

* Generating enum, vol.2

* Generating enum, vol.3

* Generating enum, vol.3

* Generating enum, vol.4

* Generating enum, vol.5

* Generating enum, vol.6

* Generating enum, vol.7

* Generating enum, vol.8

* Refactor juniper stuff

* Fix juniper tests, vol.1

* Fix juniper tests, vol.2

* Polish 'juniper' crate changes, vol.1

* Polish 'juniper' crate changes, vol.2

* Remove redundant stuf

* Polishing 'juniper_codegen', vol.1

* Polishing 'juniper_codegen', vol.2

* Polishing 'juniper_codegen', vol.3

* Polishing 'juniper_codegen', vol.4

* Polishing 'juniper_codegen', vol.5

* Polishing 'juniper_codegen', vol.6

* Polishing 'juniper_codegen', vol.7

* Polishing 'juniper_codegen', vol.8

* Polishing 'juniper_codegen', vol.9

* Fix other crates tests and make Clippy happier

* Fix examples

* Add codegen failure tests, vol. 1

* Add codegen failure tests, vol. 2

* Add codegen failure tests, vol.3

* Fix codegen failure tests accordingly to latest nightly Rust

* Fix codegen when interface has no implementers

* Fix warnings in book tests

* Describing new interfaces in Book, vol.1

Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-10-05 21:21:01 -10:00
tyranron
a4f4d24677
Fix codegen failure tests on latest nightly Rust 2020-09-10 17:15:51 +03:00
Kai Ren
a684e1d91c
Re-enable marks-based static checks in code generated by macros (#751)
- add associated type to IntoResolvable and IntoFieldResult traits allowing to name the GraphQLType being resolved
- relax Sized requirement on some IsInputType and IsOutputType impls
2020-09-02 22:48:54 +03:00
Christian Legnitto
4647a32b33
Add examples to CI (#714) 2020-07-20 21:38:22 -10:00
Christian Legnitto
29930b002b
Update compile fail tests for nightly Rust (#710)
* 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
2020-07-18 13:19:50 -10:00
Chris
f5839c034e
Fix subscriptions with custom scalars (#706) 2020-07-17 10:52:16 +03:00
Christian Legnitto
61cb75969e
Move and enable public api integration tests (#692) 2020-07-08 16:40:34 -10:00
Kai Ren
35b804c37b
Decouple object safe part from GraphQLType traits (#685)
- 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
2020-06-30 11:20:21 +03:00