-
Notifications
You must be signed in to change notification settings - Fork 430
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
Conversation
# Conflicts: # integration_tests/juniper_tests/src/codegen/mod.rs # integration_tests/juniper_tests/src/codegen/scalar_attr_derive_input.rs # integration_tests/juniper_tests/src/codegen/scalar_attr_type_alias.rs # integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs # integration_tests/juniper_tests/src/custom_scalar.rs # juniper/CHANGELOG.md # juniper/src/lib.rs # juniper/src/types/scalars.rs # juniper/src/value/scalar.rs # juniper_codegen/src/derive_scalar_value.rs # juniper_codegen/src/graphql_scalar/attr.rs # juniper_codegen/src/graphql_scalar/derive.rs # juniper_codegen/src/graphql_scalar/mod.rs # juniper_codegen/src/lib.rs # juniper_codegen/src/result.rs
# Conflicts: # juniper/src/integrations/chrono.rs # juniper/src/integrations/chrono_tz.rs
# Conflicts: # integration_tests/codegen_fail/fail/scalar_value/missing_methods.stderr
# Conflicts: # integration_tests/codegen_fail/fail/scalar_value/missing_attributes.rs # integration_tests/codegen_fail/fail/scalar_value/missing_attributes.stderr # integration_tests/codegen_fail/fail/scalar_value/multiple_named_fields.rs # integration_tests/codegen_fail/fail/scalar_value/multiple_unnamed_fields.rs # integration_tests/juniper_tests/src/custom_scalar.rs # juniper/CHANGELOG.md # juniper/src/integrations/chrono.rs # juniper/src/integrations/chrono_tz.rs # juniper/src/value/scalar.rs # juniper_codegen/src/lib.rs
FCM
|
#[derive(GraphQLInterface)]
and #[graphql_interface]
on structs#[derive(GraphQLInterface)]
and #[graphql_interface]
on structs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilslv overall good, but requires a little bit of polishing though.
@@ -0,0 +1,2498 @@ | |||
//! Tests for `#[derive(GraphQLInterface)]` macro. | |||
|
|||
#![allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We better place this in codegen dirrectly, as it may appear in the user code frequently.
|
||
Ok(quote! { | ||
#[allow(dead_code)] | ||
#ast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. You're doing this already. The issue is that we cannot place it with the proc_macro_derive
.
Maybe we can generate some dummy global const
stuff using type-asserting the struct
or something like this instead?
"trait method should have a shared reference receiver `&self`", | ||
); | ||
fn err_unnamed_field<T, S: Spanned>(span: &S) -> Option<T> { | ||
ERR.emit_custom(span.span(), "expected named struct field"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this case covered in codegen failure tests. Please, add.
.unwrap_or_else(|| format_ident!("{}Value", struct_ident.to_string())); | ||
let enum_ident = attr.r#enum.as_ref().map_or_else( | ||
|| format_ident!("{}ValueEnum", struct_ident.to_string()), | ||
|c| format_ident!("{}Enum", c.inner().to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has become quite repetitive, so can be DRYed and factored out into a separate function for reusing.
|
||
/// Emits "expected named struct field" [`syn::Error`] pointing to the given | ||
/// `span`. | ||
fn err_unnamed_field<T, S: Spanned>(span: &S) -> Option<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh... do not duplicate code. Just reuse the one from a neigbour module.
@tyranron CI build on nightly fails because of briansmith/ring#1469 and from what I can tell this is a bug in recent nightly version and how it handles doc comments inside decl macros briansmith/ring#1470 |
# Conflicts: # juniper_codegen/src/common/parse/mod.rs
Synopsis
After #1009 GraphQL interfaces are represented with traits acting as blueprints for methods names, arguments and return types.
Solution
To emphasise structural nature of GraphQL interfaces, allow representing them with structs:
Checklist
Draft:
prefixDraft:
prefix is removed