Subscription typename - [GraphQL - October 2021] #681
This commit is contained in:
parent
a2a419430b
commit
3306f85a8a
|
@ -90,6 +90,7 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
|
|||
extends: #extends,
|
||||
keys: ::std::option::Option::None,
|
||||
visible: #visible,
|
||||
is_subscription: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ pub fn generate(object_args: &args::MergedSubscription) -> GeneratorResult<Token
|
|||
extends: #extends,
|
||||
keys: ::std::option::Option::None,
|
||||
visible: #visible,
|
||||
is_subscription: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -563,6 +563,7 @@ pub fn generate(
|
|||
extends: #extends,
|
||||
keys: ::std::option::Option::None,
|
||||
visible: #visible,
|
||||
is_subscription: false,
|
||||
});
|
||||
#(#create_entity_types)*
|
||||
#(#add_keys)*
|
||||
|
@ -630,6 +631,7 @@ pub fn generate(
|
|||
extends: #extends,
|
||||
keys: ::std::option::Option::None,
|
||||
visible: #visible,
|
||||
is_subscription: false,
|
||||
});
|
||||
#(#create_entity_types)*
|
||||
#(#add_keys)*
|
||||
|
|
|
@ -293,6 +293,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
|
|||
extends: #extends,
|
||||
keys: ::std::option::Option::None,
|
||||
visible: #visible,
|
||||
is_subscription: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -343,6 +344,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
|
|||
extends: #extends,
|
||||
keys: ::std::option::Option::None,
|
||||
visible: #visible,
|
||||
is_subscription: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -456,6 +456,7 @@ pub fn generate(
|
|||
extends: #extends,
|
||||
keys: ::std::option::Option::None,
|
||||
visible: ::std::option::Option::None,
|
||||
is_subscription: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,6 +199,7 @@ pub enum MetaType {
|
|||
extends: bool,
|
||||
keys: Option<Vec<String>>,
|
||||
visible: Option<MetaVisibleFn>,
|
||||
is_subscription: bool,
|
||||
},
|
||||
Interface {
|
||||
name: String,
|
||||
|
@ -375,6 +376,7 @@ impl Registry {
|
|||
extends: false,
|
||||
keys: None,
|
||||
visible: None,
|
||||
is_subscription: false,
|
||||
},
|
||||
);
|
||||
let ty = f(self);
|
||||
|
@ -508,6 +510,7 @@ impl Registry {
|
|||
extends: false,
|
||||
keys: None,
|
||||
visible: None,
|
||||
is_subscription: false,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -190,6 +190,7 @@ where
|
|||
extends: false,
|
||||
keys: None,
|
||||
visible: None,
|
||||
is_subscription: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ where
|
|||
extends: false,
|
||||
keys: None,
|
||||
visible: None,
|
||||
is_subscription: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ impl Type for EmptyMutation {
|
|||
extends: false,
|
||||
keys: None,
|
||||
visible: None,
|
||||
is_subscription: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ impl Type for EmptySubscription {
|
|||
extends: false,
|
||||
keys: None,
|
||||
visible: None,
|
||||
is_subscription: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{registry, InputType, InputValueError, InputValueResult, Type, Value}
|
|||
|
||||
/// Similar to `Option`, but it has three states, `undefined`, `null` and `x`.
|
||||
///
|
||||
/// **Reference:** <https://spec.graphql.org/June2018/#sec-Null-Value>
|
||||
/// **Reference:** <https://spec.graphql.org/October2021/#sec-Null-Value>
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
|
@ -50,6 +50,7 @@ impl<A: Type, B: Type> Type for MergedObject<A, B> {
|
|||
extends: false,
|
||||
keys: None,
|
||||
visible: None,
|
||||
is_subscription: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -329,4 +329,9 @@ mod tests {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typename_in_subscription_root() {
|
||||
expect_fails_rule!(factory, "subscription { __typename }");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::futures_util::Stream;
|
||||
use crate::parser::types::ExecutableDocument;
|
||||
use crate::validation::visitor::{visit, RuleError, Visitor, VisitorContext};
|
||||
use crate::*;
|
||||
|
@ -345,8 +346,17 @@ impl MutationRoot {
|
|||
}
|
||||
}
|
||||
|
||||
static TEST_HARNESS: Lazy<Schema<QueryRoot, MutationRoot, EmptySubscription>> =
|
||||
Lazy::new(|| Schema::new(QueryRoot, MutationRoot, EmptySubscription));
|
||||
pub struct SubscriptionRoot;
|
||||
|
||||
#[Subscription(internal)]
|
||||
impl SubscriptionRoot {
|
||||
async fn values(&self) -> impl Stream<Item = i32> {
|
||||
futures_util::stream::once(async move { 10 })
|
||||
}
|
||||
}
|
||||
|
||||
static TEST_HARNESS: Lazy<Schema<QueryRoot, MutationRoot, SubscriptionRoot>> =
|
||||
Lazy::new(|| Schema::new(QueryRoot, MutationRoot, SubscriptionRoot));
|
||||
|
||||
pub(crate) fn validate<'a, V, F>(
|
||||
doc: &'a ExecutableDocument,
|
||||
|
|
|
@ -611,6 +611,17 @@ fn visit_selection<'a, V: Visitor<'a>>(
|
|||
visit_field(v, ctx, field);
|
||||
},
|
||||
);
|
||||
} else if ctx.current_type().map(|ty| match ty {
|
||||
MetaType::Object {
|
||||
is_subscription, ..
|
||||
} => *is_subscription,
|
||||
_ => false,
|
||||
}) == Some(true)
|
||||
{
|
||||
ctx.report_error(
|
||||
vec![field.pos],
|
||||
"Unknown field \"__typename\" on type \"Subscription\".",
|
||||
);
|
||||
}
|
||||
}
|
||||
Selection::FragmentSpread(fragment_spread) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user