Check std::prelude hygiene in codegen tests (#1195, #1194)

This commit is contained in:
tyranron 2023-10-13 21:01:43 +03:00
parent a433a278cf
commit 57628de864
No known key found for this signature in database
GPG key ID: 762E144FB230A4F0
19 changed files with 808 additions and 711 deletions

View file

@ -693,9 +693,11 @@ macro_rules! assert_field_args {
$field_name: expr $(,)?
) => {
const _: () = {
const BASE_NAME: &str = <$base_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
const IMPL_NAME: &str = <$impl_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
const ERR_PREFIX: &str = $crate::const_concat!(
const BASE_NAME: &::core::primitive::str =
<$base_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
const IMPL_NAME: &::core::primitive::str =
<$impl_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
const ERR_PREFIX: &::core::primitive::str = $crate::const_concat!(
"Failed to implement interface `",
BASE_NAME,
"` on `",
@ -703,7 +705,7 @@ macro_rules! assert_field_args {
"`: ",
);
const FIELD_NAME: &str = $field_name;
const FIELD_NAME: &::core::primitive::str = $field_name;
const BASE_ARGS: ::juniper::macros::reflect::Arguments =
<$base_ty as $crate::macros::reflect::FieldMeta<
@ -728,20 +730,20 @@ macro_rules! assert_field_args {
TypeMismatch,
}
const fn unwrap_error(v: ::std::result::Result<(), Error>) -> Error {
const fn unwrap_error(v: ::core::result::Result<(), Error>) -> Error {
match v {
// Unfortunately we can't use `unreachable!()` here, as this
// branch will be executed either way.
Ok(()) => Error {
::core::result::Result::Ok(()) => Error {
cause: Cause::RequiredField,
base: ("unreachable", "unreachable", 1),
implementation: ("unreachable", "unreachable", 1),
},
Err(err) => err,
::core::result::Result::Err(err) => err,
}
}
const fn check() -> Result<(), Error> {
const fn check() -> ::core::result::Result<(), Error> {
let mut base_i = 0;
while base_i < BASE_ARGS.len() {
let (base_name, base_type, base_wrap_val) = BASE_ARGS[base_i];
@ -800,7 +802,7 @@ macro_rules! assert_field_args {
base_i += 1;
}
if !was_found {
return Err(Error {
return ::core::result::Result::Err(Error {
cause: Cause::AdditionalNonNullableField,
base: (impl_name, impl_type, impl_wrapped_val),
implementation: (impl_name, impl_type, impl_wrapped_val),
@ -808,10 +810,10 @@ macro_rules! assert_field_args {
}
}
Ok(())
::core::result::Result::Ok(())
}
const RES: ::std::result::Result<(), Error> = check();
const RES: ::core::result::Result<(), Error> = check();
if RES.is_err() {
const ERROR: Error = unwrap_error(RES);
@ -822,7 +824,7 @@ macro_rules! assert_field_args {
const IMPL_TYPE_FORMATTED: &str =
$crate::format_type!(ERROR.implementation.1, ERROR.implementation.2);
const MSG: &str = match ERROR.cause {
const MSG: &::core::primitive::str = match ERROR.cause {
Cause::TypeMismatch => {
$crate::const_concat!(
"Argument `",
@ -865,9 +867,9 @@ macro_rules! assert_field_args {
#[macro_export]
macro_rules! const_concat {
($($s:expr),* $(,)?) => {{
const LEN: usize = 0 $(+ $s.as_bytes().len())*;
const CNT: usize = [$($s),*].len();
const fn concat(input: [&str; CNT]) -> [u8; LEN] {
const LEN: ::core::primitive::usize = 0 $(+ $s.as_bytes().len())*;
const CNT: ::core::primitive::usize = [$($s),*].len();
const fn concat(input: [&::core::primitive::str; CNT]) -> [::core::primitive::u8; LEN] {
let mut bytes = [0; LEN];
let (mut i, mut byte) = (0, 0);
while i < CNT {
@ -881,12 +883,12 @@ macro_rules! const_concat {
}
bytes
}
const CON: [u8; LEN] = concat([$($s),*]);
const CON: [::core::primitive::u8; LEN] = concat([$($s),*]);
// TODO: Use `.unwrap()` once it becomes `const`.
match ::std::str::from_utf8(&CON) {
::std::result::Result::Ok(s) => s,
_ => unreachable!(),
match ::core::str::from_utf8(&CON) {
::core::result::Result::Ok(s) => s,
_ => ::core::unreachable!(),
}
}};
}
@ -936,13 +938,13 @@ macro_rules! format_type {
) = ($ty, $wrapped_value);
const RES_LEN: usize = $crate::macros::reflect::type_len_with_wrapped_val(TYPE.0, TYPE.1);
const OPENING_BRACKET: &str = "[";
const CLOSING_BRACKET: &str = "]";
const BANG: &str = "!";
const OPENING_BRACKET: &::core::primitive::str = "[";
const CLOSING_BRACKET: &::core::primitive::str = "]";
const BANG: &::core::primitive::str = "!";
const fn format_type_arr() -> [u8; RES_LEN] {
const fn format_type_arr() -> [::core::primitive::u8; RES_LEN] {
let (ty, wrap_val) = TYPE;
let mut type_arr: [u8; RES_LEN] = [0; RES_LEN];
let mut type_arr: [::core::primitive::u8; RES_LEN] = [0; RES_LEN];
let mut current_start = 0;
let mut current_end = RES_LEN - 1;
@ -1003,13 +1005,14 @@ macro_rules! format_type {
type_arr
}
const TYPE_ARR: [u8; RES_LEN] = format_type_arr();
const TYPE_ARR: [::core::primitive::u8; RES_LEN] = format_type_arr();
// TODO: Use `.unwrap()` once it becomes `const`.
const TYPE_FORMATTED: &str = match ::std::str::from_utf8(TYPE_ARR.as_slice()) {
::std::result::Result::Ok(s) => s,
_ => unreachable!(),
};
const TYPE_FORMATTED: &::core::primitive::str =
match ::core::str::from_utf8(TYPE_ARR.as_slice()) {
::core::result::Result::Ok(s) => s,
_ => unreachable!(),
};
TYPE_FORMATTED
}};

View file

@ -1,12 +0,0 @@
// Local types overriding the stdlib Result should not affect generated code
type Result<T> = std::result::Result<T, ()>;
#[derive(juniper::GraphQLInputObject)]
#[graphql(name = "UserInformation")]
pub struct Update {
pub email: Option<String>,
pub username: Option<String>,
}
pub fn main() {}

View file

@ -1,12 +0,0 @@
// Local types overriding the stdlib Send should not affect generated code
trait Send {}
#[derive(juniper::GraphQLInputObject)]
#[graphql(name = "UserInformation")]
pub struct Update {
pub email: Option<String>,
pub username: Option<String>,
}
pub fn main() {}

View file

@ -7,10 +7,3 @@ fn test_failing_compilation() {
let t = trybuild::TestCases::new();
t.compile_fail("fail/**/*.rs");
}
#[rustversion::nightly]
#[test]
fn test_passing_compilation() {
let t = trybuild::TestCases::new();
t.pass("pass/**/*.rs");
}

View file

@ -9,6 +9,10 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod trivial {
use super::*;
@ -863,7 +867,7 @@ mod bounded_generic_scalar {
use super::*;
#[derive(GraphQLEnum)]
#[graphql(scalar = S: ScalarValue + Clone)]
#[graphql(scalar = S: ScalarValue + prelude::Clone)]
enum Character {
Human,
Droid,
@ -896,7 +900,7 @@ mod bounded_generic_scalar {
mod explicit_custom_context {
use super::*;
struct CustomContext(String);
struct CustomContext(prelude::String);
impl juniper::Context for CustomContext {}

View file

@ -9,6 +9,10 @@ use juniper::{
use self::common::util::schema;
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod trivial {
use super::*;
@ -267,16 +271,16 @@ mod default_nullable_value {
#[derive(GraphQLInputObject)]
struct Point2D {
#[graphql(default = 10.0)]
x: Option<f64>,
x: prelude::Option<f64>,
#[graphql(default = 10.0)]
y: Option<f64>,
y: prelude::Option<f64>,
}
struct QueryRoot;
#[graphql_object]
impl QueryRoot {
fn x(point: Point2D) -> Option<f64> {
fn x(point: Point2D) -> prelude::Option<f64> {
point.x
}
}

View file

@ -2,8 +2,6 @@
pub mod common;
use std::marker::PhantomData;
use juniper::{
execute, graphql_interface, graphql_object, graphql_value, graphql_vars, DefaultScalarValue,
FieldError, FieldResult, GraphQLObject, GraphQLUnion, IntoFieldError, ScalarValue, ID,
@ -11,12 +9,16 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod no_implers {
use super::*;
#[graphql_interface]
struct Character {
id: String,
id: prelude::String,
}
struct QueryRoot;
@ -82,19 +84,19 @@ mod trivial {
#[graphql_interface(for = [Human, Droid])]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -310,19 +312,19 @@ mod explicit_alias {
#[graphql_interface(enum = CharacterEnum, for = [Human, Droid])]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterEnum)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterEnum)]
@ -485,19 +487,19 @@ mod trivial_async {
#[graphql_interface(for = [Human, Droid])]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -718,24 +720,24 @@ mod fallible_field {
#[graphql_interface(for = [Human, Droid])]
struct Character {
id: Result<String, CustomError>,
id: prelude::Result<prelude::String, CustomError>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Droid {
fn id(&self) -> Result<String, CustomError> {
fn id(&self) -> prelude::Result<prelude::String, CustomError> {
Ok(self.id.clone())
}
@ -884,22 +886,22 @@ mod generic {
#[graphql_interface(for = [Human, Droid])]
struct Character<A = (), B: ?Sized = ()> {
id: String,
id: prelude::String,
#[graphql(skip)]
_phantom: PhantomData<(A, B)>,
_phantom: std::marker::PhantomData<(A, B)>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue<(), u8>)]
@ -1033,14 +1035,14 @@ mod description_from_doc_comment {
struct Character {
/// Rust `id` docs.
/// Long.
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct QueryRoot;
@ -1087,18 +1089,18 @@ mod deprecation_from_attr {
#[graphql_interface(for = Human)]
struct Character {
id: String,
id: prelude::String,
#[deprecated]
a: String,
a: prelude::String,
#[deprecated(note = "Use `id`.")]
b: String,
b: prelude::String,
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -1115,7 +1117,7 @@ mod deprecation_from_attr {
"a"
}
fn b() -> String {
fn b() -> prelude::String {
"b".into()
}
}
@ -1228,23 +1230,23 @@ mod explicit_name_description_and_deprecation {
/// Rust `id` docs.
#[graphql(name = "myId", desc = "My character ID.", deprecated = "Not used.")]
#[deprecated(note = "Should be omitted.")]
id: String,
id: prelude::String,
#[graphql(deprecated)]
#[deprecated(note = "Should be omitted.")]
a: String,
a: prelude::String,
b: String,
b: prelude::String,
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Human {
fn my_id(&self, #[graphql(name = "myName")] _: Option<String>) -> &str {
fn my_id(&self, #[graphql(name = "myName")] _: prelude::Option<prelude::String>) -> &str {
&self.id
}
@ -1252,7 +1254,7 @@ mod explicit_name_description_and_deprecation {
&self.home_planet
}
fn a() -> String {
fn a() -> prelude::String {
"a".into()
}
@ -1415,7 +1417,7 @@ mod renamed_all_fields_and_args {
#[graphql_interface(rename_all = "none", for = Human)]
struct Character {
id: String,
id: prelude::String,
}
struct Human;
@ -1490,19 +1492,19 @@ mod explicit_scalar {
#[graphql_interface(for = [Human, Droid])]
#[graphql_interface(scalar = DefaultScalarValue)]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = DefaultScalarValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = DefaultScalarValue)]
@ -1619,19 +1621,19 @@ mod custom_scalar {
#[graphql_interface(for = [Human, Droid], scalar = MyScalarValue)]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = MyScalarValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = MyScalarValue)]
@ -1746,19 +1748,19 @@ mod explicit_generic_scalar {
#[graphql_interface(for = [Human, Droid], scalar = S)]
struct Character<S: ScalarValue = DefaultScalarValue> {
id: FieldResult<String, S>,
id: FieldResult<prelude::String, S>,
}
#[derive(GraphQLObject)]
#[graphql(scalar = S: ScalarValue, impl = CharacterValue<S>)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue<__S>)]
@ -1871,24 +1873,24 @@ mod explicit_generic_scalar {
mod bounded_generic_scalar {
use super::*;
#[graphql_interface(for = [Human, Droid], scalar = S: ScalarValue + Clone)]
#[graphql_interface(for = [Human, Droid], scalar = S: ScalarValue + prelude::Clone)]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = S: ScalarValue + Clone)]
#[graphql(impl = CharacterValue, scalar = S: ScalarValue + prelude::Clone)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = S: ScalarValue + Clone)]
#[graphql_object(impl = CharacterValue, scalar = S: ScalarValue + prelude::Clone)]
impl Droid {
fn id(&self) -> &str {
&self.id
@ -2000,10 +2002,10 @@ mod ignored_method {
#[graphql_interface(for = Human)]
struct Character {
id: String,
id: prelude::String,
#[graphql(ignore)]
ignored: Option<Human>,
ignored: prelude::Option<Human>,
#[graphql(skip)]
skipped: i32,
@ -2012,8 +2014,8 @@ mod ignored_method {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct QueryRoot;
@ -2097,19 +2099,19 @@ mod field_return_subtyping {
#[graphql_interface(for = [Human, Droid])]
struct Character {
id: Option<String>,
id: prelude::Option<prelude::String>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -2241,21 +2243,21 @@ mod field_return_union_subtyping {
#[graphql_interface(for = [Human, Droid])]
struct Character {
id: Option<String>,
id: prelude::Option<prelude::String>,
key_feature: KeyFeature,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
key_feature: Knowledge,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
strength: i32,
}
@ -2401,24 +2403,24 @@ mod nullable_argument_subtyping {
#[graphql_interface(for = [Human, Droid])]
struct Character {
id: Option<String>,
id: prelude::Option<prelude::String>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Droid {
fn id(&self, is_present: Option<bool>) -> &str {
fn id(&self, is_present: prelude::Option<bool>) -> &str {
if is_present.unwrap_or_default() {
&self.id
} else {
@ -2532,20 +2534,20 @@ mod simple_subtyping {
#[graphql_interface(for = [ResourceValue, Endpoint])]
struct Node {
id: Option<ID>,
id: prelude::Option<ID>,
}
#[graphql_interface(impl = NodeValue, for = Endpoint)]
struct Resource {
id: ID,
url: Option<String>,
url: prelude::Option<prelude::String>,
}
#[derive(GraphQLObject)]
#[graphql(impl = [ResourceValue, NodeValue])]
struct Endpoint {
id: ID,
url: String,
url: prelude::String,
}
struct QueryRoot;
@ -2787,7 +2789,7 @@ mod branching_subtyping {
#[graphql_interface(impl = NodeValue, for = Luke)]
struct Human {
id: ID,
home_planet: String,
home_planet: prelude::String,
}
#[derive(GraphQLObject)]
@ -2799,7 +2801,7 @@ mod branching_subtyping {
#[graphql_interface(impl = NodeValue, for = R2D2)]
struct Droid {
id: ID,
primary_function: String,
primary_function: prelude::String,
}
#[derive(GraphQLObject)]
@ -2812,15 +2814,15 @@ mod branching_subtyping {
#[graphql(impl = [HumanValue, NodeValue])]
struct Luke {
id: ID,
home_planet: String,
father: String,
home_planet: prelude::String,
father: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = [DroidValue, NodeValue])]
struct R2D2 {
id: ID,
primary_function: String,
primary_function: prelude::String,
charge: f64,
}
@ -3065,14 +3067,14 @@ mod preserves_visibility {
#[graphql_interface(for = Human)]
pub(crate) struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub(crate) struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
}
}
@ -3084,13 +3086,13 @@ mod has_no_missing_docs {
#[graphql_interface(for = Human)]
pub struct Character {
pub id: String,
pub id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
}

View file

@ -10,6 +10,10 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod no_implers {
use super::*;
@ -87,13 +91,13 @@ mod trivial {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -315,13 +319,13 @@ mod explicit_alias {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterEnum)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterEnum)]
@ -490,13 +494,13 @@ mod trivial_async {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -720,24 +724,24 @@ mod fallible_field {
#[graphql_interface(for = [Human, Droid])]
trait Character {
fn id(&self) -> Result<&str, CustomError>;
fn id(&self) -> prelude::Result<&str, CustomError>;
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Droid {
fn id(&self) -> Result<String, CustomError> {
fn id(&self) -> prelude::Result<prelude::String, CustomError> {
Ok(self.id.clone())
}
@ -892,13 +896,13 @@ mod generic {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue<(), u8>)]
@ -1028,12 +1032,12 @@ mod argument {
trait Character {
fn id_wide(&self, is_number: bool) -> &str;
fn id_wide2(&self, is_number: bool, r#async: Option<i32>) -> &str;
fn id_wide2(&self, is_number: bool, r#async: prelude::Option<i32>) -> &str;
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -1054,7 +1058,7 @@ mod argument {
}
}
async fn id_wide2(&self, is_number: bool, _async: Option<i32>) -> &str {
async fn id_wide2(&self, is_number: bool, _async: prelude::Option<i32>) -> &str {
if is_number {
&self.id
} else {
@ -1203,10 +1207,10 @@ mod default_argument {
trait Character {
fn id(
&self,
#[graphql(default)] first: String,
#[graphql(default = "second")] second: String,
#[graphql(default = "t")] third: String,
) -> String;
#[graphql(default)] first: prelude::String,
#[graphql(default = "second")] second: prelude::String,
#[graphql(default = "t")] third: prelude::String,
) -> prelude::String;
fn info(&self, #[graphql(default = Point { x: 1 })] coord: Point) -> i32;
}
@ -1219,7 +1223,12 @@ mod default_argument {
coord.x
}
async fn id(&self, first: String, second: String, third: String) -> String {
async fn id(
&self,
first: prelude::String,
second: prelude::String,
third: prelude::String,
) -> prelude::String {
format!("{first}|{second}&{third}")
}
}
@ -1337,8 +1346,8 @@ mod description_from_doc_comment {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct QueryRoot;
@ -1395,8 +1404,8 @@ mod deprecation_from_attr {
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -1413,7 +1422,7 @@ mod deprecation_from_attr {
"a"
}
fn b() -> String {
fn b() -> prelude::String {
"b".into()
}
}
@ -1526,7 +1535,10 @@ mod explicit_name_description_and_deprecation {
/// Rust `id` docs.
#[graphql(name = "myId", desc = "My character ID.", deprecated = "Not used.")]
#[deprecated(note = "Should be omitted.")]
fn id(&self, #[graphql(name = "myName", desc = "My argument.")] n: Option<String>) -> &str;
fn id(
&self,
#[graphql(name = "myName", desc = "My argument.")] n: prelude::Option<prelude::String>,
) -> &str;
#[graphql(deprecated)]
#[deprecated(note = "Should be omitted.")]
@ -1536,13 +1548,13 @@ mod explicit_name_description_and_deprecation {
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Human {
fn my_id(&self, #[graphql(name = "myName")] _: Option<String>) -> &str {
fn my_id(&self, #[graphql(name = "myName")] _: prelude::Option<prelude::String>) -> &str {
&self.id
}
@ -1550,7 +1562,7 @@ mod explicit_name_description_and_deprecation {
&self.home_planet
}
fn a() -> String {
fn a() -> prelude::String {
"a".into()
}
@ -1715,7 +1727,7 @@ mod renamed_all_fields_and_args {
trait Character {
fn id(&self) -> &str;
fn home_planet(&self, planet_name: String) -> String;
fn home_planet(&self, planet_name: prelude::String) -> prelude::String;
fn r#async_info(&self, r#my_num: i32) -> i32;
}
@ -1728,7 +1740,7 @@ mod renamed_all_fields_and_args {
"human-32"
}
async fn home_planet(planet_name: String) -> String {
async fn home_planet(planet_name: prelude::String) -> prelude::String {
planet_name
}
@ -1812,13 +1824,13 @@ mod explicit_scalar {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = DefaultScalarValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = DefaultScalarValue)]
@ -1941,13 +1953,13 @@ mod custom_scalar {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = MyScalarValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = MyScalarValue)]
@ -2068,13 +2080,13 @@ mod explicit_generic_scalar {
#[derive(GraphQLObject)]
#[graphql(scalar = S: ScalarValue, impl = CharacterValue<S>)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue<__S>)]
@ -2187,24 +2199,24 @@ mod explicit_generic_scalar {
mod bounded_generic_scalar {
use super::*;
#[graphql_interface(for = [Human, Droid], scalar = S: ScalarValue + Clone)]
#[graphql_interface(for = [Human, Droid], scalar = S: ScalarValue + prelude::Clone)]
trait Character {
fn id(&self) -> &str;
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = S: ScalarValue + Clone)]
#[graphql(impl = CharacterValue, scalar = S: ScalarValue + prelude::Clone)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = S: ScalarValue + Clone)]
#[graphql_object(impl = CharacterValue, scalar = S: ScalarValue + prelude::Clone)]
impl Droid {
fn id(&self) -> &str {
&self.id
@ -2328,8 +2340,8 @@ mod explicit_custom_context {
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue, context = CustomContext)]
@ -2352,8 +2364,8 @@ mod explicit_custom_context {
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, context = CustomContext)]
@ -2483,7 +2495,7 @@ mod explicit_custom_context {
mod inferred_custom_context_from_field {
use super::*;
struct CustomContext(String);
struct CustomContext(prelude::String);
impl juniper::Context for CustomContext {}
@ -2495,7 +2507,7 @@ mod inferred_custom_context_from_field {
}
struct Human {
home_planet: String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue, context = CustomContext)]
@ -2514,7 +2526,7 @@ mod inferred_custom_context_from_field {
}
struct Droid {
primary_function: String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, context = CustomContext)]
@ -2647,13 +2659,13 @@ mod executor {
fn info<'b>(
&'b self,
arg: Option<i32>,
arg: prelude::Option<i32>,
#[graphql(executor)] another: &Executor<'_, '_, (), S>,
) -> &'b str;
}
struct Human {
home_planet: String,
home_planet: prelude::String,
}
#[graphql_object(scalar = S: ScalarValue, impl = CharacterValue<S>)]
@ -2666,13 +2678,13 @@ mod executor {
&self.home_planet
}
async fn info<'b>(&'b self, _arg: Option<i32>) -> &'b str {
async fn info<'b>(&'b self, _arg: prelude::Option<i32>) -> &'b str {
&self.home_planet
}
}
struct Droid {
primary_function: String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue<__S>)]
@ -2687,7 +2699,7 @@ mod executor {
async fn info<'b, S: ScalarValue>(
&'b self,
_arg: Option<i32>,
_arg: prelude::Option<i32>,
_executor: &Executor<'_, '_, (), S>,
) -> &'b str {
&self.primary_function
@ -2827,7 +2839,7 @@ mod ignored_method {
fn id(&self) -> &str;
#[graphql(ignore)]
fn ignored(&self) -> Option<&Human> {
fn ignored(&self) -> prelude::Option<&Human> {
None
}
@ -2838,8 +2850,8 @@ mod ignored_method {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct QueryRoot;
@ -2923,19 +2935,19 @@ mod field_return_subtyping {
#[graphql_interface(for = [Human, Droid])]
trait Character {
fn id(&self) -> Option<String>;
fn id(&self) -> prelude::Option<prelude::String>;
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -3067,7 +3079,7 @@ mod field_return_union_subtyping {
#[graphql_interface(for = [Human, Droid])]
trait Character {
fn id(&self) -> Option<String>;
fn id(&self) -> prelude::Option<prelude::String>;
fn key_feature(&self) -> KeyFeature;
}
@ -3075,14 +3087,14 @@ mod field_return_union_subtyping {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
key_feature: Knowledge,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
strength: i32,
}
@ -3228,24 +3240,24 @@ mod nullable_argument_subtyping {
#[graphql_interface(for = [Human, Droid])]
trait Character {
fn id(&self) -> Option<String>;
fn id(&self) -> prelude::Option<prelude::String>;
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Droid {
fn id(&self, is_present: Option<bool>) -> &str {
fn id(&self, is_present: prelude::Option<bool>) -> &str {
if is_present.unwrap_or_default() {
&self.id
} else {
@ -3359,20 +3371,20 @@ mod simple_subtyping {
#[graphql_interface(for = [ResourceValue, Endpoint])]
trait Node {
fn id() -> Option<ID>;
fn id() -> prelude::Option<ID>;
}
#[graphql_interface(impl = NodeValue, for = Endpoint)]
trait Resource {
fn id(&self) -> &ID;
fn url(&self) -> Option<&str>;
fn url(&self) -> prelude::Option<&str>;
}
#[derive(GraphQLObject)]
#[graphql(impl = [ResourceValue, NodeValue])]
struct Endpoint {
id: ID,
url: String,
url: prelude::String,
}
struct QueryRoot;
@ -3626,7 +3638,7 @@ mod branching_subtyping {
#[graphql_interface(impl = NodeValue, for = R2D2)]
trait Droid {
fn id() -> ID;
fn primary_function() -> String;
fn primary_function() -> prelude::String;
}
#[derive(GraphQLObject)]
@ -3639,15 +3651,15 @@ mod branching_subtyping {
#[graphql(impl = [HumanValue, NodeValue])]
struct Luke {
id: ID,
home_planet: String,
father: String,
home_planet: prelude::String,
father: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = [DroidValue, NodeValue])]
struct R2D2 {
id: ID,
primary_function: String,
primary_function: prelude::String,
charge: f64,
}
@ -3898,8 +3910,8 @@ mod preserves_visibility {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub(crate) struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
}
}
@ -3917,7 +3929,7 @@ mod has_no_missing_docs {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
}

View file

@ -2,8 +2,6 @@
pub mod common;
use std::marker::PhantomData;
use juniper::{
execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, FieldError,
FieldResult, GraphQLInterface, GraphQLObject, GraphQLUnion, IntoFieldError, ScalarValue, ID,
@ -11,12 +9,16 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod no_implers {
use super::*;
#[derive(GraphQLInterface)]
struct Character {
id: String,
id: prelude::String,
}
struct QueryRoot;
@ -83,19 +85,19 @@ mod trivial {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid])]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -312,19 +314,19 @@ mod explicit_alias {
#[derive(GraphQLInterface)]
#[graphql(enum = CharacterEnum, for = [Human, Droid])]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterEnum)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterEnum)]
@ -488,19 +490,19 @@ mod trivial_async {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid])]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -725,24 +727,24 @@ mod fallible_field {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid])]
struct Character {
id: Result<String, CustomError>,
id: prelude::Result<prelude::String, CustomError>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Droid {
fn id(&self) -> Result<String, CustomError> {
fn id(&self) -> prelude::Result<prelude::String, CustomError> {
Ok(self.id.clone())
}
@ -892,22 +894,22 @@ mod generic {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid])]
struct Character<A = (), B: ?Sized = ()> {
id: String,
id: prelude::String,
#[graphql(skip)]
_phantom: PhantomData<(A, B)>,
_phantom: std::marker::PhantomData<(A, B)>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue<(), u8>)]
@ -1042,14 +1044,14 @@ mod description_from_doc_comment {
struct Character {
/// Rust `id` docs.
/// Long.
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct QueryRoot;
@ -1097,18 +1099,18 @@ mod deprecation_from_attr {
#[derive(GraphQLInterface)]
#[graphql(for = Human)]
struct Character {
id: String,
id: prelude::String,
#[deprecated]
a: String,
a: prelude::String,
#[deprecated(note = "Use `id`.")]
b: String,
b: prelude::String,
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -1125,7 +1127,7 @@ mod deprecation_from_attr {
"a"
}
fn b() -> String {
fn b() -> prelude::String {
"b".into()
}
}
@ -1239,23 +1241,23 @@ mod explicit_name_description_and_deprecation {
/// Rust `id` docs.
#[graphql(name = "myId", desc = "My character ID.", deprecated = "Not used.")]
#[deprecated(note = "Should be omitted.")]
id: String,
id: prelude::String,
#[graphql(deprecated)]
#[deprecated(note = "Should be omitted.")]
a: String,
a: prelude::String,
b: String,
b: prelude::String,
}
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Human {
fn my_id(&self, #[graphql(name = "myName")] _: Option<String>) -> &str {
fn my_id(&self, #[graphql(name = "myName")] _: prelude::Option<prelude::String>) -> &str {
&self.id
}
@ -1263,7 +1265,7 @@ mod explicit_name_description_and_deprecation {
&self.home_planet
}
fn a() -> String {
fn a() -> prelude::String {
"a".into()
}
@ -1427,7 +1429,7 @@ mod renamed_all_fields_and_args {
#[derive(GraphQLInterface)]
#[graphql(rename_all = "none", for = Human)]
struct Character {
id: String,
id: prelude::String,
}
struct Human;
@ -1503,19 +1505,19 @@ mod explicit_scalar {
#[graphql(for = [Human, Droid])]
#[graphql(scalar = DefaultScalarValue)]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = DefaultScalarValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = DefaultScalarValue)]
@ -1633,19 +1635,19 @@ mod custom_scalar {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid], scalar = MyScalarValue)]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = MyScalarValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = MyScalarValue)]
@ -1761,19 +1763,19 @@ mod explicit_generic_scalar {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid], scalar = S)]
struct Character<S: ScalarValue = DefaultScalarValue> {
id: FieldResult<String, S>,
id: FieldResult<prelude::String, S>,
}
#[derive(GraphQLObject)]
#[graphql(scalar = S: ScalarValue, impl = CharacterValue<S>)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue<__S>)]
@ -1887,24 +1889,24 @@ mod bounded_generic_scalar {
use super::*;
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid], scalar = S: ScalarValue + Clone)]
#[graphql(for = [Human, Droid], scalar = S: ScalarValue + prelude::Clone)]
struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue, scalar = S: ScalarValue + Clone)]
#[graphql(impl = CharacterValue, scalar = S: ScalarValue + prelude::Clone)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue, scalar = S: ScalarValue + Clone)]
#[graphql_object(impl = CharacterValue, scalar = S: ScalarValue + prelude::Clone)]
impl Droid {
fn id(&self) -> &str {
&self.id
@ -2017,10 +2019,10 @@ mod ignored_method {
#[derive(GraphQLInterface)]
#[graphql(for = Human)]
struct Character {
id: String,
id: prelude::String,
#[graphql(ignore)]
ignored: Option<Human>,
ignored: prelude::Option<Human>,
#[graphql(skip)]
skipped: i32,
@ -2029,8 +2031,8 @@ mod ignored_method {
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct QueryRoot;
@ -2115,19 +2117,19 @@ mod field_return_subtyping {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid])]
struct Character {
id: Option<String>,
id: prelude::Option<prelude::String>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
@ -2260,21 +2262,21 @@ mod field_return_union_subtyping {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid])]
struct Character {
id: Option<String>,
id: prelude::Option<prelude::String>,
key_feature: KeyFeature,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
key_feature: Knowledge,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
strength: i32,
}
@ -2421,24 +2423,24 @@ mod nullable_argument_subtyping {
#[derive(GraphQLInterface)]
#[graphql(for = [Human, Droid])]
struct Character {
id: Option<String>,
id: prelude::Option<prelude::String>,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[graphql_object(impl = CharacterValue)]
impl Droid {
fn id(&self, is_present: Option<bool>) -> &str {
fn id(&self, is_present: prelude::Option<bool>) -> &str {
if is_present.unwrap_or_default() {
&self.id
} else {
@ -2553,21 +2555,21 @@ mod simple_subtyping {
#[derive(GraphQLInterface)]
#[graphql(for = [ResourceValue, Endpoint])]
struct Node {
id: Option<ID>,
id: prelude::Option<ID>,
}
#[derive(GraphQLInterface)]
#[graphql(impl = NodeValue, for = Endpoint)]
struct Resource {
id: ID,
url: Option<String>,
url: prelude::Option<prelude::String>,
}
#[derive(GraphQLObject)]
#[graphql(impl = [ResourceValue, NodeValue])]
struct Endpoint {
id: ID,
url: String,
url: prelude::String,
}
struct QueryRoot;
@ -2812,7 +2814,7 @@ mod branching_subtyping {
#[graphql(impl = NodeValue, for = Luke)]
struct Human {
id: ID,
home_planet: String,
home_planet: prelude::String,
}
#[derive(GraphQLObject)]
@ -2825,7 +2827,7 @@ mod branching_subtyping {
#[graphql(impl = NodeValue, for = R2D2)]
struct Droid {
id: ID,
primary_function: String,
primary_function: prelude::String,
}
#[derive(GraphQLObject)]
@ -2838,15 +2840,15 @@ mod branching_subtyping {
#[graphql(impl = [HumanValue, NodeValue])]
struct Luke {
id: ID,
home_planet: String,
father: String,
home_planet: prelude::String,
father: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = [DroidValue, NodeValue])]
struct R2D2 {
id: ID,
primary_function: String,
primary_function: prelude::String,
charge: f64,
}
@ -3092,14 +3094,14 @@ mod preserves_visibility {
#[derive(GraphQLInterface)]
#[graphql(for = Human)]
pub(crate) struct Character {
id: String,
id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub(crate) struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
}
}
@ -3112,13 +3114,13 @@ mod has_no_missing_docs {
#[derive(GraphQLInterface)]
#[graphql(for = Human)]
pub struct Character {
pub id: String,
pub id: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)]
pub struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
}

View file

@ -9,6 +9,10 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod trivial {
use super::*;
@ -333,12 +337,12 @@ mod fallible_method {
}
struct Human {
id: String,
id: prelude::String,
}
#[graphql_object]
impl Human {
fn id(&self) -> Result<&str, CustomError> {
fn id(&self) -> prelude::Result<&str, CustomError> {
Ok(&self.id)
}
@ -435,7 +439,7 @@ mod generic {
}
#[graphql_object(name = "HumanString")]
impl<B: ?Sized> Human<String, B> {
impl<B: ?Sized> Human<prelude::String, B> {
fn id(&self) -> &str {
self.id.as_str()
}
@ -453,7 +457,7 @@ mod generic {
}
}
fn human_string(&self) -> Human<String> {
fn human_string(&self) -> Human<prelude::String> {
Human {
id: "human-32".into(),
_home_planet: (),
@ -526,7 +530,7 @@ mod generic_async {
}
#[graphql_object(name = "HumanString")]
impl<B: ?Sized> Human<String, B> {
impl<B: ?Sized> Human<prelude::String, B> {
async fn id(&self) -> &str {
self.id.as_str()
}
@ -544,7 +548,7 @@ mod generic_async {
}
}
fn human_string(&self) -> Human<String> {
fn human_string(&self) -> Human<prelude::String> {
Human {
id: "human-32".into(),
_home_planet: (),
@ -632,7 +636,7 @@ mod generic_lifetime_async {
}
#[derive(Clone)]
struct QueryRoot(String);
struct QueryRoot(prelude::String);
#[graphql_object]
impl QueryRoot {
@ -780,7 +784,7 @@ mod nested_generic_lifetime_async {
}
#[derive(Clone)]
struct QueryRoot(String);
struct QueryRoot(prelude::String);
#[graphql_object]
impl QueryRoot {
@ -889,11 +893,15 @@ mod argument {
#[graphql_object]
impl Human {
fn id(arg: String) -> String {
fn id(arg: prelude::String) -> prelude::String {
arg
}
async fn home_planet(&self, r#raw_arg: String, r#async: Option<i32>) -> String {
async fn home_planet(
&self,
r#raw_arg: prelude::String,
r#async: prelude::Option<i32>,
) -> prelude::String {
format!("{raw_arg},{async:?}")
}
}
@ -1021,9 +1029,9 @@ mod default_argument {
impl Human {
fn id(
#[graphql(default)] arg1: i32,
#[graphql(default = "second".to_string())] arg2: Option<String>,
#[graphql(default = "second".to_string())] arg2: prelude::Option<prelude::String>,
#[graphql(default = true)] r#arg3: bool,
) -> String {
) -> prelude::String {
format!("{arg1}|{arg2:?}&{arg3}")
}
@ -1358,7 +1366,7 @@ mod explicit_name_description_and_deprecation {
#[graphql(name = "myId", desc = "My human ID.", deprecated = "Not used.")]
#[deprecated(note = "Should be omitted.")]
fn id(
#[graphql(name = "myName", desc = "My argument.", default)] _n: String,
#[graphql(name = "myName", desc = "My argument.", default)] _n: prelude::String,
) -> &'static str {
"human-32"
}
@ -1526,7 +1534,7 @@ mod renamed_all_fields_and_args {
"human-32"
}
async fn home_planet(&self, planet_name: String) -> String {
async fn home_planet(&self, planet_name: prelude::String) -> prelude::String {
planet_name
}
@ -1750,7 +1758,7 @@ mod bounded_generic_scalar {
struct Human;
#[graphql_object(scalar = S: ScalarValue + Clone)]
#[graphql_object(scalar = S: ScalarValue + prelude::Clone)]
impl Human {
fn id() -> &'static str {
"human-32"
@ -1799,7 +1807,7 @@ mod bounded_generic_scalar {
mod explicit_custom_context {
use super::*;
struct CustomContext(String);
struct CustomContext(prelude::String);
impl juniper::Context for CustomContext {}
@ -1859,7 +1867,7 @@ mod explicit_custom_context {
mod inferred_custom_context_from_field {
use super::*;
struct CustomContext(String);
struct CustomContext(prelude::String);
impl juniper::Context for CustomContext {}
@ -1934,9 +1942,9 @@ mod executor {
fn info<S>(
&self,
arg: String,
arg: prelude::String,
#[graphql(executor)] _another: &Executor<'_, '_, (), S>,
) -> String {
) -> prelude::String {
arg
}
@ -2033,7 +2041,7 @@ mod switched_context {
async fn switch_opt<'e, S: ScalarValue>(
executor: &'e Executor<'_, '_, CustomContext, S>,
) -> Option<(&'e CustomContext, Droid)> {
) -> prelude::Option<(&'e CustomContext, Droid)> {
Some((executor.context(), Droid { id: 1 }))
}
@ -2047,7 +2055,7 @@ mod switched_context {
async fn switch_res_opt<'e, S: ScalarValue>(
&self,
executor: &'e Executor<'_, '_, CustomContext, S>,
) -> FieldResult<Option<(&'e CustomContext, Droid)>> {
) -> FieldResult<prelude::Option<(&'e CustomContext, Droid)>> {
Ok(Some((executor.context(), Droid { id: 3 })))
}
}

View file

@ -9,6 +9,10 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod trivial {
use super::*;
@ -280,7 +284,7 @@ mod generic_lifetime {
_home_planet: B,
}
struct QueryRoot(String);
struct QueryRoot(prelude::String);
#[graphql_object]
impl QueryRoot {
@ -336,12 +340,12 @@ mod nested_generic_lifetime_async {
}
#[derive(GraphQLObject)]
struct Human<'d, A: Sync = ()> {
struct Human<'d, A: prelude::Sync = ()> {
id: i32,
droid: Droid<'d, A>,
}
struct QueryRoot(String);
struct QueryRoot(prelude::String);
#[graphql_object]
impl QueryRoot {
@ -413,7 +417,7 @@ mod description_from_doc_comment {
struct Human {
/// Rust `id` docs.
/// Here.
id: String,
id: prelude::String,
}
struct QueryRoot;
@ -458,7 +462,7 @@ mod deprecation_from_attr {
#[derive(GraphQLObject)]
struct Human {
id: String,
id: prelude::String,
#[deprecated]
a: &'static str,
#[deprecated(note = "Use `id`.")]
@ -575,7 +579,7 @@ mod explicit_name_description_and_deprecation {
/// Rust `id` docs.
#[graphql(name = "myId", desc = "My human ID.", deprecated = "Not used.")]
#[deprecated(note = "Should be omitted.")]
id: String,
id: prelude::String,
#[graphql(deprecated)]
#[deprecated(note = "Should be omitted.")]
a: &'static str,
@ -726,7 +730,7 @@ mod renamed_all_fields {
#[graphql(rename_all = "none")]
struct Human {
id: &'static str,
home_planet: String,
home_planet: prelude::String,
r#async_info: i32,
}
@ -873,7 +877,7 @@ mod explicit_generic_scalar {
#[derive(GraphQLObject)]
#[graphql(scalar = S)]
struct Human<S: Clone> {
struct Human<S: prelude::Clone> {
id: &'static str,
#[graphql(ignore)]
_scalar: PhantomData<S>,
@ -883,7 +887,7 @@ mod explicit_generic_scalar {
#[graphql_object]
impl QueryRoot {
fn human<__S: Clone>() -> Human<__S> {
fn human<__S: prelude::Clone>() -> Human<__S> {
Human {
id: "human-32",
_scalar: PhantomData,
@ -912,7 +916,7 @@ mod bounded_generic_scalar {
use super::*;
#[derive(GraphQLObject)]
#[graphql(scalar = S: ScalarValue + Clone)]
#[graphql(scalar = S: ScalarValue + prelude::Clone)]
struct Human {
id: &'static str,
}
@ -946,7 +950,7 @@ mod bounded_generic_scalar {
mod explicit_custom_context {
use super::*;
struct CustomContext(String);
struct CustomContext(prelude::String);
impl juniper::Context for CustomContext {}

View file

@ -17,6 +17,10 @@ use self::common::{
MyScalarValue,
};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod trivial {
use super::*;
@ -28,7 +32,7 @@ mod trivial {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -236,7 +240,7 @@ mod all_custom_resolvers {
Value::scalar(v.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(Counter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -311,7 +315,7 @@ mod explicit_name {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -387,7 +391,7 @@ mod delegated_parse_token {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -451,9 +455,9 @@ mod delegated_parse_token {
mod multiple_delegated_parse_token {
use super::*;
#[graphql_scalar(parse_token(String, i32))]
#[graphql_scalar(parse_token(prelude::String, i32))]
enum StringOrInt {
String(String),
String(prelude::String),
Int(i32),
}
@ -465,7 +469,7 @@ mod multiple_delegated_parse_token {
}
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_string_value()
.map(|s| Self::String(s.to_owned()))
.or_else(|| v.as_int_value().map(Self::Int))
@ -513,7 +517,7 @@ mod where_attribute {
#[graphql_scalar(
to_output_with = to_output,
from_input_with = from_input,
parse_token(String),
parse_token(prelude::String),
where(Tz: From<Utc>, Tz::Offset: fmt::Display),
specified_by_url = "https://tools.ietf.org/html/rfc3339",
)]
@ -528,7 +532,7 @@ mod where_attribute {
Value::scalar(v.0.to_rfc3339())
}
fn from_input<S, Tz>(v: &InputValue<S>) -> Result<CustomDateTime<Tz>, String>
fn from_input<S, Tz>(v: &InputValue<S>) -> prelude::Result<CustomDateTime<Tz>, prelude::String>
where
S: ScalarValue,
Tz: From<Utc> + TimeZone,
@ -598,7 +602,7 @@ mod with_self {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -668,7 +672,7 @@ mod with_module {
#[graphql_scalar(
with = custom_date_time,
parse_token(String),
parse_token(prelude::String),
where(Tz: From<Utc>, Tz::Offset: fmt::Display),
specified_by_url = "https://tools.ietf.org/html/rfc3339",
)]
@ -686,7 +690,9 @@ mod with_module {
Value::scalar(v.0.to_rfc3339())
}
pub(super) fn from_input<S, Tz>(v: &InputValue<S>) -> Result<CustomDateTime<Tz>, String>
pub(super) fn from_input<S, Tz>(
v: &InputValue<S>,
) -> prelude::Result<CustomDateTime<Tz>, prelude::String>
where
S: ScalarValue,
Tz: From<Utc> + TimeZone,
@ -758,7 +764,7 @@ mod description_from_doc_comment {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -834,7 +840,7 @@ mod description_from_attribute {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -910,7 +916,7 @@ mod custom_scalar {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -986,7 +992,7 @@ mod generic_scalar {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -1053,7 +1059,7 @@ mod generic_scalar {
mod bounded_generic_scalar {
use super::*;
#[graphql_scalar(scalar = S: ScalarValue + Clone, parse_token(i32))]
#[graphql_scalar(scalar = S: ScalarValue + prelude::Clone, parse_token(i32))]
struct Counter(i32);
impl Counter {
@ -1061,7 +1067,7 @@ mod bounded_generic_scalar {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))

View file

@ -15,6 +15,10 @@ use self::common::{
MyScalarValue,
};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod all_custom_resolvers {
use super::*;
@ -33,7 +37,7 @@ mod all_custom_resolvers {
Value::scalar(v.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -114,7 +118,9 @@ mod explicit_name {
Value::scalar(v.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<CounterScalar, String> {
fn from_input<S: ScalarValue>(
v: &InputValue<S>,
) -> prelude::Result<CounterScalar, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -214,7 +220,7 @@ mod delegated_parse_token {
Value::scalar(v.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -278,14 +284,14 @@ mod multiple_delegated_parse_token {
use super::*;
enum StringOrIntScalar {
String(String),
String(prelude::String),
Int(i32),
}
#[graphql_scalar(
to_output_with = to_output,
from_input_with = from_input,
parse_token(String, i32),
parse_token(prelude::String, i32),
)]
type StringOrInt = StringOrIntScalar;
@ -296,7 +302,9 @@ mod multiple_delegated_parse_token {
}
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<StringOrInt, String> {
fn from_input<S: ScalarValue>(
v: &InputValue<S>,
) -> prelude::Result<StringOrInt, prelude::String> {
v.as_string_value()
.map(|s| StringOrInt::String(s.to_owned()))
.or_else(|| v.as_int_value().map(StringOrInt::Int))
@ -345,7 +353,7 @@ mod where_attribute {
#[graphql_scalar(
to_output_with = to_output,
from_input_with = from_input,
parse_token(String),
parse_token(prelude::String),
where(Tz: From<Utc> + TimeZone, Tz::Offset: fmt::Display),
specified_by_url = "https://tools.ietf.org/html/rfc3339",
)]
@ -360,7 +368,7 @@ mod where_attribute {
Value::scalar(v.0.to_rfc3339())
}
fn from_input<S, Tz>(v: &InputValue<S>) -> Result<CustomDateTime<Tz>, String>
fn from_input<S, Tz>(v: &InputValue<S>) -> prelude::Result<CustomDateTime<Tz>, prelude::String>
where
S: ScalarValue,
Tz: From<Utc> + TimeZone,
@ -432,7 +440,7 @@ mod with_self {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -504,7 +512,7 @@ mod with_module {
#[graphql_scalar(
with = custom_date_time,
parse_token(String),
parse_token(prelude::String),
where(Tz: From<Utc> + TimeZone, Tz::Offset: fmt::Display),
specified_by_url = "https://tools.ietf.org/html/rfc3339",
)]
@ -522,7 +530,9 @@ mod with_module {
Value::scalar(v.0.to_rfc3339())
}
pub(super) fn from_input<S, Tz>(v: &InputValue<S>) -> Result<CustomDateTime<Tz>, String>
pub(super) fn from_input<S, Tz>(
v: &InputValue<S>,
) -> prelude::Result<CustomDateTime<Tz>, prelude::String>
where
S: ScalarValue,
Tz: From<Utc> + TimeZone,
@ -598,7 +608,9 @@ mod description_from_doc_comment {
Value::scalar(v.0)
}
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
pub(super) fn from_input<S: ScalarValue>(
v: &InputValue<S>,
) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -682,7 +694,9 @@ mod description_from_attribute {
Value::scalar(v.0)
}
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
pub(super) fn from_input<S: ScalarValue>(
v: &InputValue<S>,
) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -766,7 +780,9 @@ mod custom_scalar {
Value::scalar(v.0)
}
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
pub(super) fn from_input<S: ScalarValue>(
v: &InputValue<S>,
) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -850,7 +866,9 @@ mod generic_scalar {
Value::scalar(v.0)
}
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
pub(super) fn from_input<S: ScalarValue>(
v: &InputValue<S>,
) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -921,7 +939,7 @@ mod bounded_generic_scalar {
/// Description
#[graphql_scalar(
scalar = S: ScalarValue + Clone,
scalar = S: ScalarValue + prelude::Clone,
with = counter,
parse_token(i32),
)]
@ -934,7 +952,9 @@ mod bounded_generic_scalar {
Value::scalar(v.0)
}
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
pub(super) fn from_input<S: ScalarValue>(
v: &InputValue<S>,
) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(CustomCounter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))

View file

@ -15,6 +15,10 @@ use self::common::{
MyScalarValue,
};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod trivial {
use super::*;
@ -26,7 +30,7 @@ mod trivial {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -234,7 +238,7 @@ mod all_custom_resolvers {
Value::scalar(v.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Counter, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Counter, prelude::String> {
v.as_int_value()
.map(Counter)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -310,7 +314,7 @@ mod explicit_name {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -387,7 +391,7 @@ mod delegated_parse_token {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -452,9 +456,9 @@ mod multiple_delegated_parse_token {
use super::*;
#[derive(GraphQLScalar)]
#[graphql(parse_token(String, i32))]
#[graphql(parse_token(prelude::String, i32))]
enum StringOrInt {
String(String),
String(prelude::String),
Int(i32),
}
@ -466,7 +470,7 @@ mod multiple_delegated_parse_token {
}
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_string_value()
.map(|s| Self::String(s.to_owned()))
.or_else(|| v.as_int_value().map(Self::Int))
@ -515,7 +519,7 @@ mod where_attribute {
#[graphql(
to_output_with = to_output,
from_input_with = from_input,
parse_token(String),
parse_token(prelude::String),
where(Tz: From<Utc>, Tz::Offset: fmt::Display),
specified_by_url = "https://tools.ietf.org/html/rfc3339",
)]
@ -530,7 +534,7 @@ mod where_attribute {
Value::scalar(v.0.to_rfc3339())
}
fn from_input<S, Tz>(v: &InputValue<S>) -> Result<CustomDateTime<Tz>, String>
fn from_input<S, Tz>(v: &InputValue<S>) -> prelude::Result<CustomDateTime<Tz>, prelude::String>
where
S: ScalarValue,
Tz: From<Utc> + TimeZone,
@ -601,7 +605,7 @@ mod with_self {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -672,7 +676,7 @@ mod with_module {
#[derive(GraphQLScalar)]
#[graphql(
with = custom_date_time,
parse_token(String),
parse_token(prelude::String),
where(Tz: From<Utc>, Tz::Offset: fmt::Display),
specified_by_url = "https://tools.ietf.org/html/rfc3339",
)]
@ -690,7 +694,9 @@ mod with_module {
Value::scalar(v.0.to_rfc3339())
}
pub(super) fn from_input<S, Tz>(v: &InputValue<S>) -> Result<CustomDateTime<Tz>, String>
pub(super) fn from_input<S, Tz>(
v: &InputValue<S>,
) -> prelude::Result<CustomDateTime<Tz>, prelude::String>
where
S: ScalarValue,
Tz: From<Utc> + TimeZone,
@ -763,7 +769,7 @@ mod description_from_doc_comment {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -840,7 +846,7 @@ mod description_from_attribute {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -917,7 +923,7 @@ mod custom_scalar {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -994,7 +1000,7 @@ mod generic_scalar {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `Counter`, found: {v}"))
@ -1062,7 +1068,7 @@ mod bounded_generic_scalar {
use super::*;
#[derive(GraphQLScalar)]
#[graphql(scalar = S: ScalarValue + Clone, parse_token(i32))]
#[graphql(scalar = S: ScalarValue + prelude::Clone, parse_token(i32))]
struct Counter(i32);
impl Counter {
@ -1070,7 +1076,7 @@ mod bounded_generic_scalar {
Value::scalar(self.0)
}
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<Self, String> {
fn from_input<S: ScalarValue>(v: &InputValue<S>) -> prelude::Result<Self, prelude::String> {
v.as_int_value()
.map(Self)
.ok_or_else(|| format!("Expected `String`, found: {v}"))

View file

@ -1,8 +1,14 @@
//! Tests for `#[derive(ScalarValue)]` macro.
pub mod common;
use juniper::{DefaultScalarValue, ScalarValue};
use serde::{Deserialize, Serialize};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
mod trivial {
use super::*;
@ -14,7 +20,7 @@ mod trivial {
#[value(as_float)]
Float(f64),
#[value(as_str, as_string, into_string)]
String(String),
String(prelude::String),
#[value(as_bool)]
Boolean(bool),
}
@ -29,7 +35,7 @@ mod trivial {
.is_type::<f64>());
assert!(CustomScalarValue::from("str".to_owned())
.into_another::<DefaultScalarValue>()
.is_type::<String>());
.is_type::<prelude::String>());
assert!(CustomScalarValue::from(true)
.into_another::<DefaultScalarValue>()
.is_type::<bool>());
@ -47,7 +53,7 @@ mod named_fields {
#[value(as_float)]
Float(f64),
#[value(as_str, as_string, into_string)]
String(String),
String(prelude::String),
#[value(as_bool)]
Boolean { v: bool },
}
@ -62,7 +68,7 @@ mod named_fields {
.is_type::<f64>());
assert!(CustomScalarValue::from("str".to_owned())
.into_another::<DefaultScalarValue>()
.is_type::<String>());
.is_type::<prelude::String>());
assert!(CustomScalarValue::from(true)
.into_another::<DefaultScalarValue>()
.is_type::<bool>());
@ -84,7 +90,7 @@ mod custom_fn {
as_string = str::to_owned,
into_string = std::convert::identity,
)]
String(String),
String(prelude::String),
#[value(as_bool)]
Boolean(bool),
}
@ -99,7 +105,7 @@ mod custom_fn {
.is_type::<f64>());
assert!(CustomScalarValue::from("str".to_owned())
.into_another::<DefaultScalarValue>()
.is_type::<String>());
.is_type::<prelude::String>());
assert!(CustomScalarValue::from(true)
.into_another::<DefaultScalarValue>()
.is_type::<bool>());
@ -117,7 +123,7 @@ mod allow_missing_attributes {
#[value(as_float)]
Float(f64),
#[value(as_str, as_string, into_string)]
String(String),
String(prelude::String),
#[value(as_bool)]
Boolean(bool),
}
@ -130,7 +136,7 @@ mod allow_missing_attributes {
.is_type::<f64>());
assert!(CustomScalarValue::from("str".to_owned())
.into_another::<DefaultScalarValue>()
.is_type::<String>());
.is_type::<prelude::String>());
assert!(CustomScalarValue::from(true)
.into_another::<DefaultScalarValue>()
.is_type::<bool>());

View file

@ -13,6 +13,10 @@ use juniper::{
use self::common::util::extract_next;
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
struct Query;
#[graphql_object]
@ -45,7 +49,7 @@ where
RootNode::new_with_scalar_value(query_root, EmptyMutation::<C>::new(), subscription_root)
}
type Stream<'a, I> = Pin<Box<dyn futures::Stream<Item = I> + Send + 'a>>;
type Stream<'a, I> = Pin<prelude::Box<dyn futures::Stream<Item = I> + prelude::Send + 'a>>;
mod trivial {
use super::*;
@ -54,13 +58,13 @@ mod trivial {
#[graphql_subscription]
impl Human {
async fn id() -> Stream<'static, String> {
Box::pin(stream::once(future::ready("human-32".into())))
async fn id() -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready("human-32".into())))
}
// TODO: Make work for `Stream<'_, String>`.
async fn home_planet(&self) -> Stream<'static, String> {
Box::pin(stream::once(future::ready("earth".into())))
// TODO: Make work for `Stream<'_, prelude::String>`.
async fn home_planet(&self) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready("earth".into())))
}
}
@ -153,11 +157,11 @@ mod raw_method {
#[graphql_subscription]
impl Human {
async fn r#my_id() -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
async fn r#async(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("async-32")))
prelude::Box::pin(stream::once(future::ready("async-32")))
}
}
@ -228,8 +232,8 @@ mod ignored_method {
#[graphql_subscription]
impl Human {
async fn id() -> Stream<'static, String> {
Box::pin(stream::once(future::ready("human-32".into())))
async fn id() -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready("human-32".into())))
}
#[allow(dead_code)]
@ -292,12 +296,14 @@ mod fallible_method {
#[graphql_subscription]
impl Human {
async fn id(&self) -> Result<Stream<'static, String>, CustomError> {
Ok(Box::pin(stream::once(future::ready("human-32".into()))))
async fn id(&self) -> prelude::Result<Stream<'static, prelude::String>, CustomError> {
Ok(prelude::Box::pin(stream::once(future::ready(
"human-32".into(),
))))
}
async fn home_planet<__S>() -> FieldResult<Stream<'static, &'static str>, __S> {
Ok(Box::pin(stream::once(future::ready("earth"))))
Ok(prelude::Box::pin(stream::once(future::ready("earth"))))
}
}
@ -380,16 +386,16 @@ mod argument {
#[graphql_subscription]
impl Human {
async fn id(arg: String) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(arg)))
async fn id(arg: prelude::String) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(arg)))
}
async fn home_planet(
&self,
r#raw_arg: String,
r#async: Option<i32>,
) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(format!("{raw_arg},{async:?}"))))
r#raw_arg: prelude::String,
r#async: prelude::Option<i32>,
) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(format!("{raw_arg},{async:?}"))))
}
}
@ -520,14 +526,14 @@ mod default_argument {
async fn id(
&self,
#[graphql(default)] arg1: i32,
#[graphql(default = "second".to_string())] arg2: String,
#[graphql(default = "second".to_string())] arg2: prelude::String,
#[graphql(default = true)] r#arg3: bool,
) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(format!("{arg1}|{arg2}&{arg3}"))))
) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(format!("{arg1}|{arg2}&{arg3}"))))
}
async fn info(#[graphql(default = Point { x: 1 })] coord: Point) -> Stream<'static, i32> {
Box::pin(stream::once(future::ready(coord.x)))
prelude::Box::pin(stream::once(future::ready(coord.x)))
}
}
@ -631,16 +637,16 @@ mod generic {
}
#[graphql_subscription]
impl<B: ?Sized + Sync> Human<i32, B> {
impl<B: ?Sized + prelude::Sync> Human<i32, B> {
async fn id(&self) -> Stream<'static, i32> {
Box::pin(stream::once(future::ready(self.id)))
prelude::Box::pin(stream::once(future::ready(self.id)))
}
}
#[graphql_subscription(name = "HumanString")]
impl<B: ?Sized + Sync> Human<String, B> {
async fn id(&self) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(self.id.clone())))
impl<B: ?Sized + prelude::Sync> Human<prelude::String, B> {
async fn id(&self) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(self.id.clone())))
}
}
@ -722,25 +728,25 @@ mod generic_lifetime {
#[graphql_subscription]
impl<'p> Human<'p, i32> {
async fn id(&self) -> Stream<'static, i32> {
Box::pin(stream::once(future::ready(self.id)))
prelude::Box::pin(stream::once(future::ready(self.id)))
}
// TODO: Make it work with `Stream<'_, &str>`.
async fn planet(&self) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(self.home_planet.into())))
async fn planet(&self) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(self.home_planet.into())))
}
}
#[graphql_subscription(name = "HumanString")]
impl<'id, 'p> Human<'p, &'id str> {
// TODO: Make it work with `Stream<'_, &str>`.
async fn id(&self) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(self.id.into())))
async fn id(&self) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(self.id.into())))
}
// TODO: Make it work with `Stream<'_, &str>`.
async fn planet(&self) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(self.home_planet.into())))
async fn planet(&self) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(self.home_planet.into())))
}
}
@ -866,7 +872,7 @@ mod description_from_doc_comment {
/// Rust `id` docs.
/// Here.
async fn id() -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
}
@ -904,17 +910,17 @@ mod deprecation_from_attr {
#[graphql_subscription]
impl Human {
async fn id() -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
#[deprecated]
async fn a(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("a")))
prelude::Box::pin(stream::once(future::ready("a")))
}
#[deprecated(note = "Use `id`.")]
async fn b(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("b")))
prelude::Box::pin(stream::once(future::ready("b")))
}
}
@ -1031,19 +1037,19 @@ mod explicit_name_description_and_deprecation {
#[graphql(name = "myId", desc = "My human ID.", deprecated = "Not used.")]
#[deprecated(note = "Should be omitted.")]
async fn id(
#[graphql(name = "myName", desc = "My argument.", default)] _n: String,
#[graphql(name = "myName", desc = "My argument.", default)] _n: prelude::String,
) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
#[graphql(deprecated)]
#[deprecated(note = "Should be omitted.")]
async fn a(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("a")))
prelude::Box::pin(stream::once(future::ready("a")))
}
async fn b(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("b")))
prelude::Box::pin(stream::once(future::ready("b")))
}
}
@ -1214,15 +1220,18 @@ mod renamed_all_fields_and_args {
#[graphql_subscription(rename_all = "none")]
impl Human {
async fn id() -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
async fn home_planet(&self, planet_name: String) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(planet_name)))
async fn home_planet(
&self,
planet_name: prelude::String,
) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(planet_name)))
}
async fn r#async_info(r#my_num: i32) -> Stream<'static, i32> {
Box::pin(stream::once(future::ready(r#my_num)))
prelude::Box::pin(stream::once(future::ready(r#my_num)))
}
}
@ -1311,11 +1320,11 @@ mod explicit_scalar {
#[graphql_subscription(scalar = DefaultScalarValue)]
impl Human {
async fn id(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
async fn home_planet() -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("earth")))
prelude::Box::pin(stream::once(future::ready("earth")))
}
}
@ -1362,11 +1371,11 @@ mod custom_scalar {
#[graphql_subscription(scalar = MyScalarValue)]
impl Human {
async fn id(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
async fn home_planet() -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("earth")))
prelude::Box::pin(stream::once(future::ready("earth")))
}
}
@ -1413,11 +1422,11 @@ mod explicit_generic_scalar {
#[graphql_subscription(scalar = S)]
impl<S: ScalarValue> Human<S> {
async fn id(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
async fn home_planet(_executor: &Executor<'_, '_, (), S>) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("earth")))
prelude::Box::pin(stream::once(future::ready("earth")))
}
}
@ -1459,16 +1468,16 @@ mod bounded_generic_scalar {
struct Human;
#[graphql_subscription(scalar = S: ScalarValue + Clone)]
#[graphql_subscription(scalar = S: ScalarValue + prelude::Clone)]
impl Human {
async fn id(&self) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human-32")))
prelude::Box::pin(stream::once(future::ready("human-32")))
}
async fn home_planet<S>(
_executor: &Executor<'_, '_, (), S>,
) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("earth")))
prelude::Box::pin(stream::once(future::ready("earth")))
}
}
@ -1508,7 +1517,7 @@ mod bounded_generic_scalar {
mod explicit_custom_context {
use super::*;
struct CustomContext(String);
struct CustomContext(prelude::String);
impl juniper::Context for CustomContext {}
@ -1525,18 +1534,20 @@ mod explicit_custom_context {
#[graphql_subscription(context = CustomContext)]
impl Human {
// TODO: Make work for `Stream<'c, String>`.
async fn id<'c>(&self, context: &'c CustomContext) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(context.0.clone())))
// TODO: Make work for `Stream<'c, prelude::String>`.
async fn id<'c>(&self, context: &'c CustomContext) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(context.0.clone())))
}
// TODO: Make work for `Stream<'_, String>`.
// TODO: Make work for `Stream<'_, prelude::String>`.
async fn info(_ctx: &()) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human being")))
prelude::Box::pin(stream::once(future::ready("human being")))
}
async fn more(#[graphql(context)] custom: &CustomContext) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(custom.0.clone())))
async fn more(
#[graphql(context)] custom: &CustomContext,
) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(custom.0.clone())))
}
}
@ -1595,7 +1606,7 @@ mod explicit_custom_context {
mod inferred_custom_context_from_field {
use super::*;
struct CustomContext(String);
struct CustomContext(prelude::String);
impl juniper::Context for CustomContext {}
@ -1612,18 +1623,20 @@ mod inferred_custom_context_from_field {
#[graphql_subscription]
impl Human {
// TODO: Make work for `Stream<'c, String>`.
async fn id<'c>(&self, context: &'c CustomContext) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(context.0.clone())))
// TODO: Make work for `Stream<'c, prelude::String>`.
async fn id<'c>(&self, context: &'c CustomContext) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(context.0.clone())))
}
// TODO: Make work for `Stream<'_, String>`.
// TODO: Make work for `Stream<'_, prelude::String>`.
async fn info(_ctx: &()) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("human being")))
prelude::Box::pin(stream::once(future::ready("human being")))
}
async fn more(#[graphql(context)] custom: &CustomContext) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(custom.0.clone())))
async fn more(
#[graphql(context)] custom: &CustomContext,
) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(custom.0.clone())))
}
}
@ -1689,28 +1702,31 @@ mod executor {
#[graphql_subscription(scalar = S: ScalarValue)]
impl Human {
// TODO: Make work for `Stream<'e, &'e str>`.
async fn id<'e, S>(&self, executor: &'e Executor<'_, '_, (), S>) -> Stream<'static, String>
async fn id<'e, S>(
&self,
executor: &'e Executor<'_, '_, (), S>,
) -> Stream<'static, prelude::String>
where
S: ScalarValue,
{
Box::pin(stream::once(future::ready(
prelude::Box::pin(stream::once(future::ready(
executor.look_ahead().field_name().into(),
)))
}
async fn info<S>(
&self,
arg: String,
arg: prelude::String,
#[graphql(executor)] _another: &Executor<'_, '_, (), S>,
) -> Stream<'static, String> {
Box::pin(stream::once(future::ready(arg)))
) -> Stream<'static, prelude::String> {
prelude::Box::pin(stream::once(future::ready(arg)))
}
// TODO: Make work for `Stream<'e, &'e str>`.
async fn info2<'e, S>(
_executor: &'e Executor<'_, '_, (), S>,
) -> Stream<'static, &'static str> {
Box::pin(stream::once(future::ready("no info")))
prelude::Box::pin(stream::once(future::ready("no info")))
}
}

View file

@ -9,21 +9,25 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
#[derive(GraphQLObject)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[derive(GraphQLObject)]
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[derive(GraphQLObject)]
struct Ewok {
id: String,
id: prelude::String,
funny: bool,
}
@ -37,21 +41,21 @@ impl juniper::Context for CustomContext {}
#[derive(GraphQLObject)]
#[graphql(context = CustomContext)]
pub struct HumanCustomContext {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(context = CustomContext)]
pub struct DroidCustomContext {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(context = CustomContext)]
struct EwokCustomContext {
id: String,
id: prelude::String,
funny: bool,
}
@ -60,27 +64,27 @@ mod trivial {
#[graphql_union]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
None
}
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
impl Character for Droid {
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
enum QueryRoot {
Human,
@ -89,13 +93,13 @@ mod trivial {
#[graphql_object]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
let ch: Box<DynCharacter<'_>> = match self {
Self::Human => Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
let ch: prelude::Box<DynCharacter<'_>> = match self {
Self::Human => prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
}),
Self::Droid => Box::new(Droid {
Self::Droid => prelude::Box::new(Droid {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -197,27 +201,27 @@ mod generic {
#[graphql_union]
trait Character<A, B> {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
None
}
}
impl<A, B> Character<A, B> for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
impl<A, B> Character<A, B> for Droid {
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
Some(self)
}
}
type DynCharacter<'a, A, B> = dyn Character<A, B> + Send + Sync + 'a;
type DynCharacter<'a, A, B> = dyn Character<A, B> + prelude::Send + prelude::Sync + 'a;
enum QueryRoot {
Human,
@ -226,13 +230,13 @@ mod generic {
#[graphql_object]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_, u8, ()>> {
let ch: Box<DynCharacter<'_, u8, ()>> = match self {
Self::Human => Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_, u8, ()>> {
let ch: prelude::Box<DynCharacter<'_, u8, ()>> = match self {
Self::Human => prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
}),
Self::Droid => Box::new(Droid {
Self::Droid => prelude::Box::new(Droid {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -303,25 +307,25 @@ mod description_from_doc_comment {
/// Rust docs.
#[graphql_union]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
struct QueryRoot;
#[graphql_object]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
})
@ -376,25 +380,25 @@ mod explicit_name_and_description {
/// Rust docs.
#[graphql_union(name = "MyChar", desc = "My character.")]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
struct QueryRoot;
#[graphql_object]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
})
@ -464,27 +468,27 @@ mod explicit_scalar {
#[graphql_union(scalar = DefaultScalarValue)]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
None
}
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
impl Character for Droid {
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
enum QueryRoot {
Human,
@ -493,13 +497,13 @@ mod explicit_scalar {
#[graphql_object(scalar = DefaultScalarValue)]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
let ch: Box<DynCharacter<'_>> = match self {
Self::Human => Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
let ch: prelude::Box<DynCharacter<'_>> = match self {
Self::Human => prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
}),
Self::Droid => Box::new(Droid {
Self::Droid => prelude::Box::new(Droid {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -555,27 +559,27 @@ mod custom_scalar {
#[graphql_union(scalar = MyScalarValue)]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
None
}
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
impl Character for Droid {
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
enum QueryRoot {
Human,
@ -584,13 +588,13 @@ mod custom_scalar {
#[graphql_object(scalar = MyScalarValue)]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
let ch: Box<DynCharacter<'_>> = match self {
Self::Human => Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
let ch: prelude::Box<DynCharacter<'_>> = match self {
Self::Human => prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
}),
Self::Droid => Box::new(Droid {
Self::Droid => prelude::Box::new(Droid {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -644,27 +648,27 @@ mod explicit_generic_scalar {
#[graphql_union(scalar = S)]
trait Character<S: ScalarValue> {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
None
}
}
impl<S: ScalarValue> Character<S> for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
impl<S: ScalarValue> Character<S> for Droid {
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
Some(self)
}
}
type DynCharacter<'a, S> = dyn Character<S> + Send + Sync + 'a;
type DynCharacter<'a, S> = dyn Character<S> + prelude::Send + prelude::Sync + 'a;
enum QueryRoot {
Human,
@ -673,13 +677,13 @@ mod explicit_generic_scalar {
#[graphql_object]
impl QueryRoot {
fn character<__S: ScalarValue>(&self) -> Box<DynCharacter<'_, __S>> {
let ch: Box<DynCharacter<'_, _>> = match self {
Self::Human => Box::new(Human {
fn character<__S: ScalarValue>(&self) -> prelude::Box<DynCharacter<'_, __S>> {
let ch: prelude::Box<DynCharacter<'_, _>> = match self {
Self::Human => prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
}),
Self::Droid => Box::new(Droid {
Self::Droid => prelude::Box::new(Droid {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -731,29 +735,29 @@ mod explicit_generic_scalar {
mod bounded_generic_scalar {
use super::*;
#[graphql_union(scalar = S: ScalarValue + Clone)]
#[graphql_union(scalar = S: ScalarValue + prelude::Clone)]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
None
}
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
impl Character for Droid {
fn as_droid(&self) -> Option<&Droid> {
fn as_droid(&self) -> prelude::Option<&Droid> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
enum QueryRoot {
Human,
@ -762,13 +766,13 @@ mod bounded_generic_scalar {
#[graphql_object]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
let ch: Box<DynCharacter<'_>> = match self {
Self::Human => Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
let ch: prelude::Box<DynCharacter<'_>> = match self {
Self::Human => prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
}),
Self::Droid => Box::new(Droid {
Self::Droid => prelude::Box::new(Droid {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -822,39 +826,39 @@ mod explicit_custom_context {
#[graphql_union(context = CustomContext)]
trait Character {
fn as_human(&self) -> Option<&HumanCustomContext> {
fn as_human(&self) -> prelude::Option<&HumanCustomContext> {
None
}
fn as_droid(&self) -> Option<&DroidCustomContext> {
fn as_droid(&self) -> prelude::Option<&DroidCustomContext> {
None
}
}
impl Character for HumanCustomContext {
fn as_human(&self) -> Option<&HumanCustomContext> {
fn as_human(&self) -> prelude::Option<&HumanCustomContext> {
Some(self)
}
}
impl Character for DroidCustomContext {
fn as_droid(&self) -> Option<&DroidCustomContext> {
fn as_droid(&self) -> prelude::Option<&DroidCustomContext> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
struct QueryRoot;
#[graphql_object(context = CustomContext)]
impl QueryRoot {
fn character(&self, ctx: &CustomContext) -> Box<DynCharacter<'_>> {
let ch: Box<DynCharacter<'_>> = match ctx {
CustomContext::Human => Box::new(HumanCustomContext {
fn character(&self, ctx: &CustomContext) -> prelude::Box<DynCharacter<'_>> {
let ch: prelude::Box<DynCharacter<'_>> = match ctx {
CustomContext::Human => prelude::Box::new(HumanCustomContext {
id: "human-32".into(),
home_planet: "earth".into(),
}),
CustomContext::Droid => Box::new(DroidCustomContext {
CustomContext::Droid => prelude::Box::new(DroidCustomContext {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -909,39 +913,39 @@ mod inferred_custom_context {
#[graphql_union]
trait Character {
fn as_human(&self, _: &CustomContext) -> Option<&HumanCustomContext> {
fn as_human(&self, _: &CustomContext) -> prelude::Option<&HumanCustomContext> {
None
}
fn as_droid(&self, _: &()) -> Option<&DroidCustomContext> {
fn as_droid(&self, _: &()) -> prelude::Option<&DroidCustomContext> {
None
}
}
impl Character for HumanCustomContext {
fn as_human(&self, _: &CustomContext) -> Option<&HumanCustomContext> {
fn as_human(&self, _: &CustomContext) -> prelude::Option<&HumanCustomContext> {
Some(self)
}
}
impl Character for DroidCustomContext {
fn as_droid(&self, _: &()) -> Option<&DroidCustomContext> {
fn as_droid(&self, _: &()) -> prelude::Option<&DroidCustomContext> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
struct QueryRoot;
#[graphql_object(context = CustomContext)]
impl QueryRoot {
fn character(&self, ctx: &CustomContext) -> Box<DynCharacter<'_>> {
let ch: Box<DynCharacter<'_>> = match ctx {
CustomContext::Human => Box::new(HumanCustomContext {
fn character(&self, ctx: &CustomContext) -> prelude::Box<DynCharacter<'_>> {
let ch: prelude::Box<DynCharacter<'_>> = match ctx {
CustomContext::Human => prelude::Box::new(HumanCustomContext {
id: "human-32".into(),
home_planet: "earth".into(),
}),
CustomContext::Droid => Box::new(DroidCustomContext {
CustomContext::Droid => prelude::Box::new(DroidCustomContext {
id: "droid-99".into(),
primary_function: "run".into(),
}),
@ -996,11 +1000,11 @@ mod ignored_method {
#[graphql_union]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
#[graphql(ignore)]
fn ignored(&self) -> Option<&Ewok> {
fn ignored(&self) -> prelude::Option<&Ewok> {
None
}
#[graphql(skip)]
@ -1008,19 +1012,19 @@ mod ignored_method {
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
struct QueryRoot;
#[graphql_object]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
})
@ -1077,29 +1081,29 @@ mod external_resolver {
#[graphql_union(context = Database)]
#[graphql_union(on Droid = DynCharacter::as_droid)]
trait Character {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
None
}
}
impl Character for Human {
fn as_human(&self) -> Option<&Human> {
fn as_human(&self) -> prelude::Option<&Human> {
Some(self)
}
}
impl Character for Droid {}
type DynCharacter<'a> = dyn Character + Send + Sync + 'a;
type DynCharacter<'a> = dyn Character + prelude::Send + prelude::Sync + 'a;
impl<'a> DynCharacter<'a> {
fn as_droid<'db>(&self, db: &'db Database) -> Option<&'db Droid> {
fn as_droid<'db>(&self, db: &'db Database) -> prelude::Option<&'db Droid> {
db.droid.as_ref()
}
}
struct Database {
droid: Option<Droid>,
droid: prelude::Option<Droid>,
}
impl juniper::Context for Database {}
@ -1110,13 +1114,13 @@ mod external_resolver {
#[graphql_object(context = Database)]
impl QueryRoot {
fn character(&self) -> Box<DynCharacter<'_>> {
let ch: Box<DynCharacter<'_>> = match self {
Self::Human => Box::new(Human {
fn character(&self) -> prelude::Box<DynCharacter<'_>> {
let ch: prelude::Box<DynCharacter<'_>> = match self {
Self::Human => prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
}),
Self::Droid => Box::new(Droid {
Self::Droid => prelude::Box::new(Droid {
id: "?????".into(),
primary_function: "???".into(),
}),
@ -1181,14 +1185,14 @@ mod full_featured {
#[graphql_union(context = CustomContext, scalar = DefaultScalarValue)]
#[graphql_union(on EwokCustomContext = resolve_ewok)]
trait Character<T> {
fn as_human(&self, _: &()) -> Option<&HumanCustomContext> {
fn as_human(&self, _: &()) -> prelude::Option<&HumanCustomContext> {
None
}
fn as_droid(&self) -> Option<&DroidCustomContext> {
fn as_droid(&self) -> prelude::Option<&DroidCustomContext> {
None
}
#[graphql(ignore)]
fn as_ewok(&self) -> Option<&EwokCustomContext> {
fn as_ewok(&self) -> prelude::Option<&EwokCustomContext> {
None
}
#[graphql(ignore)]
@ -1196,29 +1200,29 @@ mod full_featured {
}
impl<T> Character<T> for HumanCustomContext {
fn as_human(&self, _: &()) -> Option<&HumanCustomContext> {
fn as_human(&self, _: &()) -> prelude::Option<&HumanCustomContext> {
Some(self)
}
}
impl<T> Character<T> for DroidCustomContext {
fn as_droid(&self) -> Option<&DroidCustomContext> {
fn as_droid(&self) -> prelude::Option<&DroidCustomContext> {
Some(self)
}
}
impl<T> Character<T> for EwokCustomContext {
fn as_ewok(&self) -> Option<&EwokCustomContext> {
fn as_ewok(&self) -> prelude::Option<&EwokCustomContext> {
Some(self)
}
}
type DynCharacter<'a, T> = dyn Character<T> + Send + Sync + 'a;
type DynCharacter<'a, T> = dyn Character<T> + prelude::Send + prelude::Sync + 'a;
fn resolve_ewok<'a, T>(
ewok: &'a DynCharacter<'a, T>,
_: &CustomContext,
) -> Option<&'a EwokCustomContext> {
) -> prelude::Option<&'a EwokCustomContext> {
ewok.as_ewok()
}
@ -1226,17 +1230,17 @@ mod full_featured {
#[graphql_object(context = CustomContext, scalar = DefaultScalarValue)]
impl QueryRoot {
fn character(&self, ctx: &CustomContext) -> Box<DynCharacter<'_, ()>> {
let ch: Box<DynCharacter<'_, ()>> = match ctx {
CustomContext::Human => Box::new(HumanCustomContext {
fn character(&self, ctx: &CustomContext) -> prelude::Box<DynCharacter<'_, ()>> {
let ch: prelude::Box<DynCharacter<'_, ()>> = match ctx {
CustomContext::Human => prelude::Box::new(HumanCustomContext {
id: "human-32".into(),
home_planet: "earth".into(),
}),
CustomContext::Droid => Box::new(DroidCustomContext {
CustomContext::Droid => prelude::Box::new(DroidCustomContext {
id: "droid-99".into(),
primary_function: "run".into(),
}),
CustomContext::Ewok => Box::new(EwokCustomContext {
CustomContext::Ewok => prelude::Box::new(EwokCustomContext {
id: "ewok-1".into(),
funny: true,
}),

View file

@ -2,8 +2,6 @@
pub mod common;
use std::marker::PhantomData;
use juniper::{
execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, GraphQLObject,
GraphQLUnion, ScalarValue,
@ -11,21 +9,25 @@ use juniper::{
use self::common::util::{schema, schema_with_scalar};
// Override `std::prelude` items to check whether macros expand hygienically.
#[allow(unused_imports)]
use self::common::hygiene::*;
#[derive(GraphQLObject)]
struct Human {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[derive(GraphQLObject)]
struct Droid {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[derive(GraphQLObject)]
struct Ewok {
id: String,
id: prelude::String,
funny: bool,
}
@ -39,21 +41,21 @@ impl juniper::Context for CustomContext {}
#[derive(GraphQLObject)]
#[graphql(context = CustomContext)]
pub struct HumanCustomContext {
id: String,
home_planet: String,
id: prelude::String,
home_planet: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(context = CustomContext)]
pub struct DroidCustomContext {
id: String,
primary_function: String,
id: prelude::String,
primary_function: prelude::String,
}
#[derive(GraphQLObject)]
#[graphql(context = CustomContext)]
struct EwokCustomContext {
id: String,
id: prelude::String,
funny: bool,
}
@ -274,9 +276,9 @@ mod generic_lifetime_enum {
#[derive(GraphQLObject)]
struct GenericDroid<B = ()> {
id: String,
id: prelude::String,
#[graphql(ignore)]
_t: PhantomData<B>,
_t: std::marker::PhantomData<B>,
}
#[derive(GraphQLUnion)]
@ -297,7 +299,7 @@ mod generic_lifetime_enum {
Self::Human => Character::A(LifetimeHuman { id: "human-32" }),
Self::Droid => Character::B(GenericDroid {
id: "droid-99".into(),
_t: PhantomData,
_t: std::marker::PhantomData,
}),
}
}
@ -654,7 +656,7 @@ mod explicit_generic_scalar {
A(Human),
B(Droid),
#[graphql(ignore)]
_P(PhantomData<S>),
_P(std::marker::PhantomData<S>),
}
enum QueryRoot {
@ -722,7 +724,7 @@ mod bounded_generic_scalar {
use super::*;
#[derive(GraphQLUnion)]
#[graphql(scalar = S: ScalarValue + Clone)]
#[graphql(scalar = S: ScalarValue + prelude::Clone)]
enum Character {
A(Human),
B(Droid),
@ -1008,7 +1010,7 @@ mod external_resolver_enum {
}
impl Character {
fn as_droid<'db>(&self, db: &'db Database) -> Option<&'db Droid> {
fn as_droid<'db>(&self, db: &'db Database) -> prelude::Option<&'db Droid> {
if let Self::B = self {
db.droid.as_ref()
} else {
@ -1018,7 +1020,7 @@ mod external_resolver_enum {
}
struct Database {
droid: Option<Droid>,
droid: prelude::Option<Droid>,
}
impl juniper::Context for Database {}
@ -1099,7 +1101,7 @@ mod external_resolver_enum_variant {
}
impl Character {
fn as_droid<'db>(&self, db: &'db Database) -> Option<&'db Droid> {
fn as_droid<'db>(&self, db: &'db Database) -> prelude::Option<&'db Droid> {
if let Self::B(_) = self {
db.droid.as_ref()
} else {
@ -1109,7 +1111,7 @@ mod external_resolver_enum_variant {
}
struct Database {
droid: Option<Droid>,
droid: prelude::Option<Droid>,
}
impl juniper::Context for Database {}
@ -1201,7 +1203,7 @@ mod full_featured_enum {
}
impl<T> Character<T> {
fn as_droid(&self, ctx: &CustomContext) -> Option<&DroidCustomContext> {
fn as_droid(&self, ctx: &CustomContext) -> prelude::Option<&DroidCustomContext> {
if let CustomContext::Droid = ctx {
if let Self::B(droid) = self {
return Some(droid);
@ -1214,7 +1216,7 @@ mod full_featured_enum {
fn resolve_ewok<'a, T>(
ewok: &'a Character<T>,
_: &CustomContext,
) -> Option<&'a EwokCustomContext> {
) -> prelude::Option<&'a EwokCustomContext> {
if let Character::C(ewok) = ewok {
Some(ewok)
} else {
@ -1346,11 +1348,11 @@ mod trivial_struct {
on Droid = Character::as_droid,
)]
struct Character {
id: String,
id: prelude::String,
}
impl Character {
fn as_human<'db>(&self, db: &'db Database) -> Option<&'db Human> {
fn as_human<'db>(&self, db: &'db Database) -> prelude::Option<&'db Human> {
if let Some(human) = &db.human {
if human.id == self.id {
return Some(human);
@ -1359,7 +1361,7 @@ mod trivial_struct {
None
}
fn as_droid<'db>(&self, db: &'db Database) -> Option<&'db Droid> {
fn as_droid<'db>(&self, db: &'db Database) -> prelude::Option<&'db Droid> {
if let Some(droid) = &db.droid {
if droid.id == self.id {
return Some(droid);
@ -1370,8 +1372,8 @@ mod trivial_struct {
}
struct Database {
human: Option<Human>,
droid: Option<Droid>,
human: prelude::Option<Human>,
droid: prelude::Option<Droid>,
}
impl juniper::Context for Database {}
@ -1523,12 +1525,12 @@ mod generic_struct {
#[graphql(context = Database)]
#[graphql(on Human = Character::as_human)]
struct Character<A, B> {
id: String,
_s: PhantomData<(A, B)>,
id: prelude::String,
_s: std::marker::PhantomData<(A, B)>,
}
impl<A, B> Character<A, B> {
fn as_human<'db>(&self, db: &'db Database) -> Option<&'db Human> {
fn as_human<'db>(&self, db: &'db Database) -> prelude::Option<&'db Human> {
if let Some(human) = &db.human {
if human.id == self.id {
return Some(human);
@ -1539,7 +1541,7 @@ mod generic_struct {
}
struct Database {
human: Option<Human>,
human: prelude::Option<Human>,
}
impl juniper::Context for Database {}
@ -1550,7 +1552,7 @@ mod generic_struct {
fn character(&self) -> Character<u8, ()> {
Character {
id: "human-32".into(),
_s: PhantomData,
_s: std::marker::PhantomData,
}
}
}
@ -1612,12 +1614,12 @@ mod full_featured_struct {
#[graphql(on Human = Character::as_human)]
#[graphql(on Droid = Character::as_droid)]
struct Character<T> {
id: String,
_s: PhantomData<T>,
id: prelude::String,
_s: std::marker::PhantomData<T>,
}
impl<T> Character<T> {
fn as_human<'db>(&self, db: &'db Database) -> Option<&'db Human> {
fn as_human<'db>(&self, db: &'db Database) -> prelude::Option<&'db Human> {
if let Some(human) = &db.human {
if human.id == self.id {
return Some(human);
@ -1628,7 +1630,7 @@ mod full_featured_struct {
}
impl<T> Character<T> {
fn as_droid<'db>(&self, db: &'db Database) -> Option<&'db Droid> {
fn as_droid<'db>(&self, db: &'db Database) -> prelude::Option<&'db Droid> {
if let Some(droid) = &db.droid {
if droid.id == self.id {
return Some(droid);
@ -1639,8 +1641,8 @@ mod full_featured_struct {
}
struct Database {
human: Option<Human>,
droid: Option<Droid>,
human: prelude::Option<Human>,
droid: prelude::Option<Droid>,
}
impl juniper::Context for Database {}
@ -1658,7 +1660,7 @@ mod full_featured_struct {
Self::Droid => "droid-99",
}
.into(),
_s: PhantomData,
_s: std::marker::PhantomData,
}
}
}
@ -1769,7 +1771,7 @@ mod issue_845 {
#[derive(GraphQLUnion)]
enum Character {
A(Box<Human>),
A(prelude::Box<Human>),
B(Arc<Droid>),
}
@ -1782,7 +1784,7 @@ mod issue_845 {
impl QueryRoot {
fn character(&self) -> Character {
match self {
Self::Human => Character::A(Box::new(Human {
Self::Human => Character::A(prelude::Box::new(Human {
id: "human-32".into(),
home_planet: "earth".into(),
})),

View file

@ -145,3 +145,32 @@ impl<'de> Deserialize<'de> for MyScalarValue {
de.deserialize_any(Visitor)
}
}
/// Definitions shadowing [`std::prelude`] items to check whether macro expansion is hygienic.
pub mod hygiene {
pub use std::prelude::rust_2021 as prelude;
pub trait Debug {}
pub trait Display {}
pub struct Box<T>(T);
pub trait Clone {}
pub trait Copy {}
pub trait Future {}
pub struct Option<T>(T);
pub struct PhantomData<T>(T);
pub struct Result<Ok, Err>(Ok, Err);
pub trait Send {}
pub struct String;
pub trait Sync {}
}