Remove all attribute macros that can be replaced by derive.

This commit is contained in:
Sunli 2020-09-13 11:41:15 +08:00
parent b8add03d53
commit 24b80d52d3
67 changed files with 382 additions and 644 deletions

View File

@ -73,7 +73,7 @@ lazy_static::lazy_static! {
pub struct Chat; pub struct Chat;
#[Object] #[GQLObject]
impl Chat { impl Chat {
pub async fn id(&self) -> ID { pub async fn id(&self) -> ID {
ID::from(&CHAT.id) ID::from(&CHAT.id)
@ -116,7 +116,7 @@ impl Chat {
pub struct Message; pub struct Message;
#[Object] #[GQLObject]
impl Message { impl Message {
pub async fn id(&self) -> ID { pub async fn id(&self) -> ID {
ID::from(&MESSAGE.id) ID::from(&MESSAGE.id)
@ -141,7 +141,7 @@ impl Message {
pub struct User; pub struct User;
#[Object] #[GQLObject]
impl User { impl User {
pub async fn id(&self) -> ID { pub async fn id(&self) -> ID {
ID::from(&USER.id) ID::from(&USER.id)
@ -169,7 +169,7 @@ impl User {
pub struct UserProfile; pub struct UserProfile;
#[Object] #[GQLObject]
impl UserProfile { impl UserProfile {
pub async fn email(&self) -> &String { pub async fn email(&self) -> &String {
&PROFILE.email &PROFILE.email
@ -193,7 +193,7 @@ impl UserProfile {
pub struct Query; pub struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn chats(&self) -> Vec<Chat> { async fn chats(&self) -> Vec<Chat> {
let mut res = vec![]; let mut res = vec![];

View File

@ -2,7 +2,7 @@ use async_graphql::*;
pub struct QueryRoot; pub struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
#[field] #[field]
async fn value_i32(&self) -> i32 { async fn value_i32(&self) -> i32 {
@ -17,7 +17,7 @@ impl QueryRoot {
pub struct MyObj; pub struct MyObj;
#[Object] #[GQLObject]
impl MyObj { impl MyObj {
#[field] #[field]
async fn value_i32(&self) -> i32 { async fn value_i32(&self) -> i32 {

View File

@ -17,15 +17,14 @@ mod subscription;
mod union; mod union;
mod utils; mod utils;
use crate::utils::{add_container_attrs, parse_derive}; use crate::utils::parse_derive;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::quote;
use syn::parse_macro_input; use syn::parse_macro_input;
use syn::{AttributeArgs, ItemImpl}; use syn::{AttributeArgs, ItemImpl};
#[proc_macro_attribute] #[proc_macro_attribute]
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn Object(args: TokenStream, input: TokenStream) -> TokenStream { pub fn GQLObject(args: TokenStream, input: TokenStream) -> TokenStream {
let object_args = match args::Object::parse(parse_macro_input!(args as AttributeArgs)) { let object_args = match args::Object::parse(parse_macro_input!(args as AttributeArgs)) {
Ok(object_args) => object_args, Ok(object_args) => object_args,
Err(err) => return err.to_compile_error().into(), Err(err) => return err.to_compile_error().into(),
@ -37,18 +36,6 @@ pub fn Object(args: TokenStream, input: TokenStream) -> TokenStream {
} }
} }
#[proc_macro_attribute]
#[allow(non_snake_case)]
pub fn SimpleObject(args: TokenStream, input: TokenStream) -> TokenStream {
add_container_attrs(
quote!(GQLSimpleObject),
parse_macro_input!(args as AttributeArgs),
input.into(),
)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
#[proc_macro_derive(GQLSimpleObject, attributes(field, graphql))] #[proc_macro_derive(GQLSimpleObject, attributes(field, graphql))]
pub fn derive_simple_object(input: TokenStream) -> TokenStream { pub fn derive_simple_object(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) { let (args, input) = match parse_derive(input.into()) {
@ -65,18 +52,6 @@ pub fn derive_simple_object(input: TokenStream) -> TokenStream {
} }
} }
#[proc_macro_attribute]
#[allow(non_snake_case)]
pub fn Enum(args: TokenStream, input: TokenStream) -> TokenStream {
add_container_attrs(
quote!(GQLEnum, Copy, Clone, Eq, PartialEq),
parse_macro_input!(args as AttributeArgs),
input.into(),
)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
#[proc_macro_derive(GQLEnum, attributes(item, graphql))] #[proc_macro_derive(GQLEnum, attributes(item, graphql))]
pub fn derive_enum(input: TokenStream) -> TokenStream { pub fn derive_enum(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) { let (args, input) = match parse_derive(input.into()) {
@ -93,18 +68,6 @@ pub fn derive_enum(input: TokenStream) -> TokenStream {
} }
} }
#[proc_macro_attribute]
#[allow(non_snake_case)]
pub fn InputObject(args: TokenStream, input: TokenStream) -> TokenStream {
add_container_attrs(
quote!(GQLInputObject),
parse_macro_input!(args as AttributeArgs),
input.into(),
)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
#[proc_macro_derive(GQLInputObject, attributes(field, graphql))] #[proc_macro_derive(GQLInputObject, attributes(field, graphql))]
pub fn derive_input_object(input: TokenStream) -> TokenStream { pub fn derive_input_object(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) { let (args, input) = match parse_derive(input.into()) {
@ -121,18 +84,6 @@ pub fn derive_input_object(input: TokenStream) -> TokenStream {
} }
} }
#[proc_macro_attribute]
#[allow(non_snake_case)]
pub fn Interface(args: TokenStream, input: TokenStream) -> TokenStream {
add_container_attrs(
quote!(GQLInterface),
parse_macro_input!(args as AttributeArgs),
input.into(),
)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
#[proc_macro_derive(GQLInterface, attributes(graphql))] #[proc_macro_derive(GQLInterface, attributes(graphql))]
pub fn derive_interface(input: TokenStream) -> TokenStream { pub fn derive_interface(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) { let (args, input) = match parse_derive(input.into()) {
@ -149,18 +100,6 @@ pub fn derive_interface(input: TokenStream) -> TokenStream {
} }
} }
#[proc_macro_attribute]
#[allow(non_snake_case)]
pub fn Union(args: TokenStream, input: TokenStream) -> TokenStream {
add_container_attrs(
quote!(GQLUnion),
parse_macro_input!(args as AttributeArgs),
input.into(),
)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
#[proc_macro_derive(GQLUnion, attributes(graphql))] #[proc_macro_derive(GQLUnion, attributes(graphql))]
pub fn derive_union(input: TokenStream) -> TokenStream { pub fn derive_union(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) { let (args, input) = match parse_derive(input.into()) {
@ -179,7 +118,7 @@ pub fn derive_union(input: TokenStream) -> TokenStream {
#[proc_macro_attribute] #[proc_macro_attribute]
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn Subscription(args: TokenStream, input: TokenStream) -> TokenStream { pub fn GQLSubscription(args: TokenStream, input: TokenStream) -> TokenStream {
let object_args = match args::Object::parse(parse_macro_input!(args as AttributeArgs)) { let object_args = match args::Object::parse(parse_macro_input!(args as AttributeArgs)) {
Ok(object_args) => object_args, Ok(object_args) => object_args,
Err(err) => return err.to_compile_error().into(), Err(err) => return err.to_compile_error().into(),
@ -193,7 +132,7 @@ pub fn Subscription(args: TokenStream, input: TokenStream) -> TokenStream {
#[proc_macro_attribute] #[proc_macro_attribute]
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn Scalar(args: TokenStream, input: TokenStream) -> TokenStream { pub fn GQLScalar(args: TokenStream, input: TokenStream) -> TokenStream {
let scalar_args = match args::Scalar::parse(parse_macro_input!(args as AttributeArgs)) { let scalar_args = match args::Scalar::parse(parse_macro_input!(args as AttributeArgs)) {
Ok(scalar_args) => scalar_args, Ok(scalar_args) => scalar_args,
Err(err) => return err.to_compile_error().into(), Err(err) => return err.to_compile_error().into(),
@ -205,18 +144,6 @@ pub fn Scalar(args: TokenStream, input: TokenStream) -> TokenStream {
} }
} }
#[proc_macro_attribute]
#[allow(non_snake_case)]
pub fn MergedObject(args: TokenStream, input: TokenStream) -> TokenStream {
add_container_attrs(
quote!(GQLMergedObject),
parse_macro_input!(args as AttributeArgs),
input.into(),
)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
#[proc_macro_derive(GQLMergedObject, attributes(item, graphql))] #[proc_macro_derive(GQLMergedObject, attributes(item, graphql))]
pub fn derive_merged_object(input: TokenStream) -> TokenStream { pub fn derive_merged_object(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) { let (args, input) = match parse_derive(input.into()) {
@ -233,18 +160,6 @@ pub fn derive_merged_object(input: TokenStream) -> TokenStream {
} }
} }
#[proc_macro_attribute]
#[allow(non_snake_case)]
pub fn MergedSubscription(args: TokenStream, input: TokenStream) -> TokenStream {
add_container_attrs(
quote!(GQLMergedObject),
parse_macro_input!(args as AttributeArgs),
input.into(),
)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
#[proc_macro_derive(GQLMergedSubscription, attributes(item, graphql))] #[proc_macro_derive(GQLMergedSubscription, attributes(item, graphql))]
pub fn derive_merged_subscription(input: TokenStream) -> TokenStream { pub fn derive_merged_subscription(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) { let (args, input) = match parse_derive(input.into()) {

View File

@ -2,10 +2,7 @@ use itertools::Itertools;
use proc_macro2::{Span, TokenStream, TokenTree}; use proc_macro2::{Span, TokenStream, TokenTree};
use proc_macro_crate::crate_name; use proc_macro_crate::crate_name;
use quote::quote; use quote::quote;
use syn::{ use syn::{Attribute, DeriveInput, Error, Expr, Ident, Lit, Meta, MetaList, NestedMeta, Result};
Attribute, AttributeArgs, DeriveInput, Error, Expr, Ident, Lit, Meta, MetaList, NestedMeta,
Result,
};
pub fn get_crate_name(internal: bool) -> TokenStream { pub fn get_crate_name(internal: bool) -> TokenStream {
if internal { if internal {
@ -16,27 +13,6 @@ pub fn get_crate_name(internal: bool) -> TokenStream {
} }
} }
pub fn add_container_attrs(
derive: TokenStream,
container_attrs: AttributeArgs,
item: TokenStream,
) -> Result<TokenStream> {
let internal = container_attrs.iter().any(|meta| {
if let NestedMeta::Meta(Meta::Path(p)) = meta {
p.is_ident("internal")
} else {
false
}
});
let crate_name = get_crate_name(internal);
let expanded = quote! {
#[derive(#crate_name::#derive)]
#[graphql(#(#container_attrs),*)]
#item
};
Ok(expanded)
}
pub fn parse_derive(input: TokenStream) -> Result<(proc_macro::TokenStream, DeriveInput)> { pub fn parse_derive(input: TokenStream) -> Result<(proc_macro::TokenStream, DeriveInput)> {
let mut input: DeriveInput = syn::parse2(input)?; let mut input: DeriveInput = syn::parse2(input)?;
let attrs = &mut input.attrs; let attrs = &mut input.attrs;

View File

@ -18,7 +18,7 @@ fn quickstart() -> Result<()> {
use tide::{http::StatusCode, Request, Response}; use tide::{http::StatusCode, Request, Response};
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
#[field(desc = "Returns the sum of a and b")] #[field(desc = "Returns the sum of a and b")]
async fn add(&self, a: i32, b: i32) -> i32 { async fn add(&self, a: i32, b: i32) -> i32 {
@ -99,7 +99,7 @@ fn hello() -> Result<()> {
struct Hello(String); struct Hello(String);
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
#[field(desc = "Returns hello")] #[field(desc = "Returns hello")]
async fn hello<'a>(&self, ctx: &'a Context<'_>) -> String { async fn hello<'a>(&self, ctx: &'a Context<'_>) -> String {
@ -194,18 +194,17 @@ fn upload() -> Result<()> {
use tide::Request; use tide::Request;
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
#[async_graphql::SimpleObject] #[derive(Clone, GQLSimpleObject)]
#[derive(Clone)]
pub struct FileInfo { pub struct FileInfo {
filename: String, filename: String,
mime_type: Option<String>, mime_type: Option<String>,
} }
struct MutationRoot; struct MutationRoot;
#[Object] #[GQLObject]
impl MutationRoot { impl MutationRoot {
async fn single_upload(&self, file: Upload) -> FileInfo { async fn single_upload(&self, file: Upload) -> FileInfo {
println!("single_upload: filename={}", file.filename()); println!("single_upload: filename={}", file.filename());

View File

@ -63,7 +63,7 @@ pub trait InputObjectType: InputValueType {}
/// ///
/// struct MyInt(i32); /// struct MyInt(i32);
/// ///
/// #[Scalar] /// #[GQLScalar]
/// impl ScalarType for MyInt { /// impl ScalarType for MyInt {
/// fn parse(value: Value) -> InputValueResult<Self> { /// fn parse(value: Value) -> InputValueResult<Self> {
/// if let Value::Number(n) = &value { /// if let Value::Number(n) = &value {

View File

@ -487,13 +487,13 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
/// ```no_run /// ```no_run
/// use async_graphql::*; /// use async_graphql::*;
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct Detail { /// struct Detail {
/// c: i32, /// c: i32,
/// d: i32, /// d: i32,
/// } /// }
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct MyObj { /// struct MyObj {
/// a: i32, /// a: i32,
/// b: i32, /// b: i32,
@ -502,7 +502,7 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
/// ///
/// struct Query; /// struct Query;
/// ///
/// #[Object] /// #[GQLObject]
/// impl Query { /// impl Query {
/// async fn obj(&self, ctx: &Context<'_>) -> MyObj { /// async fn obj(&self, ctx: &Context<'_>) -> MyObj {
/// if ctx.look_ahead().field("a").exists() { /// if ctx.look_ahead().field("a").exists() {

View File

@ -229,7 +229,7 @@ pub use types::{EnumItem, EnumType};
/// You can define a context as an argument to a method, and the context should be the first argument to the method. /// You can define a context as an argument to a method, and the context should be the first argument to the method.
/// ///
/// ```ignore /// ```ignore
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// async fn value(&self, ctx: &Context<'_>) -> { ... } /// async fn value(&self, ctx: &Context<'_>) -> { ... }
/// } /// }
@ -244,7 +244,7 @@ pub use types::{EnumItem, EnumType};
/// value: i32, /// value: i32,
/// } /// }
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// #[field(desc = "value")] /// #[field(desc = "value")]
/// async fn value(&self) -> i32 { /// async fn value(&self) -> i32 {
@ -284,7 +284,7 @@ pub use types::{EnumItem, EnumType};
/// })); /// }));
/// }); /// });
/// ``` /// ```
pub use async_graphql_derive::Object; pub use async_graphql_derive::GQLObject;
/// Define a GraphQL object with fields /// Define a GraphQL object with fields
/// ///
@ -322,7 +322,7 @@ pub use async_graphql_derive::Object;
/// ```rust /// ```rust
/// use async_graphql::*; /// use async_graphql::*;
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct QueryRoot { /// struct QueryRoot {
/// value: i32, /// value: i32,
/// } /// }
@ -335,64 +335,6 @@ pub use async_graphql_derive::Object;
/// })); /// }));
/// }); /// });
/// ``` /// ```
pub use async_graphql_derive::SimpleObject;
/// Derive a GraphQL enum
///
/// You can also [use an attribute](attr.Enum.html).
///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/define_enum.html).*
///
/// All variants are converted to SCREAMING_SNAKE_CASE.
///
/// # Examples
///
/// ```rust
/// use async_graphql::*;
///
/// #[derive(GQLEnum, Eq, PartialEq, Copy, Clone)]
/// #[graphql(name = "Enum1")]
/// enum MyEnum {
/// One,
/// Two,
/// }
/// ```
pub use async_graphql_derive::GQLEnum;
/// Derive a GraphQL input object
///
/// You can also [use an attribute](attr.InputObject.html).
///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/define_input_object.html).*
///
/// # Examples
///
/// ```rust
/// use async_graphql::*;
/// #[derive(GQLInputObject)]
/// #[graphql(name = "MyInput1")]
/// struct MyInput {
/// value: i32,
/// }
/// ```
pub use async_graphql_derive::GQLInputObject;
/// Derive a GraphQL object with fields
///
/// You can also [use an attribute](attr.SimpleObject.html).
///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/define_simple_object.html).*
///
/// # Examples
///
/// ```rust
/// use async_graphql::*;
/// #[derive(GQLSimpleObject)]
/// #[graphql(name = "MyObj1")]
/// struct MyObj {
/// value: i32,
/// }
/// ```
pub use async_graphql_derive::GQLSimpleObject; pub use async_graphql_derive::GQLSimpleObject;
/// Define a GraphQL enum /// Define a GraphQL enum
@ -421,7 +363,7 @@ pub use async_graphql_derive::GQLSimpleObject;
/// ```rust /// ```rust
/// use async_graphql::*; /// use async_graphql::*;
/// ///
/// #[Enum] /// #[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
/// enum MyEnum { /// enum MyEnum {
/// A, /// A,
/// #[item(name = "b")] B, /// #[item(name = "b")] B,
@ -432,7 +374,7 @@ pub use async_graphql_derive::GQLSimpleObject;
/// value2: MyEnum, /// value2: MyEnum,
/// } /// }
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// #[field(desc = "value")] /// #[field(desc = "value")]
/// async fn value1(&self) -> MyEnum { /// async fn value1(&self) -> MyEnum {
@ -451,7 +393,7 @@ pub use async_graphql_derive::GQLSimpleObject;
/// assert_eq!(res, serde_json::json!({ "value1": "A", "value2": "b" })); /// assert_eq!(res, serde_json::json!({ "value1": "A", "value2": "b" }));
/// }); /// });
/// ``` /// ```
pub use async_graphql_derive::Enum; pub use async_graphql_derive::GQLEnum;
/// Define a GraphQL input object /// Define a GraphQL input object
/// ///
@ -484,7 +426,7 @@ pub use async_graphql_derive::Enum;
/// ```rust /// ```rust
/// use async_graphql::*; /// use async_graphql::*;
/// ///
/// #[InputObject] /// #[derive(GQLInputObject)]
/// struct MyInputObject { /// struct MyInputObject {
/// a: i32, /// a: i32,
/// #[field(default = 10)] /// #[field(default = 10)]
@ -493,7 +435,7 @@ pub use async_graphql_derive::Enum;
/// ///
/// struct QueryRoot; /// struct QueryRoot;
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// #[field(desc = "value")] /// #[field(desc = "value")]
/// async fn value(&self, input: MyInputObject) -> i32 { /// async fn value(&self, input: MyInputObject) -> i32 {
@ -511,7 +453,7 @@ pub use async_graphql_derive::Enum;
/// assert_eq!(res, serde_json::json!({ "value1": 27, "value2": 90 })); /// assert_eq!(res, serde_json::json!({ "value1": 27, "value2": 90 }));
/// }); /// });
/// ``` /// ```
pub use async_graphql_derive::InputObject; pub use async_graphql_derive::GQLInputObject;
/// Define a GraphQL interface /// Define a GraphQL interface
/// ///
@ -553,7 +495,7 @@ pub use async_graphql_derive::InputObject;
/// Define TypeA, TypeB, TypeC... Implement the MyInterface /// Define TypeA, TypeB, TypeC... Implement the MyInterface
/// ///
/// ```ignore /// ```ignore
/// #[Interface] /// #[derive(GQLInterface)]
/// enum MyInterface { /// enum MyInterface {
/// TypeA(TypeA), /// TypeA(TypeA),
/// TypeB(TypeB), /// TypeB(TypeB),
@ -574,7 +516,7 @@ pub use async_graphql_derive::InputObject;
/// value: i32, /// value: i32,
/// } /// }
/// ///
/// #[Object] /// #[GQLObject]
/// impl TypeA { /// impl TypeA {
/// /// Returns data borrowed from the context /// /// Returns data borrowed from the context
/// async fn value_a<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<&'a str> { /// async fn value_a<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<&'a str> {
@ -598,7 +540,8 @@ pub use async_graphql_derive::InputObject;
/// } /// }
/// } /// }
/// ///
/// #[Interface( /// #[derive(GQLInterface)]
/// #[graphql(
/// field(name = "value_a", type = "&'ctx str"), /// field(name = "value_a", type = "&'ctx str"),
/// field(name = "value_b", type = "&i32"), /// field(name = "value_b", type = "&i32"),
/// field(name = "value_c", type = "i32", /// field(name = "value_c", type = "i32",
@ -612,7 +555,7 @@ pub use async_graphql_derive::InputObject;
/// ///
/// struct QueryRoot; /// struct QueryRoot;
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// async fn type_a(&self) -> MyInterface { /// async fn type_a(&self) -> MyInterface {
/// TypeA { value: 10 }.into() /// TypeA { value: 10 }.into()
@ -640,13 +583,6 @@ pub use async_graphql_derive::InputObject;
/// })); /// }));
/// }); /// });
/// ``` /// ```
pub use async_graphql_derive::Interface;
/// Derive a GraphQL interface
///
/// You can also [use an attribute](attr.Interface.html).
///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/define_interface.html).*
pub use async_graphql_derive::GQLInterface; pub use async_graphql_derive::GQLInterface;
/// Define a GraphQL union /// Define a GraphQL union
@ -669,17 +605,17 @@ pub use async_graphql_derive::GQLInterface;
/// ```rust /// ```rust
/// use async_graphql::*; /// use async_graphql::*;
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct TypeA { /// struct TypeA {
/// value_a: i32, /// value_a: i32,
/// } /// }
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct TypeB { /// struct TypeB {
/// value_b: i32 /// value_b: i32
/// } /// }
/// ///
/// #[Union] /// #[derive(GQLUnion)]
/// enum MyUnion { /// enum MyUnion {
/// TypeA(TypeA), /// TypeA(TypeA),
/// TypeB(TypeB), /// TypeB(TypeB),
@ -687,7 +623,7 @@ pub use async_graphql_derive::GQLInterface;
/// ///
/// struct QueryRoot; /// struct QueryRoot;
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// async fn all_data(&self) -> Vec<MyUnion> { /// async fn all_data(&self) -> Vec<MyUnion> {
/// vec![TypeA { value_a: 10 }.into(), TypeB { value_b: 20 }.into()] /// vec![TypeA { value_a: 10 }.into(), TypeB { value_b: 20 }.into()]
@ -715,13 +651,6 @@ pub use async_graphql_derive::GQLInterface;
/// })); /// }));
/// }); /// });
/// ``` /// ```
pub use async_graphql_derive::Union;
/// Derive a GraphQL union
///
/// You can also [use an attribute](attr.Union.html).
///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/define_union.html).*
pub use async_graphql_derive::GQLUnion; pub use async_graphql_derive::GQLUnion;
/// Define a GraphQL subscription /// Define a GraphQL subscription
@ -763,25 +692,21 @@ pub use async_graphql_derive::GQLUnion;
/// ///
/// # Examples /// # Examples
/// ///
/// ```ignore /// ```rust
/// use async_graphql::*; /// use async_graphql::*;
/// /// use futures::{Stream, StreamExt};
/// #[Object]
/// struct Event {
/// value: i32,
/// }
/// ///
/// struct SubscriptionRoot; /// struct SubscriptionRoot;
/// ///
/// #[Subscription] /// #[GQLSubscription]
/// impl SubscriptionRoot { /// impl SubscriptionRoot {
/// async fn value(&self, event: &Event, condition: i32) -> bool { /// async fn value(&self, condition: i32) -> impl Stream<Item = i32> {
/// // Push when value is greater than condition /// // Returns the number from 0 to `condition`.
/// event.value > condition /// futures::stream::iter(0..condition)
/// } /// }
/// } /// }
/// ``` /// ```
pub use async_graphql_derive::Subscription; pub use async_graphql_derive::GQLSubscription;
/// Define a Scalar /// Define a Scalar
/// ///
@ -792,7 +717,7 @@ pub use async_graphql_derive::Subscription;
/// | name | Scalar name | string | Y | /// | name | Scalar name | string | Y |
/// | desc | Scalar description | string | Y | /// | desc | Scalar description | string | Y |
/// ///
pub use async_graphql_derive::Scalar; pub use async_graphql_derive::GQLScalar;
/// Define a merged object with multiple object types. /// Define a merged object with multiple object types.
/// ///
@ -814,33 +739,26 @@ pub use async_graphql_derive::Scalar;
/// ```rust /// ```rust
/// use async_graphql::*; /// use async_graphql::*;
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct Object1 { /// struct Object1 {
/// a: i32, /// a: i32,
/// } /// }
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct Object2 { /// struct Object2 {
/// b: i32, /// b: i32,
/// } /// }
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct Object3 { /// struct Object3 {
/// c: i32, /// c: i32,
/// } /// }
/// ///
/// #[MergedObject] /// #[derive(GQLMergedObject)]
/// struct MyObj(Object1, Object2, Object3); /// struct MyObj(Object1, Object2, Object3);
/// ///
/// let obj = MyObj(Object1 { a: 10 }, Object2 { b: 20 }, Object3 { c: 30 }); /// let obj = MyObj(Object1 { a: 10 }, Object2 { b: 20 }, Object3 { c: 30 });
/// ``` /// ```
pub use async_graphql_derive::MergedObject;
/// Derive a GraphQL Merged object
///
/// You can also [use an attribute](attr.MergedObject.html).
///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/merging_objects.html).*
pub use async_graphql_derive::GQLMergedObject; pub use async_graphql_derive::GQLMergedObject;
/// Define a merged subscription with multiple subscription types. /// Define a merged subscription with multiple subscription types.
@ -865,7 +783,7 @@ pub use async_graphql_derive::GQLMergedObject;
/// #[derive(Default)] /// #[derive(Default)]
/// struct Subscription1; /// struct Subscription1;
/// ///
/// #[Subscription] /// #[GQLSubscription]
/// impl Subscription1 { /// impl Subscription1 {
/// async fn events1(&self) -> impl Stream<Item = i32> { /// async fn events1(&self) -> impl Stream<Item = i32> {
/// futures::stream::iter(0..10) /// futures::stream::iter(0..10)
@ -875,7 +793,7 @@ pub use async_graphql_derive::GQLMergedObject;
/// #[derive(Default)] /// #[derive(Default)]
/// struct Subscription2; /// struct Subscription2;
/// ///
/// #[Subscription] /// #[GQLSubscription]
/// impl Subscription2 { /// impl Subscription2 {
/// async fn events2(&self) -> impl Stream<Item = i32> { /// async fn events2(&self) -> impl Stream<Item = i32> {
/// futures::stream::iter(10..20) /// futures::stream::iter(10..20)
@ -885,11 +803,4 @@ pub use async_graphql_derive::GQLMergedObject;
/// #[derive(GQLMergedSubscription, Default)] /// #[derive(GQLMergedSubscription, Default)]
/// struct Subscription(Subscription1, Subscription2); /// struct Subscription(Subscription1, Subscription2);
/// ``` /// ```
pub use async_graphql_derive::MergedSubscription;
/// Derive a GraphQL merged subscription with multiple subscription types.
///
/// You can also [use an attribute](attr.MergedSubscription.html).
///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/merging_objects.html).*
pub use async_graphql_derive::GQLMergedSubscription; pub use async_graphql_derive::GQLMergedSubscription;

View File

@ -63,13 +63,15 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_look_ahead() { async fn test_look_ahead() {
#[SimpleObject(internal)] #[derive(GQLSimpleObject)]
#[graphql(internal)]
struct Detail { struct Detail {
c: i32, c: i32,
d: i32, d: i32,
} }
#[SimpleObject(internal)] #[derive(GQLSimpleObject)]
#[graphql(internal)]
struct MyObj { struct MyObj {
a: i32, a: i32,
b: i32, b: i32,
@ -78,7 +80,7 @@ mod tests {
struct Query; struct Query;
#[Object(internal)] #[GQLObject(internal)]
impl Query { impl Query {
async fn obj(&self, ctx: &Context<'_>, n: i32) -> MyObj { async fn obj(&self, ctx: &Context<'_>, n: i32) -> MyObj {
if ctx.look_ahead().field("a").exists() { if ctx.look_ahead().field("a").exists() {

View File

@ -1,10 +1,9 @@
use crate::model::__InputValue; use crate::model::__InputValue;
use crate::registry; use crate::{registry, GQLEnum, GQLObject};
use async_graphql_derive::{Enum, Object};
/// A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies. /// A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.
#[Enum(internal)] #[derive(Debug, GQLEnum, Copy, Clone, Eq, PartialEq)]
#[derive(Debug)] #[graphql(internal)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub enum __DirectiveLocation { pub enum __DirectiveLocation {
/// Location adjacent to a query operation. /// Location adjacent to a query operation.
@ -73,7 +72,7 @@ pub struct __Directive<'a> {
/// A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document. /// A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
// //
// In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor. // In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
#[Object(internal)] #[GQLObject(internal)]
impl<'a> __Directive<'a> { impl<'a> __Directive<'a> {
async fn name(&self) -> String { async fn name(&self) -> String {
self.directive.name.to_string() self.directive.name.to_string()

View File

@ -1,5 +1,4 @@
use crate::registry; use crate::{registry, GQLObject};
use async_graphql_derive::Object;
pub struct __EnumValue<'a> { pub struct __EnumValue<'a> {
pub registry: &'a registry::Registry, pub registry: &'a registry::Registry,
@ -7,7 +6,7 @@ pub struct __EnumValue<'a> {
} }
/// One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string. /// One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.
#[Object(internal)] #[GQLObject(internal)]
impl<'a> __EnumValue<'a> { impl<'a> __EnumValue<'a> {
async fn name(&self) -> String { async fn name(&self) -> String {
self.value.name.to_string() self.value.name.to_string()

View File

@ -1,6 +1,5 @@
use crate::model::{__InputValue, __Type}; use crate::model::{__InputValue, __Type};
use crate::registry; use crate::{registry, GQLObject};
use async_graphql_derive::Object;
use itertools::Itertools; use itertools::Itertools;
pub struct __Field<'a> { pub struct __Field<'a> {
@ -9,7 +8,7 @@ pub struct __Field<'a> {
} }
/// Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type. /// Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.
#[Object(internal)] #[GQLObject(internal)]
impl<'a> __Field<'a> { impl<'a> __Field<'a> {
async fn name(&self) -> String { async fn name(&self) -> String {
self.field.name.to_string() self.field.name.to_string()

View File

@ -1,6 +1,5 @@
use crate::model::__Type; use crate::model::__Type;
use crate::registry; use crate::{registry, GQLObject};
use async_graphql_derive::Object;
pub struct __InputValue<'a> { pub struct __InputValue<'a> {
pub registry: &'a registry::Registry, pub registry: &'a registry::Registry,
@ -8,7 +7,7 @@ pub struct __InputValue<'a> {
} }
/// Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value. /// Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.
#[Object(internal)] #[GQLObject(internal)]
impl<'a> __InputValue<'a> { impl<'a> __InputValue<'a> {
async fn name(&self) -> String { async fn name(&self) -> String {
self.input_value.name.to_string() self.input_value.name.to_string()

View File

@ -1,7 +1,8 @@
use async_graphql_derive::Enum; use crate::GQLEnum;
/// An enum describing what kind of type a given `__Type` is. /// An enum describing what kind of type a given `__Type` is.
#[Enum(internal)] #[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
#[graphql(internal)]
pub enum __TypeKind { pub enum __TypeKind {
/// Indicates this type is a scalar. /// Indicates this type is a scalar.
Scalar, Scalar,

View File

@ -1,6 +1,5 @@
use crate::model::{__Directive, __Type}; use crate::model::{__Directive, __Type};
use crate::registry; use crate::{registry, GQLObject};
use async_graphql_derive::Object;
use itertools::Itertools; use itertools::Itertools;
pub struct __Schema<'a> { pub struct __Schema<'a> {
@ -8,7 +7,7 @@ pub struct __Schema<'a> {
} }
/// A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations. /// A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.
#[Object(internal)] #[GQLObject(internal)]
impl<'a> __Schema<'a> { impl<'a> __Schema<'a> {
/// A list of all types supported by this server. /// A list of all types supported by this server.
async fn types(&self) -> Vec<__Type<'a>> { async fn types(&self) -> Vec<__Type<'a>> {

View File

@ -1,6 +1,5 @@
use crate::model::{__EnumValue, __Field, __InputValue, __TypeKind}; use crate::model::{__EnumValue, __Field, __InputValue, __TypeKind};
use crate::registry; use crate::{registry, GQLObject};
use async_graphql_derive::Object;
use itertools::Itertools; use itertools::Itertools;
enum TypeDetail<'a> { enum TypeDetail<'a> {
@ -43,7 +42,7 @@ impl<'a> __Type<'a> {
/// The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum. /// The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.
/// ///
/// Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name and description, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types. /// Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name and description, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
#[Object(internal)] #[GQLObject(internal)]
impl<'a> __Type<'a> { impl<'a> __Type<'a> {
async fn kind(&self) -> __TypeKind { async fn kind(&self) -> __TypeKind {
match &self.detail { match &self.detail {

View File

@ -118,7 +118,7 @@ pub struct MetaEnumValue {
/// ///
/// struct QueryRoot; /// struct QueryRoot;
/// ///
/// #[Object(cache_control(max_age = 60))] /// #[GQLObject(cache_control(max_age = 60))]
/// impl QueryRoot { /// impl QueryRoot {
/// #[field(cache_control(max_age = 30))] /// #[field(cache_control(max_age = 30))]
/// async fn value1(&self) -> i32 { /// async fn value1(&self) -> i32 {

View File

@ -1,5 +1,4 @@
use crate::{InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
/// Any scalar /// Any scalar
@ -9,7 +8,7 @@ use serde::de::DeserializeOwned;
pub struct Any(pub Value); pub struct Any(pub Value);
/// The `_Any` scalar is used to pass representations of entities from external services into the root `_entities` field for execution. /// The `_Any` scalar is used to pass representations of entities from external services into the root `_entities` field for execution.
#[Scalar(internal, name = "_Any")] #[GQLScalar(internal, name = "_Any")]
impl ScalarType for Any { impl ScalarType for Any {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
Ok(Self(value)) Ok(Self(value))

View File

@ -1,8 +1,7 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
/// The `Boolean` scalar type represents `true` or `false`. /// The `Boolean` scalar type represents `true` or `false`.
#[Scalar(internal, name = "Boolean")] #[GQLScalar(internal, name = "Boolean")]
impl ScalarType for bool { impl ScalarType for bool {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,9 +1,8 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use bson::{oid::ObjectId, DateTime as UtcDateTime}; use bson::{oid::ObjectId, DateTime as UtcDateTime};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
#[Scalar(internal)] #[GQLScalar(internal)]
impl ScalarType for ObjectId { impl ScalarType for ObjectId {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -17,7 +16,7 @@ impl ScalarType for ObjectId {
} }
} }
#[Scalar(internal, name = "DateTime")] #[GQLScalar(internal, name = "DateTime")]
impl ScalarType for UtcDateTime { impl ScalarType for UtcDateTime {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
DateTime::<Utc>::parse(value).map(UtcDateTime::from) DateTime::<Utc>::parse(value).map(UtcDateTime::from)

View File

@ -1,11 +1,10 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use chrono::{DateTime, FixedOffset, Local, Utc}; use chrono::{DateTime, FixedOffset, Local, Utc};
/// Implement the DateTime<FixedOffset> scalar /// Implement the DateTime<FixedOffset> scalar
/// ///
/// The input/output is a string in RFC3339 format. /// The input/output is a string in RFC3339 format.
#[Scalar(internal, name = "DateTime")] #[GQLScalar(internal, name = "DateTime")]
impl ScalarType for DateTime<FixedOffset> { impl ScalarType for DateTime<FixedOffset> {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match &value { match &value {
@ -22,7 +21,7 @@ impl ScalarType for DateTime<FixedOffset> {
/// Implement the DateTime<Local> scalar /// Implement the DateTime<Local> scalar
/// ///
/// The input/output is a string in RFC3339 format. /// The input/output is a string in RFC3339 format.
#[Scalar(internal, name = "DateTime")] #[GQLScalar(internal, name = "DateTime")]
impl ScalarType for DateTime<Local> { impl ScalarType for DateTime<Local> {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match &value { match &value {
@ -39,7 +38,7 @@ impl ScalarType for DateTime<Local> {
/// Implement the DateTime<Utc> scalar /// Implement the DateTime<Utc> scalar
/// ///
/// The input/output is a string in RFC3339 format. /// The input/output is a string in RFC3339 format.
#[Scalar(internal, name = "DateTime")] #[GQLScalar(internal, name = "DateTime")]
impl ScalarType for DateTime<Utc> { impl ScalarType for DateTime<Utc> {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match &value { match &value {

View File

@ -1,8 +1,7 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
/// The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point). /// The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point).
#[Scalar(internal, name = "Float")] #[GQLScalar(internal, name = "Float")]
impl ScalarType for f32 { impl ScalarType for f32 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -27,7 +26,7 @@ impl ScalarType for f32 {
} }
/// The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point). /// The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point).
#[Scalar(internal, name = "Float")] #[GQLScalar(internal, name = "Float")]
impl ScalarType for f64 { impl ScalarType for f64 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,5 +1,4 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
#[cfg(feature = "bson")] #[cfg(feature = "bson")]
use bson::oid::{self, ObjectId}; use bson::oid::{self, ObjectId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -81,7 +80,7 @@ impl PartialEq<&str> for ID {
} }
} }
#[Scalar(internal)] #[GQLScalar(internal)]
impl ScalarType for ID { impl ScalarType for ID {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,8 +1,7 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for i8 { impl ScalarType for i8 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -36,7 +35,7 @@ impl ScalarType for i8 {
} }
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for i16 { impl ScalarType for i16 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -70,7 +69,7 @@ impl ScalarType for i16 {
} }
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for i32 { impl ScalarType for i32 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -104,7 +103,7 @@ impl ScalarType for i32 {
} }
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for i64 { impl ScalarType for i64 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -138,7 +137,7 @@ impl ScalarType for i64 {
} }
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for u8 { impl ScalarType for u8 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -172,7 +171,7 @@ impl ScalarType for u8 {
} }
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for u16 { impl ScalarType for u16 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -206,7 +205,7 @@ impl ScalarType for u16 {
} }
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for u32 { impl ScalarType for u32 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -240,7 +239,7 @@ impl ScalarType for u32 {
} }
/// The `Int` scalar type represents non-fractional whole numeric values. /// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")] #[GQLScalar(internal, name = "Int")]
impl ScalarType for u64 { impl ScalarType for u64 {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,10 +1,9 @@
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::registry::{MetaType, Registry}; use crate::registry::{MetaType, Registry};
use crate::{ use crate::{
ContextSelectionSet, InputValueResult, OutputValueType, Positioned, Result, ScalarType, Type, ContextSelectionSet, GQLScalar, InputValueResult, OutputValueType, Positioned, Result,
Value, ScalarType, Type, Value,
}; };
use async_graphql_derive::Scalar;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::borrow::Cow; use std::borrow::Cow;
@ -38,7 +37,7 @@ impl<T> From<T> for Json<T> {
} }
/// A scalar that can represent any JSON value. /// A scalar that can represent any JSON value.
#[Scalar(internal, name = "JSON")] #[GQLScalar(internal, name = "JSON")]
impl<T: DeserializeOwned + Serialize + Send + Sync> ScalarType for Json<T> { impl<T: DeserializeOwned + Serialize + Send + Sync> ScalarType for Json<T> {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
Ok(serde_json::from_value(value.into_json()?)?) Ok(serde_json::from_value(value.into_json()?)?)
@ -118,7 +117,7 @@ mod test {
struct Query; struct Query;
#[Object(internal)] #[GQLObject(internal)]
impl Query { impl Query {
async fn obj(&self, input: Json<MyStruct>) -> Json<MyStruct> { async fn obj(&self, input: Json<MyStruct>) -> Json<MyStruct> {
input input

View File

@ -1,8 +1,7 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
#[Scalar(internal)] #[GQLScalar(internal)]
impl ScalarType for NaiveDate { impl ScalarType for NaiveDate {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -16,7 +15,7 @@ impl ScalarType for NaiveDate {
} }
} }
#[Scalar(internal)] #[GQLScalar(internal)]
impl ScalarType for NaiveTime { impl ScalarType for NaiveTime {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {
@ -30,7 +29,7 @@ impl ScalarType for NaiveTime {
} }
} }
#[Scalar(internal)] #[GQLScalar(internal)]
impl ScalarType for NaiveDateTime { impl ScalarType for NaiveDateTime {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,13 +1,12 @@
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, OutputValueType, Positioned, registry, ContextSelectionSet, GQLScalar, InputValueError, InputValueResult, OutputValueType,
Result, ScalarType, Type, Value, Positioned, Result, ScalarType, Type, Value,
}; };
use async_graphql_derive::Scalar;
use std::borrow::Cow; use std::borrow::Cow;
/// The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. /// The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
#[Scalar(internal)] #[GQLScalar(internal)]
impl ScalarType for String { impl ScalarType for String {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,8 +1,7 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use url::Url; use url::Url;
#[Scalar(internal)] #[GQLScalar(internal)]
impl ScalarType for Url { impl ScalarType for Url {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,8 +1,7 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value}; use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use uuid::Uuid; use uuid::Uuid;
#[Scalar(internal, name = "UUID")] #[GQLScalar(internal, name = "UUID")]
impl ScalarType for Uuid { impl ScalarType for Uuid {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -5,7 +5,7 @@ mod cursor;
mod edge; mod edge;
mod page_info; mod page_info;
use crate::FieldResult; use crate::{FieldResult, GQLSimpleObject};
pub use connection_type::Connection; pub use connection_type::Connection;
pub use cursor::CursorType; pub use cursor::CursorType;
pub use edge::Edge; pub use edge::Edge;
@ -14,7 +14,8 @@ pub use page_info::PageInfo;
use std::fmt::Display; use std::fmt::Display;
/// Empty additional fields /// Empty additional fields
#[async_graphql_derive::SimpleObject(internal)] #[derive(GQLSimpleObject)]
#[graphql(internal)]
pub struct EmptyFields; pub struct EmptyFields;
/// Parses the parameters and executes the query. /// Parses the parameters and executes the query.
@ -29,12 +30,12 @@ pub struct EmptyFields;
/// ///
/// struct Numbers; /// struct Numbers;
/// ///
/// #[SimpleObject] /// #[derive(GQLSimpleObject)]
/// struct Diff { /// struct Diff {
/// diff: i32, /// diff: i32,
/// } /// }
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// async fn numbers(&self, /// async fn numbers(&self,
/// after: Option<String>, /// after: Option<String>,

View File

@ -1,7 +1,8 @@
use async_graphql_derive::SimpleObject; use crate::GQLSimpleObject;
/// Information about pagination in a connection /// Information about pagination in a connection
#[SimpleObject(internal)] #[derive(GQLSimpleObject)]
#[graphql(internal)]
pub struct PageInfo { pub struct PageInfo {
/// When paginating backwards, are there more items? /// When paginating backwards, are there more items?
pub has_previous_page: bool, pub has_previous_page: bool,

View File

@ -17,7 +17,7 @@ use std::borrow::Cow;
/// ///
/// struct QueryRoot; /// struct QueryRoot;
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot {} /// impl QueryRoot {}
/// ///
/// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); /// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);

View File

@ -12,7 +12,7 @@ use std::borrow::Cow;
/// ///
/// struct Query; /// struct Query;
/// ///
/// #[Object] /// #[GQLObject]
/// impl Query { /// impl Query {
/// async fn value1(&self, input: MaybeUndefined<i32>) -> i32 { /// async fn value1(&self, input: MaybeUndefined<i32>) -> i32 {
/// if input.is_null() { /// if input.is_null() {

View File

@ -2,8 +2,9 @@ use crate::parser::types::Field;
use crate::registry::{MetaType, Registry}; use crate::registry::{MetaType, Registry};
use crate::resolver_utils::{resolve_object, ObjectType}; use crate::resolver_utils::{resolve_object, ObjectType};
use crate::{ use crate::{
CacheControl, Context, ContextSelectionSet, Error, OutputValueType, Positioned, QueryEnv, CacheControl, Context, ContextSelectionSet, Error, GQLSimpleObject, GQLSubscription,
QueryError, Response, Result, SchemaEnv, SubscriptionType, Type, OutputValueType, Positioned, QueryEnv, QueryError, Response, Result, SchemaEnv,
SubscriptionType, Type,
}; };
use futures::Stream; use futures::Stream;
use indexmap::IndexMap; use indexmap::IndexMap;
@ -133,13 +134,13 @@ where
} }
#[doc(hidden)] #[doc(hidden)]
#[async_graphql_derive::SimpleObject(internal)] #[derive(GQLSimpleObject, Default)]
#[derive(Default)] #[graphql(internal)]
pub struct MergedObjectTail; pub struct MergedObjectTail;
#[doc(hidden)] #[doc(hidden)]
#[derive(Default)] #[derive(Default)]
pub struct MergedObjectSubscriptionTail; pub struct MergedObjectSubscriptionTail;
#[async_graphql_derive::Subscription(internal)] #[GQLSubscription(internal)]
impl MergedObjectSubscriptionTail {} impl MergedObjectSubscriptionTail {}

View File

@ -3,15 +3,16 @@ use crate::parser::types::Field;
use crate::resolver_utils::{resolve_object, ObjectType}; use crate::resolver_utils::{resolve_object, ObjectType};
use crate::scalars::Any; use crate::scalars::Any;
use crate::{ use crate::{
registry, Context, ContextSelectionSet, Error, OutputValueType, Positioned, QueryError, Result, registry, Context, ContextSelectionSet, Error, GQLSimpleObject, OutputValueType, Positioned,
Type, QueryError, Result, Type,
}; };
use async_graphql_derive::SimpleObject;
use indexmap::map::IndexMap; use indexmap::map::IndexMap;
use std::borrow::Cow; use std::borrow::Cow;
/// Federation service /// Federation service
#[SimpleObject(internal, name = "_Service")] #[derive(GQLSimpleObject)]
#[graphql(internal, name = "_Service")]
struct Service { struct Service {
sdl: Option<String>, sdl: Option<String>,
} }

View File

@ -17,11 +17,11 @@ use std::io::Read;
/// *[Full Example](<https://github.com/async-graphql/examples/blob/master/models/files/src/lib.rs>)* /// *[Full Example](<https://github.com/async-graphql/examples/blob/master/models/files/src/lib.rs>)*
/// ///
/// ``` /// ```
/// use async_graphql::Upload; /// use async_graphql::*;
/// ///
/// struct MutationRoot; /// struct MutationRoot;
/// ///
/// #[async_graphql::Object] /// #[GQLObject]
/// impl MutationRoot { /// impl MutationRoot {
/// async fn upload(&self, file: Upload) -> bool { /// async fn upload(&self, file: Upload) -> bool {
/// println!("upload: filename={}", file.filename()); /// println!("upload: filename={}", file.filename());

View File

@ -7,7 +7,8 @@ use crate::validation::visitor::{visit, Visitor, VisitorContext};
use crate::*; use crate::*;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
#[InputObject(internal)] #[derive(GQLInputObject)]
#[graphql(internal)]
struct TestInput { struct TestInput {
id: i32, id: i32,
name: String, name: String,
@ -22,7 +23,8 @@ impl Default for TestInput {
} }
} }
#[Enum(internal)] #[derive(GQLEnum, Eq, PartialEq, Copy, Clone)]
#[graphql(internal)]
enum DogCommand { enum DogCommand {
Sit, Sit,
Heel, Heel,
@ -31,7 +33,7 @@ enum DogCommand {
struct Dog; struct Dog;
#[Object(internal)] #[GQLObject(internal)]
impl Dog { impl Dog {
async fn name(&self, surname: Option<bool>) -> Option<String> { async fn name(&self, surname: Option<bool>) -> Option<String> {
unimplemented!() unimplemented!()
@ -62,7 +64,8 @@ impl Dog {
} }
} }
#[Enum(internal)] #[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
#[graphql(internal)]
enum FurColor { enum FurColor {
Brown, Brown,
Black, Black,
@ -72,7 +75,7 @@ enum FurColor {
struct Cat; struct Cat;
#[Object(internal)] #[GQLObject(internal)]
impl Cat { impl Cat {
async fn name(&self, surname: Option<bool>) -> Option<String> { async fn name(&self, surname: Option<bool>) -> Option<String> {
unimplemented!() unimplemented!()
@ -95,7 +98,8 @@ impl Cat {
} }
} }
#[Union(internal)] #[derive(GQLUnion)]
#[graphql(internal)]
enum CatOrDog { enum CatOrDog {
Cat(Cat), Cat(Cat),
Dog(Dog), Dog(Dog),
@ -103,7 +107,7 @@ enum CatOrDog {
struct Human; struct Human;
#[Object(internal)] #[GQLObject(internal)]
impl Human { impl Human {
async fn name(&self, surname: Option<bool>) -> Option<String> { async fn name(&self, surname: Option<bool>) -> Option<String> {
unimplemented!() unimplemented!()
@ -124,7 +128,7 @@ impl Human {
struct Alien; struct Alien;
#[Object(internal)] #[GQLObject(internal)]
impl Alien { impl Alien {
async fn name(&self, surname: Option<bool>) -> Option<String> { async fn name(&self, surname: Option<bool>) -> Option<String> {
unimplemented!() unimplemented!()
@ -139,19 +143,22 @@ impl Alien {
} }
} }
#[Union(internal)] #[derive(GQLUnion)]
#[graphql(internal)]
enum DogOrHuman { enum DogOrHuman {
Dog(Dog), Dog(Dog),
Human(Human), Human(Human),
} }
#[Union(internal)] #[derive(GQLUnion)]
#[graphql(internal)]
enum HumanOrAlien { enum HumanOrAlien {
Human(Human), Human(Human),
Alien(Alien), Alien(Alien),
} }
#[Interface( #[derive(GQLInterface)]
#[graphql(
internal, internal,
field( field(
name = "name", name = "name",
@ -166,7 +173,8 @@ enum Being {
Alien(Alien), Alien(Alien),
} }
#[Interface( #[derive(GQLInterface)]
#[graphql(
internal, internal,
field( field(
name = "name", name = "name",
@ -179,7 +187,8 @@ enum Pet {
Cat(Cat), Cat(Cat),
} }
#[Interface( #[derive(GQLInterface)]
#[graphql(
internal, internal,
field( field(
name = "name", name = "name",
@ -191,13 +200,15 @@ enum Canine {
Dog(Dog), Dog(Dog),
} }
#[Interface(internal, field(name = "iq", type = "Option<i32>"))] #[derive(GQLInterface)]
#[graphql(internal, field(name = "iq", type = "Option<i32>"))]
enum Intelligent { enum Intelligent {
Human(Human), Human(Human),
Alien(Alien), Alien(Alien),
} }
#[InputObject(internal)] #[derive(GQLInputObject)]
#[graphql(internal)]
struct ComplexInput { struct ComplexInput {
required_field: bool, required_field: bool,
int_field: Option<i32>, int_field: Option<i32>,
@ -208,7 +219,7 @@ struct ComplexInput {
struct ComplicatedArgs; struct ComplicatedArgs;
#[Object(internal)] #[GQLObject(internal)]
impl ComplicatedArgs { impl ComplicatedArgs {
async fn int_arg_field(&self, int_arg: Option<i32>) -> Option<String> { async fn int_arg_field(&self, int_arg: Option<i32>) -> Option<String> {
unimplemented!() unimplemented!()
@ -274,7 +285,7 @@ impl ComplicatedArgs {
pub struct QueryRoot; pub struct QueryRoot;
#[Object(internal)] #[GQLObject(internal)]
impl QueryRoot { impl QueryRoot {
async fn human(&self, id: Option<ID>) -> Option<Human> { async fn human(&self, id: Option<ID>) -> Option<Human> {
unimplemented!() unimplemented!()
@ -323,7 +334,7 @@ impl QueryRoot {
pub struct MutationRoot; pub struct MutationRoot;
#[Object(internal)] #[GQLObject(internal)]
impl MutationRoot { impl MutationRoot {
async fn test_input(&self, #[arg(default)] input: TestInput) -> i32 { async fn test_input(&self, #[arg(default)] input: TestInput) -> i32 {
unimplemented!() unimplemented!()

View File

@ -22,7 +22,7 @@ pub use string_validators::{Email, StringMaxLength, StringMinLength, MAC};
/// ///
/// struct QueryRoot; /// struct QueryRoot;
/// ///
/// #[Object] /// #[GQLObject]
/// impl QueryRoot { /// impl QueryRoot {
/// // Input is email address /// // Input is email address
/// async fn value1(&self, #[arg(validator(Email))] email: String) -> i32 { /// async fn value1(&self, #[arg(validator(Email))] email: String) -> i32 {

View File

@ -6,7 +6,7 @@ pub async fn test_complexity_and_depth() {
struct MyObj; struct MyObj;
#[Object] #[GQLObject]
impl MyObj { impl MyObj {
async fn a(&self) -> i32 { async fn a(&self) -> i32 {
1 1
@ -21,7 +21,7 @@ pub async fn test_complexity_and_depth() {
} }
} }
#[Object] #[GQLObject]
impl Query { impl Query {
async fn value(&self) -> i32 { async fn value(&self) -> i32 {
1 1

View File

@ -5,17 +5,17 @@ use async_graphql::*;
pub async fn test_connection_additional_fields() { pub async fn test_connection_additional_fields() {
struct QueryRoot; struct QueryRoot;
#[SimpleObject] #[derive(GQLSimpleObject)]
struct ConnectionFields { struct ConnectionFields {
total_count: i32, total_count: i32,
} }
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Diff { struct Diff {
diff: i32, diff: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn numbers( async fn numbers(
&self, &self,

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_default_value_arg() { pub async fn test_default_value_arg() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn value1(&self, #[arg(default = 100)] input: i32) -> i32 { async fn value1(&self, #[arg(default = 100)] input: i32) -> i32 {
input input
@ -44,7 +44,7 @@ pub async fn test_default_value_arg() {
#[async_std::test] #[async_std::test]
pub async fn test_default_value_inputobject() { pub async fn test_default_value_inputobject() {
#[InputObject] #[derive(GQLInputObject)]
struct MyInput { struct MyInput {
#[field(default = 100)] #[field(default = 100)]
value1: i32, value1: i32,
@ -56,7 +56,7 @@ pub async fn test_default_value_inputobject() {
value3: i32, value3: i32,
} }
#[SimpleObject] #[derive(GQLSimpleObject)]
struct MyOutput { struct MyOutput {
value1: i32, value1: i32,
value2: i32, value2: i32,
@ -65,7 +65,7 @@ pub async fn test_default_value_inputobject() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn value(&self, input: MyInput) -> MyOutput { async fn value(&self, input: MyInput) -> MyOutput {
MyOutput { MyOutput {

View File

@ -1,67 +0,0 @@
use async_graphql::*;
#[async_std::test]
pub async fn test_derive() {
#[Enum(name = "MyEnum1")]
enum MyEnum {
#[cfg_attr(feature = "bson", item(name = "A1"))]
A,
}
// Infers the name based on Rust name
#[derive(GQLEnum, Eq, Copy, PartialEq, Clone)]
enum MyEnumDerive {
#[cfg_attr(feature = "bson", item(name = "A1"))]
A,
}
// Can be renamed with graphql(name = ..) attribute
#[derive(GQLEnum, Eq, Copy, PartialEq, Clone)]
#[graphql(name = "MyEnumDerive")]
enum MyEnumDeriveRenamed {
#[cfg_attr(feature = "bson", item(name = "A1"))]
A,
}
#[InputObject(name = "MyInputObj1")]
struct MyInputObj {
#[cfg_attr(feature = "bson", field(default))]
value: i32,
}
// Infers the name based on Rust name
#[derive(GQLInputObject)]
struct MyInputObjDerive {
#[cfg_attr(feature = "bson", field(default))]
value: i32,
}
// Can be renamed with graphql(name = ..) attribute
#[derive(GQLInputObject)]
#[graphql(name = "MyInputObjDerive")]
struct MyInputObjDeriveRenamed {
#[cfg_attr(feature = "bson", field(default))]
value: i32,
}
#[InputObject(name = "MySimpleObj1")]
struct MySimpleObj {
#[cfg_attr(feature = "bson", field(name = "value1"))]
value: i32,
}
// Infers the name based on Rust name
#[derive(GQLInputObject)]
struct MySimpleObjDerive {
#[cfg_attr(feature = "bson", field(name = "value1"))]
value: i32,
}
// Can be renamed with graphql(name = ..) attribute
#[derive(GQLInputObject)]
#[graphql(name = "MySimpleObjDerive")]
struct MySimpleObjDeriveRenamed {
#[cfg_attr(feature = "bson", field(name = "value1"))]
value: i32,
}
}

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_directive_skip() { pub async fn test_directive_skip() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
pub async fn value(&self) -> i32 { pub async fn value(&self) -> i32 {
10 10
@ -34,7 +34,7 @@ pub async fn test_directive_skip() {
pub async fn test_directive_include() { pub async fn test_directive_include() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
pub async fn value(&self) -> i32 { pub async fn value(&self) -> i32 {
10 10
@ -64,7 +64,7 @@ pub async fn test_directive_include() {
pub async fn test_directive_ifdef() { pub async fn test_directive_ifdef() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
pub async fn value1(&self) -> i32 { pub async fn value1(&self) -> i32 {
10 10
@ -73,7 +73,7 @@ pub async fn test_directive_ifdef() {
struct MutationRoot; struct MutationRoot;
#[Object] #[GQLObject]
impl MutationRoot { impl MutationRoot {
pub async fn action1(&self) -> i32 { pub async fn action1(&self) -> i32 {
10 10

View File

@ -2,13 +2,13 @@ use async_graphql::*;
#[async_std::test] #[async_std::test]
pub async fn test_enum_type() { pub async fn test_enum_type() {
#[Enum] #[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
enum MyEnum { enum MyEnum {
A, A,
B, B,
} }
#[InputObject] #[derive(GQLInputObject)]
struct MyInput { struct MyInput {
value: MyEnum, value: MyEnum,
} }
@ -17,7 +17,7 @@ pub async fn test_enum_type() {
value: MyEnum, value: MyEnum,
} }
#[Object] #[GQLObject]
impl Root { impl Root {
async fn value(&self) -> MyEnum { async fn value(&self) -> MyEnum {
self.value self.value
@ -53,8 +53,7 @@ pub async fn test_enum_type() {
pub async fn test_enum_derive_and_item_attributes() { pub async fn test_enum_derive_and_item_attributes() {
use serde::Deserialize; use serde::Deserialize;
#[async_graphql::Enum] #[derive(Deserialize, Debug, GQLEnum, Copy, Clone, Eq, PartialEq)]
#[derive(Deserialize, Debug)]
enum Test { enum Test {
#[serde(alias = "Other")] #[serde(alias = "Other")]
Real, Real,

View File

@ -6,7 +6,7 @@ struct User {
id: ID, id: ID,
} }
#[Object(extends)] #[GQLObject(extends)]
impl User { impl User {
#[field(external)] #[field(external)]
async fn id(&self) -> &ID { async fn id(&self) -> &ID {
@ -20,7 +20,7 @@ impl User {
struct Review; struct Review;
#[Object] #[GQLObject]
impl Review { impl Review {
async fn body(&self) -> String { async fn body(&self) -> String {
todo!() todo!()
@ -40,7 +40,7 @@ struct Product {
upc: String, upc: String,
} }
#[Object(extends)] #[GQLObject(extends)]
impl Product { impl Product {
#[field(external)] #[field(external)]
async fn upc(&self) -> &str { async fn upc(&self) -> &str {
@ -54,7 +54,7 @@ impl Product {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
#[entity] #[entity]
async fn find_user_by_id(&self, id: ID) -> User { async fn find_user_by_id(&self, id: ID) -> User {

View File

@ -6,7 +6,7 @@ use std::pin::Pin;
#[async_std::test] #[async_std::test]
pub async fn test_field_features() { pub async fn test_field_features() {
#[SimpleObject] #[derive(GQLSimpleObject)]
struct MyObj { struct MyObj {
value: i32, value: i32,
@ -19,7 +19,7 @@ pub async fn test_field_features() {
struct Subscription; struct Subscription;
#[Subscription] #[GQLSubscription]
impl Subscription { impl Subscription {
async fn values(&self) -> impl Stream<Item = i32> { async fn values(&self) -> impl Stream<Item = i32> {
futures::stream::once(async move { 10 }) futures::stream::once(async move { 10 })
@ -40,7 +40,7 @@ pub async fn test_field_features() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn value(&self) -> i32 { async fn value(&self) -> i32 {
10 10

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_fieldresult() { pub async fn test_fieldresult() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn error(&self) -> FieldResult<i32> { async fn error(&self) -> FieldResult<i32> {
Err("TestError".into()) Err("TestError".into())

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_field_merge() { pub async fn test_field_merge() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn value1(&self) -> i32 { async fn value1(&self) -> i32 {
1 1
@ -43,7 +43,7 @@ pub async fn test_field_merge() {
#[async_std::test] #[async_std::test]
pub async fn test_field_object_merge() { pub async fn test_field_object_merge() {
#[SimpleObject] #[derive(GQLSimpleObject)]
struct MyObject { struct MyObject {
a: i32, a: i32,
b: i32, b: i32,
@ -52,7 +52,7 @@ pub async fn test_field_object_merge() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn obj(&self) -> MyObject { async fn obj(&self) -> MyObject {
MyObject { a: 1, b: 2, c: 3 } MyObject { a: 1, b: 2, c: 3 }

View File

@ -42,7 +42,7 @@ impl Guard for UserGuard {
#[async_std::test] #[async_std::test]
pub async fn test_guard() { pub async fn test_guard() {
#[SimpleObject] #[derive(GQLSimpleObject)]
struct MyObj { struct MyObj {
#[field(guard(RoleGuard(role = "Role::Admin")))] #[field(guard(RoleGuard(role = "Role::Admin")))]
value: i32, value: i32,
@ -50,7 +50,7 @@ pub async fn test_guard() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
#[field(guard(RoleGuard(role = "Role::Admin")))] #[field(guard(RoleGuard(role = "Role::Admin")))]
async fn value(&self) -> i32 { async fn value(&self) -> i32 {
@ -64,7 +64,7 @@ pub async fn test_guard() {
struct Subscription; struct Subscription;
#[Subscription] #[GQLSubscription]
impl Subscription { impl Subscription {
#[field(guard(RoleGuard(role = "Role::Admin")))] #[field(guard(RoleGuard(role = "Role::Admin")))]
async fn values(&self) -> impl Stream<Item = i32> { async fn values(&self) -> impl Stream<Item = i32> {
@ -168,7 +168,7 @@ pub async fn test_guard() {
#[async_std::test] #[async_std::test]
pub async fn test_multiple_guards() { pub async fn test_multiple_guards() {
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Query { struct Query {
#[field(guard(RoleGuard(role = "Role::Admin"), UserGuard(username = r#""test""#)))] #[field(guard(RoleGuard(role = "Role::Admin"), UserGuard(username = r#""test""#)))]
value: i32, value: i32,
@ -272,7 +272,7 @@ pub async fn test_guard_forward_arguments() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
#[field(guard(UserGuard(id = "@id")))] #[field(guard(UserGuard(id = "@id")))]
async fn user(&self, id: ID) -> ID { async fn user(&self, id: ID) -> ID {

View File

@ -2,7 +2,7 @@ use async_graphql::*;
#[async_std::test] #[async_std::test]
pub async fn test_input_object_default_value() { pub async fn test_input_object_default_value() {
#[InputObject] #[derive(GQLInputObject)]
struct MyInput { struct MyInput {
#[field(default = 999)] #[field(default = 999)]
a: i32, a: i32,
@ -28,7 +28,7 @@ pub async fn test_input_object_default_value() {
e: Option<i32>, e: Option<i32>,
} }
#[Object] #[GQLObject]
impl MyOutput { impl MyOutput {
async fn a(&self) -> i32 { async fn a(&self) -> i32 {
self.a self.a
@ -53,7 +53,7 @@ pub async fn test_input_object_default_value() {
struct Root; struct Root;
#[Object] #[GQLObject]
impl Root { impl Root {
async fn a(&self, input: MyInput) -> MyOutput { async fn a(&self, input: MyInput) -> MyOutput {
MyOutput { MyOutput {
@ -91,8 +91,7 @@ pub async fn test_input_object_default_value() {
pub async fn test_inputobject_derive_and_item_attributes() { pub async fn test_inputobject_derive_and_item_attributes() {
use serde::Deserialize; use serde::Deserialize;
#[InputObject] #[derive(Deserialize, PartialEq, Debug, GQLInputObject)]
#[derive(Deserialize, PartialEq, Debug)]
struct MyInputObject { struct MyInputObject {
#[serde(alias = "other")] #[serde(alias = "other")]
real: i32, real: i32,
@ -164,7 +163,7 @@ pub async fn test_inputobject_flatten_recursive() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn test(&self, input: MyInputObject) -> i32 { async fn test(&self, input: MyInputObject) -> i32 {
input.c + input.b_obj.b + input.b_obj.a_obj.a input.c + input.b_obj.b + input.b_obj.a_obj.a

View File

@ -9,13 +9,13 @@ use async_graphql_parser::types::Name;
pub async fn test_input_validator_string_min_length() { pub async fn test_input_validator_string_min_length() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputMaxLength { struct InputMaxLength {
#[field(validator(StringMinLength(length = "6")))] #[field(validator(StringMinLength(length = "6")))]
pub id: String, pub id: String,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -125,13 +125,13 @@ pub async fn test_input_validator_string_min_length() {
pub async fn test_input_validator_string_max_length() { pub async fn test_input_validator_string_max_length() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputMaxLength { struct InputMaxLength {
#[field(validator(StringMaxLength(length = "6")))] #[field(validator(StringMaxLength(length = "6")))]
pub id: String, pub id: String,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -235,13 +235,13 @@ pub async fn test_input_validator_string_max_length() {
pub async fn test_input_validator_string_email() { pub async fn test_input_validator_string_email() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputEmail { struct InputEmail {
#[field(validator(Email))] #[field(validator(Email))]
pub email: String, pub email: String,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter(&self, #[arg(validator(Email))] _email: String) -> bool { async fn field_parameter(&self, #[arg(validator(Email))] _email: String) -> bool {
true true
@ -376,19 +376,19 @@ pub async fn test_input_validator_string_mac() {
struct QueryRootWithColon; struct QueryRootWithColon;
struct QueryRootWithoutColon; struct QueryRootWithoutColon;
#[InputObject] #[derive(GQLInputObject)]
struct InputMACWithColon { struct InputMACWithColon {
#[field(validator(MAC(colon = "true")))] #[field(validator(MAC(colon = "true")))]
pub mac: String, pub mac: String,
} }
#[InputObject] #[derive(GQLInputObject)]
struct InputMACWithoutColon { struct InputMACWithoutColon {
#[field(validator(MAC(colon = "false")))] #[field(validator(MAC(colon = "false")))]
pub mac: String, pub mac: String,
} }
#[Object] #[GQLObject]
impl QueryRootWithColon { impl QueryRootWithColon {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -402,7 +402,7 @@ pub async fn test_input_validator_string_mac() {
} }
} }
#[Object] #[GQLObject]
impl QueryRootWithoutColon { impl QueryRootWithoutColon {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -665,13 +665,13 @@ pub async fn test_input_validator_string_mac() {
pub async fn test_input_validator_int_range() { pub async fn test_input_validator_int_range() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputIntRange { struct InputIntRange {
#[field(validator(IntRange(min = "-2", max = "5")))] #[field(validator(IntRange(min = "-2", max = "5")))]
pub id: i32, pub id: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -767,13 +767,13 @@ pub async fn test_input_validator_int_range() {
pub async fn test_input_validator_int_less_than() { pub async fn test_input_validator_int_less_than() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputIntLessThan { struct InputIntLessThan {
#[field(validator(IntLessThan(value = "5")))] #[field(validator(IntLessThan(value = "5")))]
pub id: i32, pub id: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -872,13 +872,13 @@ pub async fn test_input_validator_int_less_than() {
pub async fn test_input_validator_int_greater_than() { pub async fn test_input_validator_int_greater_than() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputIntGreaterThan { struct InputIntGreaterThan {
#[field(validator(IntGreaterThan(value = "3")))] #[field(validator(IntGreaterThan(value = "3")))]
pub id: i32, pub id: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -979,13 +979,13 @@ pub async fn test_input_validator_int_greater_than() {
pub async fn test_input_validator_int_nonzero() { pub async fn test_input_validator_int_nonzero() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputIntNonZero { struct InputIntNonZero {
#[field(validator(IntNonZero))] #[field(validator(IntNonZero))]
pub id: i32, pub id: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter(&self, #[arg(validator(IntNonZero))] _id: i32) -> bool { async fn field_parameter(&self, #[arg(validator(IntNonZero))] _id: i32) -> bool {
true true
@ -1079,13 +1079,13 @@ pub async fn test_input_validator_int_nonzero() {
pub async fn test_input_validator_int_equal() { pub async fn test_input_validator_int_equal() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputIntEqual { struct InputIntEqual {
#[field(validator(IntEqual(value = "5")))] #[field(validator(IntEqual(value = "5")))]
pub id: i32, pub id: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter(&self, #[arg(validator(IntEqual(value = "5")))] _id: i32) -> bool { async fn field_parameter(&self, #[arg(validator(IntEqual(value = "5")))] _id: i32) -> bool {
true true
@ -1180,13 +1180,13 @@ pub async fn test_input_validator_int_equal() {
pub async fn test_input_validator_list_max_length() { pub async fn test_input_validator_list_max_length() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputListMaxLength { struct InputListMaxLength {
#[field(validator(ListMaxLength(length = "5")))] #[field(validator(ListMaxLength(length = "5")))]
pub id: Vec<i32>, pub id: Vec<i32>,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -1296,13 +1296,13 @@ pub async fn test_input_validator_list_max_length() {
pub async fn test_input_validator_list_min_length() { pub async fn test_input_validator_list_min_length() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputListMinLength { struct InputListMinLength {
#[field(validator(ListMinLength(length = "4")))] #[field(validator(ListMinLength(length = "4")))]
pub id: Vec<i32>, pub id: Vec<i32>,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -1412,13 +1412,13 @@ pub async fn test_input_validator_list_min_length() {
pub async fn test_input_validator_operator_or() { pub async fn test_input_validator_operator_or() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputOrValidator { struct InputOrValidator {
#[field(validator(or(Email, MAC(colon = "false"))))] #[field(validator(or(Email, MAC(colon = "false"))))]
pub id: String, pub id: String,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -1536,13 +1536,13 @@ pub async fn test_input_validator_operator_or() {
pub async fn test_input_validator_operator_and() { pub async fn test_input_validator_operator_and() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputAndValidator { struct InputAndValidator {
#[field(validator(and(Email, StringMinLength(length = "14"))))] #[field(validator(and(Email, StringMinLength(length = "14"))))]
pub email: String, pub email: String,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,
@ -1653,13 +1653,13 @@ pub async fn test_input_validator_operator_and() {
pub async fn test_input_validator_variable() { pub async fn test_input_validator_variable() {
struct QueryRoot; struct QueryRoot;
#[InputObject] #[derive(GQLInputObject)]
struct InputMaxLength { struct InputMaxLength {
#[field(validator(StringMinLength(length = "6")))] #[field(validator(StringMinLength(length = "6")))]
pub id: String, pub id: String,
} }
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn field_parameter( async fn field_parameter(
&self, &self,

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_input_value_custom_error() { pub async fn test_input_value_custom_error() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn parse_int(&self, _n: i8) -> bool { async fn parse_int(&self, _n: i8) -> bool {
true true

View File

@ -2,20 +2,21 @@ use async_graphql::*;
#[async_std::test] #[async_std::test]
pub async fn test_interface_simple_object() { pub async fn test_interface_simple_object() {
#[async_graphql::SimpleObject] #[derive(GQLSimpleObject)]
struct MyObj { struct MyObj {
id: i32, id: i32,
title: String, title: String,
} }
#[async_graphql::Interface(field(name = "id", type = "&i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "id", type = "&i32"))]
enum Node { enum Node {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn node(&self) -> Node { async fn node(&self) -> Node {
MyObj { MyObj {
@ -46,20 +47,21 @@ pub async fn test_interface_simple_object() {
#[async_std::test] #[async_std::test]
pub async fn test_interface_simple_object2() { pub async fn test_interface_simple_object2() {
#[async_graphql::SimpleObject] #[derive(GQLSimpleObject)]
struct MyObj { struct MyObj {
id: i32, id: i32,
title: String, title: String,
} }
#[async_graphql::Interface(field(name = "id", type = "&i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "id", type = "&i32"))]
enum Node { enum Node {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn node(&self) -> Node { async fn node(&self) -> Node {
MyObj { MyObj {
@ -92,7 +94,7 @@ pub async fn test_interface_simple_object2() {
pub async fn test_multiple_interfaces() { pub async fn test_multiple_interfaces() {
struct MyObj; struct MyObj;
#[async_graphql::Object] #[GQLObject]
impl MyObj { impl MyObj {
async fn value_a(&self) -> i32 { async fn value_a(&self) -> i32 {
1 1
@ -107,19 +109,21 @@ pub async fn test_multiple_interfaces() {
} }
} }
#[async_graphql::Interface(field(name = "value_a", type = "i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "value_a", type = "i32"))]
enum InterfaceA { enum InterfaceA {
MyObj(MyObj), MyObj(MyObj),
} }
#[async_graphql::Interface(field(name = "value_b", type = "i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "value_b", type = "i32"))]
enum InterfaceB { enum InterfaceB {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn my_obj(&self) -> InterfaceB { async fn my_obj(&self) -> InterfaceB {
MyObj.into() MyObj.into()
@ -158,7 +162,7 @@ pub async fn test_multiple_interfaces() {
pub async fn test_multiple_objects_in_multiple_interfaces() { pub async fn test_multiple_objects_in_multiple_interfaces() {
struct MyObjOne; struct MyObjOne;
#[async_graphql::Object] #[GQLObject]
impl MyObjOne { impl MyObjOne {
async fn value_a(&self) -> i32 { async fn value_a(&self) -> i32 {
1 1
@ -175,27 +179,29 @@ pub async fn test_multiple_objects_in_multiple_interfaces() {
struct MyObjTwo; struct MyObjTwo;
#[async_graphql::Object] #[GQLObject]
impl MyObjTwo { impl MyObjTwo {
async fn value_a(&self) -> i32 { async fn value_a(&self) -> i32 {
1 1
} }
} }
#[async_graphql::Interface(field(name = "value_a", type = "i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "value_a", type = "i32"))]
enum InterfaceA { enum InterfaceA {
MyObjOne(MyObjOne), MyObjOne(MyObjOne),
MyObjTwo(MyObjTwo), MyObjTwo(MyObjTwo),
} }
#[async_graphql::Interface(field(name = "value_b", type = "i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "value_b", type = "i32"))]
enum InterfaceB { enum InterfaceB {
MyObjOne(MyObjOne), MyObjOne(MyObjOne),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn my_obj(&self) -> Vec<InterfaceA> { async fn my_obj(&self) -> Vec<InterfaceA> {
vec![MyObjOne.into(), MyObjTwo.into()] vec![MyObjOne.into(), MyObjTwo.into()]
@ -236,21 +242,22 @@ pub async fn test_multiple_objects_in_multiple_interfaces() {
pub async fn test_interface_field_result() { pub async fn test_interface_field_result() {
struct MyObj; struct MyObj;
#[async_graphql::Object] #[GQLObject]
impl MyObj { impl MyObj {
async fn value(&self) -> FieldResult<i32> { async fn value(&self) -> FieldResult<i32> {
Ok(10) Ok(10)
} }
} }
#[async_graphql::Interface(field(name = "value", type = "FieldResult<i32>"))] #[derive(GQLInterface)]
#[graphql(field(name = "value", type = "FieldResult<i32>"))]
enum Node { enum Node {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn node(&self) -> Node { async fn node(&self) -> Node {
MyObj.into() MyObj.into()
@ -279,7 +286,7 @@ pub async fn test_interface_field_result() {
pub async fn test_interface_field_method() { pub async fn test_interface_field_method() {
struct A; struct A;
#[Object] #[GQLObject]
impl A { impl A {
#[field(name = "created_at")] #[field(name = "created_at")]
pub async fn created_at(&self) -> i32 { pub async fn created_at(&self) -> i32 {
@ -289,7 +296,7 @@ pub async fn test_interface_field_method() {
struct B; struct B;
#[Object] #[GQLObject]
impl B { impl B {
#[field(name = "created_at")] #[field(name = "created_at")]
pub async fn created_at(&self) -> i32 { pub async fn created_at(&self) -> i32 {
@ -297,7 +304,8 @@ pub async fn test_interface_field_method() {
} }
} }
#[Interface(field(name = "created_at", method = "created_at", type = "i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "created_at", method = "created_at", type = "i32"))]
enum MyInterface { enum MyInterface {
A(A), A(A),
B(B), B(B),
@ -305,7 +313,7 @@ pub async fn test_interface_field_method() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn test(&self) -> MyInterface { async fn test(&self) -> MyInterface {
A.into() A.into()

View File

@ -1,13 +1,12 @@
use async_graphql::*; use async_graphql::*;
use async_std::stream; use async_std::stream::{self, Stream};
use async_std::stream::Stream;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct Circle { struct Circle {
radius: f32, radius: f32,
} }
#[Object(desc = "Circle")] #[GQLObject(desc = "Circle")]
impl Circle { impl Circle {
async fn scale(&self, s: f32) -> TestInterface { async fn scale(&self, s: f32) -> TestInterface {
Circle { Circle {
@ -22,7 +21,7 @@ struct Square {
width: f32, width: f32,
} }
#[Object(desc = "Square")] #[GQLObject(desc = "Square")]
impl Square { impl Square {
#[field(deprecation = "Field scale is deprecated")] #[field(deprecation = "Field scale is deprecated")]
async fn scale(&self, s: f32) -> TestInterface { async fn scale(&self, s: f32) -> TestInterface {
@ -33,21 +32,22 @@ impl Square {
} }
} }
#[Interface(field(name = "scale", type = "TestInterface", arg(name = "s", type = "f32")))] #[derive(Clone, Debug, GQLInterface)]
#[derive(Clone, Debug)] #[graphql(field(name = "scale", type = "TestInterface", arg(name = "s", type = "f32")))]
enum TestInterface { enum TestInterface {
Circle(Circle), Circle(Circle),
Square(Square), Square(Square),
} }
#[Union(desc = "Test Union")] #[derive(Clone, Debug, GQLUnion)]
#[derive(Clone, Debug)] #[graphql(desc = "Test Union")]
enum TestUnion { enum TestUnion {
Circle(Circle), Circle(Circle),
Square(Square), Square(Square),
} }
#[Enum(desc = "Test Enum")] #[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
#[graphql(desc = "Test Enum")]
enum TestEnum { enum TestEnum {
#[item(desc = "Kind 1")] #[item(desc = "Kind 1")]
Kind1, Kind1,
@ -56,14 +56,12 @@ enum TestEnum {
Kind2, Kind2,
} }
#[SimpleObject] #[derive(Clone, Debug, GQLSimpleObject)]
#[derive(Clone, Debug)]
struct SimpleList { struct SimpleList {
items: Vec<String>, items: Vec<String>,
} }
#[SimpleObject] #[derive(Clone, Debug, GQLSimpleObject)]
#[derive(Clone, Debug)]
struct SimpleOption { struct SimpleOption {
required: i32, required: i32,
optional: Option<i32>, optional: Option<i32>,
@ -73,7 +71,7 @@ struct SimpleOption {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct TestScalar(i32); struct TestScalar(i32);
#[Scalar(desc = "Test scalar")] #[GQLScalar(desc = "Test scalar")]
impl ScalarType for TestScalar { impl ScalarType for TestScalar {
fn parse(_value: Value) -> InputValueResult<Self> { fn parse(_value: Value) -> InputValueResult<Self> {
Ok(TestScalar(42)) Ok(TestScalar(42))
@ -90,7 +88,7 @@ impl ScalarType for TestScalar {
/// Is SimpleObject /// Is SimpleObject
/// and some more ```lorem ipsum``` /// and some more ```lorem ipsum```
#[SimpleObject] #[derive(GQLSimpleObject)]
struct SimpleObject { struct SimpleObject {
/// Value a with # 'some' `markdown`"." /// Value a with # 'some' `markdown`"."
/// and some more lorem ipsum /// and some more lorem ipsum
@ -122,7 +120,7 @@ struct SimpleObject {
struct Query; struct Query;
#[Object(desc = "Global query")] #[GQLObject(desc = "Global query")]
impl Query { impl Query {
/// Get a simple object /// Get a simple object
async fn simple_object(&self) -> SimpleObject { async fn simple_object(&self) -> SimpleObject {
@ -130,14 +128,15 @@ impl Query {
} }
} }
#[async_graphql::InputObject(desc = "Simple Input")] #[derive(GQLInputObject)]
#[graphql(desc = "Simple Input")]
pub struct SimpleInput { pub struct SimpleInput {
pub a: String, pub a: String,
} }
struct Mutation; struct Mutation;
#[Object(desc = "Global mutation")] #[GQLObject(desc = "Global mutation")]
impl Mutation { impl Mutation {
/// simple_mutation description /// simple_mutation description
/// line2 /// line2
@ -149,7 +148,7 @@ impl Mutation {
struct Subscription; struct Subscription;
#[Subscription(desc = "Global subscription")] #[GQLSubscription(desc = "Global subscription")]
impl Subscription { impl Subscription {
/// simple_subscription description /// simple_subscription description
async fn simple_subscription(&self, #[arg(default = 1)] step: i32) -> impl Stream<Item = i32> { async fn simple_subscription(&self, #[arg(default = 1)] step: i32) -> impl Stream<Item = i32> {

View File

@ -13,7 +13,7 @@ pub async fn test_json_scalar() {
data: MyDataOutput, data: MyDataOutput,
} }
#[Object] #[GQLObject]
impl Query { impl Query {
async fn data(&self) -> Json<MyData> { async fn data(&self) -> Json<MyData> {
let mut items = HashMap::new(); let mut items = HashMap::new();

View File

@ -2,7 +2,7 @@ use async_graphql::*;
#[async_std::test] #[async_std::test]
pub async fn test_list_type() { pub async fn test_list_type() {
#[InputObject] #[derive(GQLInputObject)]
struct MyInput { struct MyInput {
value: Vec<i32>, value: Vec<i32>,
} }
@ -11,7 +11,7 @@ pub async fn test_list_type() {
value: Vec<i32>, value: Vec<i32>,
} }
#[Object] #[GQLObject]
impl Root { impl Root {
async fn value_vec(&self) -> Vec<i32> { async fn value_vec(&self) -> Vec<i32> {
self.value.clone() self.value.clone()

View File

@ -2,14 +2,14 @@ use async_graphql::*;
#[async_std::test] #[async_std::test]
pub async fn test_maybe_undefined_type() { pub async fn test_maybe_undefined_type() {
#[InputObject] #[derive(GQLInputObject)]
struct MyInput { struct MyInput {
value: MaybeUndefined<i32>, value: MaybeUndefined<i32>,
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn value1(&self, input: MaybeUndefined<i32>) -> i32 { async fn value1(&self, input: MaybeUndefined<i32>) -> i32 {
if input.is_null() { if input.is_null() {

View File

@ -1,18 +1,17 @@
use async_graphql::MergedObjectTail;
use async_graphql::*; use async_graphql::*;
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Object1 { struct Object1 {
a: i32, a: i32,
} }
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Object2 { struct Object2 {
b: i32, b: i32,
} }
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Object3 { struct Object3 {
c: i32, c: i32,
} }
@ -24,7 +23,7 @@ pub async fn test_merged_object() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn obj(&self) -> MyObj { async fn obj(&self) -> MyObj {
MergedObject( MergedObject(
@ -58,12 +57,12 @@ pub async fn test_merged_object() {
#[async_std::test] #[async_std::test]
pub async fn test_merged_object_macro() { pub async fn test_merged_object_macro() {
#[MergedObject] #[derive(GQLMergedObject)]
struct MyObj(Object1, Object2, Object3); struct MyObj(Object1, Object2, Object3);
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn obj(&self) -> MyObj { async fn obj(&self) -> MyObj {
MyObj(Object1 { a: 10 }, Object2 { b: 20 }, Object3 { c: 30 }) MyObj(Object1 { a: 10 }, Object2 { b: 20 }, Object3 { c: 30 })
@ -91,7 +90,7 @@ pub async fn test_merged_object_derive() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn obj(&self) -> MyObj { async fn obj(&self) -> MyObj {
MyObj(Object1 { a: 10 }, Object2 { b: 20 }, Object3 { c: 30 }) MyObj(Object1 { a: 10 }, Object2 { b: 20 }, Object3 { c: 30 })
@ -163,7 +162,7 @@ pub async fn test_merged_subscription() {
#[derive(Default)] #[derive(Default)]
struct Subscription1; struct Subscription1;
#[Subscription] #[GQLSubscription]
impl Subscription1 { impl Subscription1 {
async fn events1(&self) -> impl Stream<Item = i32> { async fn events1(&self) -> impl Stream<Item = i32> {
futures::stream::iter(0..10) futures::stream::iter(0..10)
@ -173,7 +172,7 @@ pub async fn test_merged_subscription() {
#[derive(Default)] #[derive(Default)]
struct Subscription2; struct Subscription2;
#[Subscription] #[GQLSubscription]
impl Subscription2 { impl Subscription2 {
async fn events2(&self) -> impl Stream<Item = i32> { async fn events2(&self) -> impl Stream<Item = i32> {
futures::stream::iter(10..20) futures::stream::iter(10..20)
@ -185,7 +184,7 @@ pub async fn test_merged_subscription() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query {} impl Query {}
let schema = Schema::new(Query, EmptyMutation, Subscription::default()); let schema = Schema::new(Query, EmptyMutation, Subscription::default());

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_mut_args() { pub async fn test_mut_args() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn test(&self, mut a: i32, mut b: String) -> String { async fn test(&self, mut a: i32, mut b: String) -> String {
a += 1; a += 1;

View File

@ -7,12 +7,12 @@ use std::time::Duration;
pub async fn test_mutation_execution_order() { pub async fn test_mutation_execution_order() {
type List = Arc<Mutex<Vec<i32>>>; type List = Arc<Mutex<Vec<i32>>>;
#[SimpleObject] #[derive(GQLSimpleObject)]
struct QueryRoot; struct QueryRoot;
struct MutationRoot; struct MutationRoot;
#[Object] #[GQLObject]
impl MutationRoot { impl MutationRoot {
async fn append1(&self, ctx: &Context<'_>) -> bool { async fn append1(&self, ctx: &Context<'_>) -> bool {
async_std::task::sleep(Duration::from_secs(1)).await; async_std::task::sleep(Duration::from_secs(1)).await;
@ -38,12 +38,12 @@ pub async fn test_mutation_execution_order() {
#[async_std::test] #[async_std::test]
pub async fn test_mutation_fragment() { pub async fn test_mutation_fragment() {
#[SimpleObject] #[derive(GQLSimpleObject)]
struct QueryRoot; struct QueryRoot;
struct MutationRoot; struct MutationRoot;
#[Object] #[GQLObject]
impl MutationRoot { impl MutationRoot {
async fn action(&self) -> bool { async fn action(&self) -> bool {
true true

View File

@ -2,7 +2,7 @@ use async_graphql::*;
#[async_std::test] #[async_std::test]
pub async fn test_optional_type() { pub async fn test_optional_type() {
#[InputObject] #[derive(GQLInputObject)]
struct MyInput { struct MyInput {
value: Option<i32>, value: Option<i32>,
} }
@ -12,7 +12,7 @@ pub async fn test_optional_type() {
value2: Option<i32>, value2: Option<i32>,
} }
#[Object] #[GQLObject]
impl Root { impl Root {
async fn value1(&self) -> Option<i32> { async fn value1(&self) -> Option<i32> {
self.value1 self.value1

View File

@ -22,7 +22,7 @@ impl PostGuard<i32> for RoleGuard {
} }
} }
#[SimpleObject] #[derive(GQLSimpleObject)]
struct MyObj { struct MyObj {
#[field(owned, post_guard(UserGuard(username = r#""test""#, value = "88")))] #[field(owned, post_guard(UserGuard(username = r#""test""#, value = "88")))]
value: i32, value: i32,
@ -63,7 +63,7 @@ impl PostGuard<MyObj> for UserGuard {
pub async fn test_post_guard() { pub async fn test_post_guard() {
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
#[field(post_guard(UserGuard(username = r#""test""#, value = "99")))] #[field(post_guard(UserGuard(username = r#""test""#, value = "99")))]
async fn value(&self) -> i32 { async fn value(&self) -> i32 {
@ -136,7 +136,7 @@ pub async fn test_post_guard() {
#[async_std::test] #[async_std::test]
pub async fn test_multiple_post_guards() { pub async fn test_multiple_post_guards() {
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Query { struct Query {
#[field(post_guard( #[field(post_guard(
RoleGuard(role = "Role::Admin"), RoleGuard(role = "Role::Admin"),
@ -244,7 +244,7 @@ pub async fn test_post_guard_forward_arguments() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
#[field(post_guard(UserGuard(id = "@_id")))] #[field(post_guard(UserGuard(id = "@_id")))]
async fn user(&self, _id: ID) -> ID { async fn user(&self, _id: ID) -> ID {
@ -300,7 +300,7 @@ pub async fn test_post_guard_generic() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
#[field(post_guard(UserGuard(id = r#""abc""#)))] #[field(post_guard(UserGuard(id = r#""abc""#)))]
async fn user(&self) -> ID { async fn user(&self) -> ID {

View File

@ -3,25 +3,25 @@ use futures::{Stream, StreamExt, TryStreamExt};
#[async_std::test] #[async_std::test]
pub async fn test_input_value_custom_error() { pub async fn test_input_value_custom_error() {
#[Enum] #[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
enum MyEnum { enum MyEnum {
r#type, r#type,
} }
#[SimpleObject] #[derive(GQLSimpleObject)]
struct MyObject { struct MyObject {
r#i32: i32, r#i32: i32,
} }
#[InputObject] #[derive(GQLInputObject)]
struct MyInputObject { struct MyInputObject {
r#i32: i32, r#i32: i32,
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn r#type(&self, r#i32: i32) -> i32 { async fn r#type(&self, r#i32: i32) -> i32 {
r#i32 r#i32
@ -38,7 +38,7 @@ pub async fn test_input_value_custom_error() {
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn r#type(&self) -> impl Stream<Item = i32> { async fn r#type(&self) -> impl Stream<Item = i32> {
futures::stream::iter(0..10) futures::stream::iter(0..10)

View File

@ -5,18 +5,18 @@ use futures::{Stream, StreamExt, TryStreamExt};
pub async fn test_subscription() { pub async fn test_subscription() {
struct QueryRoot; struct QueryRoot;
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Event { struct Event {
a: i32, a: i32,
b: i32, b: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn values(&self, start: i32, end: i32) -> impl Stream<Item = i32> { async fn values(&self, start: i32, end: i32) -> impl Stream<Item = i32> {
futures::stream::iter(start..end) futures::stream::iter(start..end)
@ -62,24 +62,22 @@ pub async fn test_subscription() {
pub async fn test_simple_broker() { pub async fn test_simple_broker() {
struct QueryRoot; struct QueryRoot;
#[SimpleObject] #[derive(Clone, GQLSimpleObject)]
#[derive(Clone)]
struct Event1 { struct Event1 {
value: i32, value: i32,
} }
#[SimpleObject] #[derive(Clone, GQLSimpleObject)]
#[derive(Clone)]
struct Event2 { struct Event2 {
value: i32, value: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn events1(&self) -> impl Stream<Item = Event1> { async fn events1(&self) -> impl Stream<Item = Event1> {
let stream = SimpleBroker::<Event1>::subscribe(); let stream = SimpleBroker::<Event1>::subscribe();
@ -129,12 +127,12 @@ pub async fn test_simple_broker() {
pub async fn test_subscription_with_ctx_data() { pub async fn test_subscription_with_ctx_data() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct MyObject; struct MyObject;
#[Object] #[GQLObject]
impl MyObject { impl MyObject {
async fn value(&self, ctx: &Context<'_>) -> i32 { async fn value(&self, ctx: &Context<'_>) -> i32 {
*ctx.data_unchecked::<i32>() *ctx.data_unchecked::<i32>()
@ -143,7 +141,7 @@ pub async fn test_subscription_with_ctx_data() {
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn values(&self, ctx: &Context<'_>) -> impl Stream<Item = i32> { async fn values(&self, ctx: &Context<'_>) -> impl Stream<Item = i32> {
let value = *ctx.data_unchecked::<i32>(); let value = *ctx.data_unchecked::<i32>();
@ -178,14 +176,14 @@ pub async fn test_subscription_with_ctx_data() {
pub async fn test_subscription_with_token() { pub async fn test_subscription_with_token() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
struct Token(String); struct Token(String);
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn values(&self, ctx: &Context<'_>) -> FieldResult<impl Stream<Item = i32>> { async fn values(&self, ctx: &Context<'_>) -> FieldResult<impl Stream<Item = i32>> {
if ctx.data_unchecked::<Token>().0 != "123456" { if ctx.data_unchecked::<Token>().0 != "123456" {
@ -228,18 +226,18 @@ pub async fn test_subscription_with_token() {
pub async fn test_subscription_inline_fragment() { pub async fn test_subscription_inline_fragment() {
struct QueryRoot; struct QueryRoot;
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Event { struct Event {
a: i32, a: i32,
b: i32, b: i32,
} }
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn events(&self, start: i32, end: i32) -> impl Stream<Item = Event> { async fn events(&self, start: i32, end: i32) -> impl Stream<Item = Event> {
futures::stream::iter((start..end).map(|n| Event { a: n, b: n * 10 })) futures::stream::iter((start..end).map(|n| Event { a: n, b: n * 10 }))
@ -275,23 +273,24 @@ pub async fn test_subscription_inline_fragment() {
pub async fn test_subscription_fragment() { pub async fn test_subscription_fragment() {
struct QueryRoot; struct QueryRoot;
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Event { struct Event {
a: i32, a: i32,
b: i32, b: i32,
} }
#[Interface(field(name = "a", type = "&i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "a", type = "&i32"))]
enum MyInterface { enum MyInterface {
Event(Event), Event(Event),
} }
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn events(&self, start: i32, end: i32) -> impl Stream<Item = Event> { async fn events(&self, start: i32, end: i32) -> impl Stream<Item = Event> {
futures::stream::iter((start..end).map(|n| Event { a: n, b: n * 10 })) futures::stream::iter((start..end).map(|n| Event { a: n, b: n * 10 }))
@ -329,23 +328,24 @@ pub async fn test_subscription_fragment() {
pub async fn test_subscription_fragment2() { pub async fn test_subscription_fragment2() {
struct QueryRoot; struct QueryRoot;
#[SimpleObject] #[derive(GQLSimpleObject)]
struct Event { struct Event {
a: i32, a: i32,
b: i32, b: i32,
} }
#[Interface(field(name = "a", type = "&i32"))] #[derive(GQLInterface)]
#[graphql(field(name = "a", type = "&i32"))]
enum MyInterface { enum MyInterface {
Event(Event), Event(Event),
} }
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn events(&self, start: i32, end: i32) -> impl Stream<Item = Event> { async fn events(&self, start: i32, end: i32) -> impl Stream<Item = Event> {
futures::stream::iter((start..end).map(|n| Event { a: n, b: n * 10 })) futures::stream::iter((start..end).map(|n| Event { a: n, b: n * 10 }))
@ -388,7 +388,7 @@ pub async fn test_subscription_error() {
value: i32, value: i32,
} }
#[Object] #[GQLObject]
impl Event { impl Event {
async fn value(&self) -> FieldResult<i32> { async fn value(&self) -> FieldResult<i32> {
if self.value < 5 { if self.value < 5 {
@ -399,12 +399,12 @@ pub async fn test_subscription_error() {
} }
} }
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn events(&self) -> impl Stream<Item = Event> { async fn events(&self) -> impl Stream<Item = Event> {
futures::stream::iter((0..10).map(|n| Event { value: n })) futures::stream::iter((0..10).map(|n| Event { value: n }))
@ -445,12 +445,12 @@ pub async fn test_subscription_error() {
pub async fn test_subscription_fieldresult() { pub async fn test_subscription_fieldresult() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn values(&self) -> impl Stream<Item = FieldResult<i32>> { async fn values(&self) -> impl Stream<Item = FieldResult<i32>> {
futures::stream::iter(0..5) futures::stream::iter(0..5)

View File

@ -5,12 +5,12 @@ use futures::{SinkExt, Stream, StreamExt};
pub async fn test_subscription_ws_transport() { pub async fn test_subscription_ws_transport() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn values(&self) -> impl Stream<Item = i32> { async fn values(&self) -> impl Stream<Item = i32> {
futures::stream::iter(0..10) futures::stream::iter(0..10)
@ -76,12 +76,12 @@ pub async fn test_subscription_ws_transport_with_token() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn values(&self, ctx: &Context<'_>) -> FieldResult<impl Stream<Item = i32>> { async fn values(&self, ctx: &Context<'_>) -> FieldResult<impl Stream<Item = i32>> {
if ctx.data_unchecked::<Token>().0 != "123456" { if ctx.data_unchecked::<Token>().0 != "123456" {
@ -163,7 +163,7 @@ pub async fn test_subscription_ws_transport_error() {
value: i32, value: i32,
} }
#[Object] #[GQLObject]
impl Event { impl Event {
async fn value(&self) -> FieldResult<i32> { async fn value(&self) -> FieldResult<i32> {
if self.value < 5 { if self.value < 5 {
@ -174,12 +174,12 @@ pub async fn test_subscription_ws_transport_error() {
} }
} }
#[Object] #[GQLObject]
impl QueryRoot {} impl QueryRoot {}
struct SubscriptionRoot; struct SubscriptionRoot;
#[Subscription] #[GQLSubscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn events(&self) -> impl Stream<Item = Event> { async fn events(&self) -> impl Stream<Item = Event> {
futures::stream::iter((0..10).map(|n| Event { value: n })) futures::stream::iter((0..10).map(|n| Event { value: n }))
@ -248,7 +248,7 @@ pub async fn test_subscription_ws_transport_error() {
pub async fn test_query_over_websocket() { pub async fn test_query_over_websocket() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn value(&self) -> i32 { async fn value(&self) -> i32 {
999 999

View File

@ -2,20 +2,20 @@ use async_graphql::*;
#[async_std::test] #[async_std::test]
pub async fn test_union_simple_object() { pub async fn test_union_simple_object() {
#[async_graphql::SimpleObject] #[derive(GQLSimpleObject)]
struct MyObj { struct MyObj {
id: i32, id: i32,
title: String, title: String,
} }
#[async_graphql::Union] #[derive(GQLUnion)]
enum Node { enum Node {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn node(&self) -> Node { async fn node(&self) -> Node {
MyObj { MyObj {
@ -46,20 +46,20 @@ pub async fn test_union_simple_object() {
#[async_std::test] #[async_std::test]
pub async fn test_union_simple_object2() { pub async fn test_union_simple_object2() {
#[async_graphql::SimpleObject] #[derive(GQLSimpleObject)]
struct MyObj { struct MyObj {
id: i32, id: i32,
title: String, title: String,
} }
#[async_graphql::Union] #[derive(GQLUnion)]
enum Node { enum Node {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn node(&self) -> Node { async fn node(&self) -> Node {
MyObj { MyObj {
@ -92,7 +92,7 @@ pub async fn test_union_simple_object2() {
pub async fn test_multiple_unions() { pub async fn test_multiple_unions() {
struct MyObj; struct MyObj;
#[async_graphql::Object] #[GQLObject]
impl MyObj { impl MyObj {
async fn value_a(&self) -> i32 { async fn value_a(&self) -> i32 {
1 1
@ -107,19 +107,19 @@ pub async fn test_multiple_unions() {
} }
} }
#[async_graphql::Union] #[derive(GQLUnion)]
enum UnionA { enum UnionA {
MyObj(MyObj), MyObj(MyObj),
} }
#[async_graphql::Union] #[derive(GQLUnion)]
enum UnionB { enum UnionB {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn union_a(&self) -> UnionA { async fn union_a(&self) -> UnionA {
MyObj.into() MyObj.into()
@ -169,7 +169,7 @@ pub async fn test_multiple_unions() {
pub async fn test_multiple_objects_in_multiple_unions() { pub async fn test_multiple_objects_in_multiple_unions() {
struct MyObjOne; struct MyObjOne;
#[async_graphql::Object] #[GQLObject]
impl MyObjOne { impl MyObjOne {
async fn value_a(&self) -> i32 { async fn value_a(&self) -> i32 {
1 1
@ -186,27 +186,27 @@ pub async fn test_multiple_objects_in_multiple_unions() {
struct MyObjTwo; struct MyObjTwo;
#[async_graphql::Object] #[GQLObject]
impl MyObjTwo { impl MyObjTwo {
async fn value_a(&self) -> i32 { async fn value_a(&self) -> i32 {
1 1
} }
} }
#[async_graphql::Union] #[derive(GQLUnion)]
enum UnionA { enum UnionA {
MyObjOne(MyObjOne), MyObjOne(MyObjOne),
MyObjTwo(MyObjTwo), MyObjTwo(MyObjTwo),
} }
#[async_graphql::Union] #[derive(GQLUnion)]
enum UnionB { enum UnionB {
MyObjOne(MyObjOne), MyObjOne(MyObjOne),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn my_obj(&self) -> Vec<UnionA> { async fn my_obj(&self) -> Vec<UnionA> {
vec![MyObjOne.into(), MyObjTwo.into()] vec![MyObjOne.into(), MyObjTwo.into()]
@ -246,21 +246,21 @@ pub async fn test_multiple_objects_in_multiple_unions() {
pub async fn test_union_field_result() { pub async fn test_union_field_result() {
struct MyObj; struct MyObj;
#[async_graphql::Object] #[GQLObject]
impl MyObj { impl MyObj {
async fn value(&self) -> FieldResult<i32> { async fn value(&self) -> FieldResult<i32> {
Ok(10) Ok(10)
} }
} }
#[async_graphql::Union] #[derive(GQLUnion)]
enum Node { enum Node {
MyObj(MyObj), MyObj(MyObj),
} }
struct Query; struct Query;
#[Object] #[GQLObject]
impl Query { impl Query {
async fn node(&self) -> Node { async fn node(&self) -> Node {
MyObj.into() MyObj.into()

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_variables() { pub async fn test_variables() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
pub async fn int_val(&self, value: i32) -> i32 { pub async fn int_val(&self, value: i32) -> i32 {
value value
@ -42,7 +42,7 @@ pub async fn test_variables() {
pub async fn test_variable_default_value() { pub async fn test_variable_default_value() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
pub async fn int_val(&self, value: i32) -> i32 { pub async fn int_val(&self, value: i32) -> i32 {
value value
@ -71,7 +71,7 @@ pub async fn test_variable_default_value() {
pub async fn test_variable_no_value() { pub async fn test_variable_no_value() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
pub async fn int_val(&self, value: Option<i32>) -> i32 { pub async fn int_val(&self, value: Option<i32>) -> i32 {
value.unwrap_or(10) value.unwrap_or(10)
@ -102,7 +102,7 @@ pub async fn test_variable_no_value() {
pub async fn test_variable_null() { pub async fn test_variable_null() {
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
pub async fn int_val(&self, value: Option<i32>) -> i32 { pub async fn int_val(&self, value: Option<i32>) -> i32 {
value.unwrap_or(10) value.unwrap_or(10)
@ -131,14 +131,14 @@ pub async fn test_variable_null() {
#[async_std::test] #[async_std::test]
pub async fn test_variable_in_input_object() { pub async fn test_variable_in_input_object() {
#[InputObject] #[derive(GQLInputObject)]
struct MyInput { struct MyInput {
value: i32, value: i32,
} }
struct QueryRoot; struct QueryRoot;
#[Object] #[GQLObject]
impl QueryRoot { impl QueryRoot {
async fn test(&self, input: MyInput) -> i32 { async fn test(&self, input: MyInput) -> i32 {
input.value input.value
@ -151,7 +151,7 @@ pub async fn test_variable_in_input_object() {
struct MutationRoot; struct MutationRoot;
#[Object] #[GQLObject]
impl MutationRoot { impl MutationRoot {
async fn test(&self, input: MyInput) -> i32 { async fn test(&self, input: MyInput) -> i32 {
input.value input.value