Impl objects, vol.1 [skip ci]
This commit is contained in:
parent
37257934b7
commit
b3659b88a4
3 changed files with 70 additions and 30 deletions
|
@ -395,7 +395,7 @@ impl ToTokens for Definition {
|
|||
self.impl_field_tokens().to_tokens(into);
|
||||
self.impl_async_field_tokens().to_tokens(into);
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//self.impl_reflect().to_tokens(into);
|
||||
self.impl_reflect().to_tokens(into);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1002,15 +1002,15 @@ impl Definition {
|
|||
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::BaseType<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::BaseType<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAME: ::juniper::reflect::Type = #name;
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::BaseSubTypes<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::BaseSubTypes<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAMES: ::juniper::reflect::Types = &[
|
||||
<Self as ::juniper::reflect::BaseType<#bh>>::NAME,
|
||||
|
@ -1019,8 +1019,8 @@ impl Definition {
|
|||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::Implements<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::Implements<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAMES: ::juniper::reflect::Types = &[#(
|
||||
<#interfaces as ::juniper::reflect::BaseType<#bh>>::NAME
|
||||
|
@ -1028,16 +1028,16 @@ impl Definition {
|
|||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::WrappedType<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::WrappedType<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const VALUE: ::juniper::reflect::WrappedValue =
|
||||
::juniper::reflect::wrap::SINGULAR;
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::Fields<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::Fields<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAMES: ::juniper::reflect::Names = &[#( #fields ),*];
|
||||
}
|
||||
|
|
|
@ -474,23 +474,23 @@ impl<Operation: ?Sized + 'static> Definition<Operation> {
|
|||
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::BaseType<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::BaseType<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAME: ::juniper::reflect::Type = #name;
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::BaseSubTypes<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::BaseSubTypes<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAMES: ::juniper::reflect::Types =
|
||||
&[<Self as ::juniper::reflect::BaseType<#bh>>::NAME];
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::Implements<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::Implements<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAMES: ::juniper::reflect::Types = &[#(
|
||||
<#interfaces as ::juniper::reflect::BaseType<#bh>>::NAME
|
||||
|
@ -498,16 +498,16 @@ impl<Operation: ?Sized + 'static> Definition<Operation> {
|
|||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::WrappedType<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::WrappedType<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const VALUE: ::juniper::reflect::WrappedValue =
|
||||
::juniper::reflect::wrap::SINGULAR;
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::Fields<#bh> for #ty
|
||||
#where_clause
|
||||
impl #impl_gens ::juniper::reflect::Fields<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAMES: ::juniper::reflect::Names = &[#( #fields ),*];
|
||||
}
|
||||
|
@ -531,9 +531,8 @@ impl<Operation: ?Sized + 'static> Definition<Operation> {
|
|||
.map(|field| {
|
||||
let (f_name, f_ty, f_bh) = (&field.name, &field.ty, &field.behavior);
|
||||
|
||||
let arguments = field
|
||||
.arguments
|
||||
.as_ref()
|
||||
let arguments = field.arguments.as_ref();
|
||||
let arguments = arguments
|
||||
.iter()
|
||||
.flat_map(|vec| vec.iter().filter_map(field::MethodArgument::as_regular))
|
||||
.map(|arg| {
|
||||
|
@ -546,11 +545,9 @@ impl<Operation: ?Sized + 'static> Definition<Operation> {
|
|||
<#a_ty as ::juniper::reflect::WrappedType<#a_bh>>
|
||||
::VALUE,
|
||||
)}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
});
|
||||
|
||||
quote! {
|
||||
#[allow(deprecated, non_snake_case)]
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::Field<
|
||||
{ ::juniper::reflect::fnv1a128(#f_name) }, #bh,
|
||||
|
@ -657,8 +654,8 @@ impl ToTokens for Definition<Query> {
|
|||
self.impl_field_tokens().to_tokens(into);
|
||||
self.impl_async_field_tokens().to_tokens(into);
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//self.impl_reflect().to_tokens(into);
|
||||
//self.impl_reflect_field().to_tokens(into);
|
||||
self.impl_reflect().to_tokens(into);
|
||||
self.impl_reflect_field().to_tokens(into);
|
||||
//self.impl_resolve_field_static().to_tokens(into);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,6 +315,8 @@ impl ToTokens for Definition {
|
|||
self.impl_graphql_value_tokens().to_tokens(into);
|
||||
self.impl_graphql_value_async_tokens().to_tokens(into);
|
||||
self.impl_reflection_traits_tokens().to_tokens(into);
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
self.impl_reflect().to_tokens(into);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -610,7 +612,7 @@ impl Definition {
|
|||
/// [`WrappedType`]: juniper::macros::reflect::WrappedType
|
||||
/// [1]: https://spec.graphql.org/October2021#sec-Unions
|
||||
#[must_use]
|
||||
pub(crate) fn impl_reflection_traits_tokens(&self) -> TokenStream {
|
||||
pub(crate)fn impl_reflection_traits_tokens(&self) -> TokenStream {
|
||||
let scalar = &self.scalar;
|
||||
let name = &self.name;
|
||||
let variants = self.variants.iter().map(|var| &var.ty);
|
||||
|
@ -645,6 +647,47 @@ impl Definition {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns generated code implementing [`reflect::BaseType`],
|
||||
/// [`reflect::BaseSubTypes`] and [`reflect::WrappedType`] traits for this
|
||||
/// [GraphQL union][0].
|
||||
///
|
||||
/// [`reflect::BaseSubTypes`]: juniper::reflect::BaseSubTypes
|
||||
/// [`reflect::BaseType`]: juniper::reflect::BaseType
|
||||
/// [`reflect::WrappedType`]: juniper::reflect::WrappedType
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Unions
|
||||
fn impl_reflect(&self) -> TokenStream {
|
||||
let bh = &self.behavior;
|
||||
let (ty, generics) = self.ty_and_generics();
|
||||
let (impl_gens, _, where_clause) = generics.split_for_impl();
|
||||
|
||||
let name = &self.name;
|
||||
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::BaseType<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAME: ::juniper::reflect::Type = #name;
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::BaseSubTypes<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const NAMES: ::juniper::reflect::Types =
|
||||
&[<Self as ::juniper::reflect::BaseType<#bh>>::NAME];
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl #impl_gens ::juniper::reflect::WrappedType<#bh>
|
||||
for #ty #where_clause
|
||||
{
|
||||
const VALUE: ::juniper::reflect::WrappedValue =
|
||||
::juniper::reflect::wrap::SINGULAR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Definition of [GraphQL union][1] variant for code generation.
|
||||
|
|
Loading…
Add table
Reference in a new issue