Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow #[derive(GraphQLInterface)] and #[graphql_interface] on structs #1026

Merged
merged 128 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
01d7cb8
WIP
ilslv Dec 20, 2021
205cfcd
WIP
ilslv Dec 20, 2021
928cb9c
WIP (with IsSubtype)
ilslv Dec 20, 2021
3dad162
WIP (It looks like we're onto something)
ilslv Dec 20, 2021
af04486
WIP (return to const assertions)
ilslv Dec 21, 2021
4ae8c5d
Make `chrono` scalars similar to the `time`
ilslv Dec 23, 2021
279ae22
Remove FixedOffset scalar
ilslv Dec 23, 2021
bba4af8
Corrections
ilslv Dec 23, 2021
ecf9179
Merge branch 'master' into chrono-scalars
ilslv Dec 23, 2021
15e527f
It's alive!
ilslv Dec 24, 2021
cb9cad5
Merge branch 'master' into 1000-new-interfaces
ilslv Dec 24, 2021
7a78f9e
Use Field inside object's field resolver
ilslv Dec 24, 2021
5c2087c
Add async object fields
ilslv Dec 24, 2021
e9c6046
Fix
ilslv Dec 24, 2021
f2275a4
Corrections
tyranron Dec 25, 2021
0739c3e
Fix Wrapped type for tuple with context
ilslv Dec 27, 2021
263d544
WIP (Make graphql_interface_new attribute work)
ilslv Dec 28, 2021
f4c48a6
WIP (move to the new tests volume 1)
ilslv Dec 28, 2021
a1df387
WIP (move to the new tests volume 2)
ilslv Dec 29, 2021
5040d68
WIP (move to the new tests volume 3)
ilslv Dec 29, 2021
f5533e3
WIP (move to the new tests volume 4)
ilslv Dec 29, 2021
527325c
WIP (move to the new tests volume 5)
ilslv Dec 29, 2021
704f079
WIP (move to the new tests volume 5)
ilslv Dec 29, 2021
b84009e
WIP (refactor)
ilslv Dec 30, 2021
11345f7
WIP (refactor)
ilslv Dec 30, 2021
5e7230f
WIP (moving to readable const asserts)
ilslv Dec 30, 2021
d17ba4f
WIP (finally good const assert message)
ilslv Dec 30, 2021
8cb9b81
WIP (corrections)
ilslv Dec 30, 2021
116cdd9
WIP (pretty field arguments check)
ilslv Jan 3, 2022
7bd8c73
WIP (pretty subtype check)
ilslv Jan 3, 2022
3ebc8fd
WIP (corrections)
ilslv Jan 3, 2022
ce249b0
WIP (FieldMeta trait)
ilslv Jan 3, 2022
d9971a0
WIP (Refactor graphql_interface_new a bit)
ilslv Jan 3, 2022
8a966fb
WIP (Corrections)
ilslv Jan 3, 2022
21f4940
WIP (Prettify non-existent Field assertions)
ilslv Jan 4, 2022
e03901b
WIP (Move to macros::reflection module)
ilslv Jan 4, 2022
3ad8399
WIP (Docs vol. 1)
ilslv Jan 4, 2022
463bbb8
WIP (Docs vol. 2)
ilslv Jan 4, 2022
26ab27e
WIP (Refactoring)
ilslv Jan 4, 2022
cddb252
Merge branch 'master' into 1000-new-interfaces
ilslv Jan 4, 2022
9977746
WIP (Refactoring)
ilslv Jan 4, 2022
f5340a7
WIP (Tests corrections)
ilslv Jan 4, 2022
4c31c13
WIP (More tests vol. 1)
ilslv Jan 4, 2022
7bd09d0
WIP (Move everything to the new graphql_interface macro)
ilslv Jan 5, 2022
b5f552a
WIP (More codegen_fail tests)
ilslv Jan 5, 2022
66819e9
WIP (prettify missing references in `impl` and `for` attributes)
ilslv Jan 5, 2022
3d53dc1
WIP (more tests)
ilslv Jan 5, 2022
732bc13
WIP (Correct docs)
ilslv Jan 6, 2022
81d96ce
WIP (Forbid default trait method impls)
ilslv Jan 6, 2022
94164eb
WIP (Corrections)
ilslv Jan 6, 2022
1345bff
WIP (Corrections)
ilslv Jan 6, 2022
6cb5cef
WIP (Corrections)
ilslv Jan 6, 2022
41a2dcf
WIP (CHANGELOG)
ilslv Jan 6, 2022
eb8c56d
WIP (Correction)
ilslv Jan 6, 2022
7f45aef
WIP
ilslv Jan 10, 2022
81c4df9
Migrate to real GraphQLScalar trait
ilslv Jan 10, 2022
d359524
Corrections
ilslv Jan 10, 2022
888789a
Corrections
ilslv Jan 11, 2022
e28ca92
Add generic test and remove redundant lifetime
ilslv Jan 11, 2022
f531037
Some corrections [skip ci]
tyranron Jan 11, 2022
8f169cf
WIP
ilslv Jan 12, 2022
a2287dc
Minor tests corrections
ilslv Jan 12, 2022
ceb2cf6
Don't inject `#[async_trait]` in case some trait methods are async
ilslv Jan 12, 2022
d77a1ab
Corrections
ilslv Jan 13, 2022
8be555c
Merge branch '1000-new-interfaces' into generic-scalar
ilslv Jan 13, 2022
ebc0149
Merge branch 'generic-scalar' into new-derive-scalar
ilslv Jan 13, 2022
8fb4587
WIP
ilslv Jan 13, 2022
52c14b2
WIP
ilslv Jan 13, 2022
4b6df34
Corrections
ilslv Jan 14, 2022
0cb101d
Corrections
ilslv Jan 14, 2022
8d47ba7
Merge branch '1000-new-interfaces' into generic-scalar
ilslv Jan 14, 2022
22b3fe2
Merge branch 'generic-scalar' into new-derive-scalar
ilslv Jan 14, 2022
7635a1e
Corrections
ilslv Jan 14, 2022
3da33ba
Corrections
ilslv Jan 14, 2022
cc365d3
Corrections
ilslv Jan 14, 2022
30117a8
Docs and the book
ilslv Jan 14, 2022
2362b27
Fix The Book
ilslv Jan 14, 2022
193c77b
Merge branch 'master' into generic-scalar
ilslv Jan 28, 2022
86f1c10
CHANGELOG
ilslv Jan 28, 2022
7db2adc
Sprinkle `#[automatically_derived]` attributes
ilslv Jan 28, 2022
859b3be
Merge branch 'generic-scalar' into new-derive-scalar
ilslv Jan 28, 2022
6fb0dbf
Implement `#[graphql(with)]` attribute
ilslv Feb 2, 2022
f063728
CHANGELOG
ilslv Feb 2, 2022
10bea73
Implement `GraphQLScalarValue` derive macro
ilslv Feb 3, 2022
512f377
Add `codegen_fail` tests
ilslv Feb 3, 2022
60fcbbc
WIP
ilslv Feb 4, 2022
8b3e80a
Merge branch 'master' into new-derive-scalar
ilslv Feb 4, 2022
8706043
Corrections and tests
ilslv Feb 4, 2022
5b96861
Correction
ilslv Feb 4, 2022
81bb650
WIP
ilslv Feb 15, 2022
b4df74a
Corrections
ilslv Feb 15, 2022
2c5cf99
Merge branch 'new-derive-scalar' into derive-scalar-value
ilslv Feb 15, 2022
aed11f9
Corrections
ilslv Feb 15, 2022
a5cf713
CHANGELOG
ilslv Feb 15, 2022
5cc24db
CHANGELOG
ilslv Feb 15, 2022
ea6c4f7
WIP
ilslv Feb 17, 2022
8cea820
WIP
ilslv Feb 18, 2022
9c58419
Corrections
ilslv Feb 21, 2022
baad84b
Corrections
ilslv Feb 21, 2022
8ebd520
Merge branch 'new-derive-scalar' into derive-scalar-value
ilslv Feb 21, 2022
a2ecb44
Corrections
ilslv Feb 21, 2022
7a7d6ea
Merge branch 'derive-scalar-value' into derive-interface-on-structs
ilslv Feb 21, 2022
943526f
Corrections
ilslv Feb 21, 2022
9144d02
Corrections
ilslv Feb 21, 2022
6c5c7b7
Merge branch 'derive-scalar-value' into derive-interface-on-structs
ilslv Feb 21, 2022
7fab2ce
WIP
ilslv Feb 21, 2022
e58da4f
Merge branch 'derive-scalar-value' into chrono-scalars
ilslv Feb 24, 2022
173cddb
WIP
ilslv Feb 24, 2022
a7d4b28
Corrections
ilslv Feb 25, 2022
28bd546
Merge branch 'master' into derive-scalar-value
ilslv Mar 1, 2022
aa8a345
Corrections
ilslv Mar 1, 2022
b28cc4a
Merge branch 'derive-scalar-value' into chrono-scalars
ilslv Mar 1, 2022
641860b
Corrections
ilslv Mar 1, 2022
4226d19
Merge branch 'derive-scalar-value' into derive-interface-on-structs
ilslv Mar 1, 2022
466e7ae
Merge branch 'chrono-scalars' into derive-interface-on-structs
ilslv Mar 1, 2022
b4a7370
WIP
ilslv Mar 1, 2022
d443190
Corrections
ilslv Mar 1, 2022
32576cc
Merge branch 'master' into derive-interface-on-structs
ilslv Mar 8, 2022
f25488e
Corrections
ilslv Mar 10, 2022
f4bbdaf
CHANGELOG
ilslv Mar 10, 2022
c77fa9a
Corrections [skip ci]
tyranron Mar 11, 2022
6aa9b0b
Corrections
ilslv Mar 24, 2022
e9961ec
Corrections
ilslv Mar 25, 2022
33ee5b0
Merge remote-tracking branch 'origin/derive-interface-on-structs' int…
ilslv Mar 25, 2022
a89162c
Merge branch 'master' into derive-interface-on-structs
ilslv Mar 25, 2022
499cdf9
Corrections
ilslv Mar 29, 2022
b66452e
Merge branch 'master' into derive-interface-on-structs
tyranron Apr 1, 2022
89fc491
Minor corrections
tyranron Apr 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error[E0277]: the trait bound `ObjectA: IsInputType<__S>` is not satisfied
--> fail/input-object/derive_incompatible_object.rs:6:10
|
6 | #[derive(juniper::GraphQLInputObject)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IsInputType<__S>` is not implemented for `ObjectA`
--> fail/input-object/derive_incompatible_object.rs:8:12
|
= note: this error originates in the derive macro `juniper::GraphQLInputObject` (in Nightly builds, run with -Z macro-backtrace for more info)
8 | field: ObjectA,
| ^^^^^^^ the trait `IsInputType<__S>` is not implemented for `ObjectA`

error[E0277]: the trait bound `ObjectA: FromInputValue<__S>` is not satisfied
--> fail/input-object/derive_incompatible_object.rs:6:10
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: GraphQL interface #[graphql_interface] attribute is applicable to trait and struct definitions only
--> fail/interface/attr_wrong_item.rs:9:1
|
9 | enum Character {}
| ^^^^^^^^^^^^^^^^^
12 changes: 12 additions & 0 deletions integration_tests/codegen_fail/fail/interface/derive_wrong_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use juniper::{GraphQLInterface, GraphQLObject};

#[derive(GraphQLObject)]
pub struct ObjA {
test: String,
}

#[derive(GraphQLInterface)]
#[graphql(for = ObjA)]
enum Character {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: GraphQL interface can only be derived on structs
--> fail/interface/derive_wrong_item.rs:9:1
|
9 | / #[graphql(for = ObjA)]
10 | | enum Character {}
| |_________________^

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use juniper::{graphql_interface, graphql_object};

pub struct ObjA {
id: String,
}

#[graphql_object(impl = CharacterValue)]
impl ObjA {
fn id(&self, is_present: bool) -> &str {
is_present.then(|| self.id.as_str()).unwrap_or("missing")
}
}

#[graphql_interface(for = ObjA)]
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> fail/interface/struct/attr_additional_non_nullable_argument.rs:16:5
|
16 | id: String,
| ^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: Field `id`: Argument `isPresent` of type `Boolean!` isn't present on the interface and so has to be nullable.', $DIR/fail/interface/struct/attr_additional_non_nullable_argument.rs:16:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use juniper::graphql_interface;

#[graphql_interface]
struct Character {
__id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: All types and directives defined within a schema must not have a name which begins with `__` (two underscores), as this is used exclusively by GraphQL’s introspection system.
--> fail/interface/struct/attr_field_double_underscored.rs:5:5
|
5 | __id: String,
| ^^^^
|
= note: https://spec.graphql.org/June2018/#sec-Schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use juniper::{graphql_interface, GraphQLInputObject};

#[derive(GraphQLInputObject)]
pub struct ObjB {
id: i32,
}

#[graphql_interface]
struct Character {
id: ObjB,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0277]: the trait bound `ObjB: IsOutputType<__S>` is not satisfied
--> fail/interface/struct/attr_field_non_output_return_type.rs:10:9
|
10 | id: ObjB,
| ^^^^ the trait `IsOutputType<__S>` is not implemented for `ObjB`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use juniper::graphql_interface;

#[graphql_interface]
struct Character {
id: String,

#[graphql(name = "id")]
id2: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: GraphQL interface must have a different name for each field
--> fail/interface/struct/attr_fields_duplicate.rs:4:1
|
4 | / struct Character {
5 | | id: String,
6 | |
7 | | #[graphql(name = "id")]
8 | | id2: String,
9 | | }
| |_^
|
= note: https://spec.graphql.org/June2018/#sec-Interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use juniper::{graphql_interface, GraphQLObject};

#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct ObjA {
id: String,
}

#[graphql_interface(for = [ObjA, ObjA])]
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: duplicated attribute argument found
--> fail/interface/struct/attr_implementers_duplicate_pretty.rs:9:34
|
9 | #[graphql_interface(for = [ObjA, ObjA])]
| ^^^^

error[E0412]: cannot find type `CharacterValue` in this scope
--> fail/interface/struct/attr_implementers_duplicate_pretty.rs:4:18
|
4 | #[graphql(impl = CharacterValue)]
| ^^^^^^^^^^^^^^ not found in this scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use juniper::{graphql_interface, GraphQLObject};

#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct ObjA {
id: String,
}

type ObjAlias = ObjA;

#[graphql_interface(for = [ObjA, ObjAlias])]
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0119]: conflicting implementations of trait `std::convert::From<ObjA>` for type `CharacterValueEnum<ObjA, ObjA>`
--> fail/interface/struct/attr_implementers_duplicate_ugly.rs:11:1
|
11 | #[graphql_interface(for = [ObjA, ObjAlias])]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| first implementation here
| conflicting implementation for `CharacterValueEnum<ObjA, ObjA>`
|
= note: this error originates in the attribute macro `graphql_interface` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0119]: conflicting implementations of trait `<CharacterValueEnum<ObjA, ObjA> as juniper::GraphQLInterface<__S>>::mark::_::{closure#0}::MutuallyExclusive` for type `ObjA`
--> fail/interface/struct/attr_implementers_duplicate_ugly.rs:11:1
|
11 | #[graphql_interface(for = [ObjA, ObjAlias])]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| first implementation here
| conflicting implementation for `ObjA`
|
= note: this error originates in the macro `::juniper::sa::assert_type_ne_all` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use juniper::{graphql_interface, GraphQLObject};

#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct ObjA {
test: String,
}

#[graphql_interface(for = ObjA)]
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> fail/interface/struct/attr_missing_field.rs:11:5
|
11 | id: String,
| ^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: Field `id` isn't implemented on `ObjA`.', $DIR/fail/interface/struct/attr_missing_field.rs:11:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use juniper::{graphql_interface, GraphQLObject};

#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct ObjA {
id: String,
}

#[graphql_interface]
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> fail/interface/struct/attr_missing_for_attr.rs:3:10
|
3 | #[derive(GraphQLObject)]
| ^^^^^^^^^^^^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: missing implementer reference in interface's `for` attribute.', $DIR/fail/interface/struct/attr_missing_for_attr.rs:3:10
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use juniper::{graphql_interface, GraphQLObject};

#[derive(GraphQLObject)]
pub struct ObjA {
test: String,
id: String,
}

#[graphql_interface(for = ObjA)]
impl ObjA {}
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> fail/interface/struct/attr_missing_impl_attr.rs:8:1
|
8 | #[graphql_interface(for = ObjA)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: missing interface reference in implementer's `impl` attribute.', $DIR/fail/interface/struct/attr_missing_impl_attr.rs:8:1
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use juniper::graphql_interface;

#[graphql_interface]
struct __Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: All types and directives defined within a schema must not have a name which begins with `__` (two underscores), as this is used exclusively by GraphQL’s introspection system.
--> fail/interface/struct/attr_name_double_underscored.rs:4:8
|
4 | struct __Character {
| ^^^^^^^^^^^
|
= note: https://spec.graphql.org/June2018/#sec-Schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use juniper::graphql_interface;

#[graphql_interface]
struct Character {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: GraphQL interface must have at least one field
--> fail/interface/struct/attr_no_fields.rs:4:1
|
4 | struct Character {}
| ^^^^^^^^^^^^^^^^^^^
|
= note: https://spec.graphql.org/June2018/#sec-Interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use juniper::{graphql_interface, GraphQLObject};

#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct ObjA {
id: Vec<String>,
}

#[graphql_interface(for = ObjA)]
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> fail/interface/struct/attr_non_subtype_return.rs:11:5
|
11 | id: String,
| ^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: Field `id`: implementor is expected to return a subtype of interface's return object: `[String!]!` is not a subtype of `String!`.', $DIR/fail/interface/struct/attr_non_subtype_return.rs:11:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use juniper::{graphql_object, GraphQLInterface};

pub struct ObjA {
id: String,
}

#[graphql_object(impl = CharacterValue)]
impl ObjA {
fn id(&self, is_present: bool) -> &str {
is_present.then(|| self.id.as_str()).unwrap_or("missing")
}
}

#[derive(GraphQLInterface)]
#[graphql(for = ObjA)]
struct Character {
id: String,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> fail/interface/struct/derive_additional_non_nullable_argument.rs:17:5
|
17 | id: String,
| ^^ the evaluated program panicked at 'Failed to implement interface `Character` on `ObjA`: Field `id`: Argument `isPresent` of type `Boolean!` isn't present on the interface and so has to be nullable.', $DIR/fail/interface/struct/derive_additional_non_nullable_argument.rs:17:5
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use juniper::GraphQLInterface;

#[derive(GraphQLInterface)]
struct Character {
__id: String,
}

fn main() {}
Loading