Skip to content

Commit ddc1488

Browse files
authored
Codegen reimplementation for GraphQL unions (#666)
- 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
1 parent 31d0888 commit ddc1488

File tree

99 files changed

+5656
-1530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5656
-1530
lines changed

docs/book/content/types/unions.md

Lines changed: 347 additions & 88 deletions
Large diffs are not rendered by default.

docs/book/tests/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ build = "build.rs"
99
juniper = { path = "../../../juniper" }
1010
juniper_iron = { path = "../../../juniper_iron" }
1111
juniper_subscriptions = { path = "../../../juniper_subscriptions" }
12+
13+
derive_more = "0.99.7"
1214
futures = "0.3"
1315
tokio = { version = "0.2", features = ["rt-core", "blocking", "stream", "rt-util"] }
1416
iron = "0.5.0"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use juniper::graphql_union;
2+
3+
#[graphql_union]
4+
enum Character {}
5+
6+
fn main() {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: #[graphql_union] attribute is applicable to trait definitions only
2+
--> $DIR/attr_wrong_item.rs:3:1
3+
|
4+
3 | #[graphql_union]
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

integration_tests/codegen_fail/fail/union/derive_enum_field.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

integration_tests/codegen_fail/fail/union/derive_enum_field.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

integration_tests/codegen_fail/fail/union/derive_no_fields.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

integration_tests/codegen_fail/fail/union/derive_no_fields.stderr

Lines changed: 0 additions & 7 deletions
This file was deleted.

integration_tests/codegen_fail/fail/union/derive_same_type.stderr

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use juniper::GraphQLUnion;
2+
3+
#[derive(GraphQLUnion)]
4+
union Character { id: i32 }
5+
6+
fn main() {}

0 commit comments

Comments
 (0)