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

View File

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

View File

@ -17,15 +17,14 @@ mod subscription;
mod union;
mod utils;
use crate::utils::{add_container_attrs, parse_derive};
use crate::utils::parse_derive;
use proc_macro::TokenStream;
use quote::quote;
use syn::parse_macro_input;
use syn::{AttributeArgs, ItemImpl};
#[proc_macro_attribute]
#[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)) {
Ok(object_args) => object_args,
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))]
pub fn derive_simple_object(input: TokenStream) -> TokenStream {
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))]
pub fn derive_enum(input: TokenStream) -> TokenStream {
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))]
pub fn derive_input_object(input: TokenStream) -> TokenStream {
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))]
pub fn derive_interface(input: TokenStream) -> TokenStream {
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))]
pub fn derive_union(input: TokenStream) -> TokenStream {
let (args, input) = match parse_derive(input.into()) {
@ -179,7 +118,7 @@ pub fn derive_union(input: TokenStream) -> TokenStream {
#[proc_macro_attribute]
#[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)) {
Ok(object_args) => object_args,
Err(err) => return err.to_compile_error().into(),
@ -193,7 +132,7 @@ pub fn Subscription(args: TokenStream, input: TokenStream) -> TokenStream {
#[proc_macro_attribute]
#[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)) {
Ok(scalar_args) => scalar_args,
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))]
pub fn derive_merged_object(input: TokenStream) -> TokenStream {
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))]
pub fn derive_merged_subscription(input: TokenStream) -> TokenStream {
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_macro_crate::crate_name;
use quote::quote;
use syn::{
Attribute, AttributeArgs, DeriveInput, Error, Expr, Ident, Lit, Meta, MetaList, NestedMeta,
Result,
};
use syn::{Attribute, DeriveInput, Error, Expr, Ident, Lit, Meta, MetaList, NestedMeta, Result};
pub fn get_crate_name(internal: bool) -> TokenStream {
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)> {
let mut input: DeriveInput = syn::parse2(input)?;
let attrs = &mut input.attrs;

View File

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

View File

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

View File

@ -487,13 +487,13 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
/// ```no_run
/// use async_graphql::*;
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct Detail {
/// c: i32,
/// d: i32,
/// }
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct MyObj {
/// a: i32,
/// b: i32,
@ -502,7 +502,7 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
///
/// struct Query;
///
/// #[Object]
/// #[GQLObject]
/// impl Query {
/// async fn obj(&self, ctx: &Context<'_>) -> MyObj {
/// 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.
///
/// ```ignore
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// async fn value(&self, ctx: &Context<'_>) -> { ... }
/// }
@ -244,7 +244,7 @@ pub use types::{EnumItem, EnumType};
/// value: i32,
/// }
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// #[field(desc = "value")]
/// 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
///
@ -322,7 +322,7 @@ pub use async_graphql_derive::Object;
/// ```rust
/// use async_graphql::*;
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct QueryRoot {
/// 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;
/// Define a GraphQL enum
@ -421,7 +363,7 @@ pub use async_graphql_derive::GQLSimpleObject;
/// ```rust
/// use async_graphql::*;
///
/// #[Enum]
/// #[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
/// enum MyEnum {
/// A,
/// #[item(name = "b")] B,
@ -432,7 +374,7 @@ pub use async_graphql_derive::GQLSimpleObject;
/// value2: MyEnum,
/// }
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// #[field(desc = "value")]
/// 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" }));
/// });
/// ```
pub use async_graphql_derive::Enum;
pub use async_graphql_derive::GQLEnum;
/// Define a GraphQL input object
///
@ -484,7 +426,7 @@ pub use async_graphql_derive::Enum;
/// ```rust
/// use async_graphql::*;
///
/// #[InputObject]
/// #[derive(GQLInputObject)]
/// struct MyInputObject {
/// a: i32,
/// #[field(default = 10)]
@ -493,7 +435,7 @@ pub use async_graphql_derive::Enum;
///
/// struct QueryRoot;
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// #[field(desc = "value")]
/// 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 }));
/// });
/// ```
pub use async_graphql_derive::InputObject;
pub use async_graphql_derive::GQLInputObject;
/// Define a GraphQL interface
///
@ -553,7 +495,7 @@ pub use async_graphql_derive::InputObject;
/// Define TypeA, TypeB, TypeC... Implement the MyInterface
///
/// ```ignore
/// #[Interface]
/// #[derive(GQLInterface)]
/// enum MyInterface {
/// TypeA(TypeA),
/// TypeB(TypeB),
@ -574,7 +516,7 @@ pub use async_graphql_derive::InputObject;
/// value: i32,
/// }
///
/// #[Object]
/// #[GQLObject]
/// impl TypeA {
/// /// Returns data borrowed from the context
/// 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_b", type = "&i32"),
/// field(name = "value_c", type = "i32",
@ -612,7 +555,7 @@ pub use async_graphql_derive::InputObject;
///
/// struct QueryRoot;
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// async fn type_a(&self) -> MyInterface {
/// 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;
/// Define a GraphQL union
@ -669,17 +605,17 @@ pub use async_graphql_derive::GQLInterface;
/// ```rust
/// use async_graphql::*;
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct TypeA {
/// value_a: i32,
/// }
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct TypeB {
/// value_b: i32
/// }
///
/// #[Union]
/// #[derive(GQLUnion)]
/// enum MyUnion {
/// TypeA(TypeA),
/// TypeB(TypeB),
@ -687,7 +623,7 @@ pub use async_graphql_derive::GQLInterface;
///
/// struct QueryRoot;
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// async fn all_data(&self) -> Vec<MyUnion> {
/// 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;
/// Define a GraphQL subscription
@ -763,25 +692,21 @@ pub use async_graphql_derive::GQLUnion;
///
/// # Examples
///
/// ```ignore
/// ```rust
/// use async_graphql::*;
///
/// #[Object]
/// struct Event {
/// value: i32,
/// }
/// use futures::{Stream, StreamExt};
///
/// struct SubscriptionRoot;
///
/// #[Subscription]
/// #[GQLSubscription]
/// impl SubscriptionRoot {
/// async fn value(&self, event: &Event, condition: i32) -> bool {
/// // Push when value is greater than condition
/// event.value > condition
/// async fn value(&self, condition: i32) -> impl Stream<Item = i32> {
/// // Returns the number from 0 to `condition`.
/// futures::stream::iter(0..condition)
/// }
/// }
/// ```
pub use async_graphql_derive::Subscription;
pub use async_graphql_derive::GQLSubscription;
/// Define a Scalar
///
@ -792,7 +717,7 @@ pub use async_graphql_derive::Subscription;
/// | name | Scalar name | 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.
///
@ -814,33 +739,26 @@ pub use async_graphql_derive::Scalar;
/// ```rust
/// use async_graphql::*;
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct Object1 {
/// a: i32,
/// }
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct Object2 {
/// b: i32,
/// }
///
/// #[SimpleObject]
/// #[derive(GQLSimpleObject)]
/// struct Object3 {
/// c: i32,
/// }
///
/// #[MergedObject]
/// #[derive(GQLMergedObject)]
/// struct MyObj(Object1, Object2, Object3);
///
/// 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;
/// Define a merged subscription with multiple subscription types.
@ -865,7 +783,7 @@ pub use async_graphql_derive::GQLMergedObject;
/// #[derive(Default)]
/// struct Subscription1;
///
/// #[Subscription]
/// #[GQLSubscription]
/// impl Subscription1 {
/// async fn events1(&self) -> impl Stream<Item = i32> {
/// futures::stream::iter(0..10)
@ -875,7 +793,7 @@ pub use async_graphql_derive::GQLMergedObject;
/// #[derive(Default)]
/// struct Subscription2;
///
/// #[Subscription]
/// #[GQLSubscription]
/// impl Subscription2 {
/// async fn events2(&self) -> impl Stream<Item = i32> {
/// futures::stream::iter(10..20)
@ -885,11 +803,4 @@ pub use async_graphql_derive::GQLMergedObject;
/// #[derive(GQLMergedSubscription, Default)]
/// 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;

View File

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

View File

@ -1,10 +1,9 @@
use crate::model::__InputValue;
use crate::registry;
use async_graphql_derive::{Enum, Object};
use crate::{registry, GQLEnum, GQLObject};
/// A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.
#[Enum(internal)]
#[derive(Debug)]
#[derive(Debug, GQLEnum, Copy, Clone, Eq, PartialEq)]
#[graphql(internal)]
#[allow(non_camel_case_types)]
pub enum __DirectiveLocation {
/// 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.
//
// 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> {
async fn name(&self) -> String {
self.directive.name.to_string()

View File

@ -1,5 +1,4 @@
use crate::registry;
use async_graphql_derive::Object;
use crate::{registry, GQLObject};
pub struct __EnumValue<'a> {
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.
#[Object(internal)]
#[GQLObject(internal)]
impl<'a> __EnumValue<'a> {
async fn name(&self) -> String {
self.value.name.to_string()

View File

@ -1,6 +1,5 @@
use crate::model::{__InputValue, __Type};
use crate::registry;
use async_graphql_derive::Object;
use crate::{registry, GQLObject};
use itertools::Itertools;
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(internal)]
#[GQLObject(internal)]
impl<'a> __Field<'a> {
async fn name(&self) -> String {
self.field.name.to_string()

View File

@ -1,6 +1,5 @@
use crate::model::__Type;
use crate::registry;
use async_graphql_derive::Object;
use crate::{registry, GQLObject};
pub struct __InputValue<'a> {
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.
#[Object(internal)]
#[GQLObject(internal)]
impl<'a> __InputValue<'a> {
async fn name(&self) -> 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.
#[Enum(internal)]
#[derive(GQLEnum, Copy, Clone, Eq, PartialEq)]
#[graphql(internal)]
pub enum __TypeKind {
/// Indicates this type is a scalar.
Scalar,

View File

@ -1,6 +1,5 @@
use crate::model::{__Directive, __Type};
use crate::registry;
use async_graphql_derive::Object;
use crate::{registry, GQLObject};
use itertools::Itertools;
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.
#[Object(internal)]
#[GQLObject(internal)]
impl<'a> __Schema<'a> {
/// A list of all types supported by this server.
async fn types(&self) -> Vec<__Type<'a>> {

View File

@ -1,6 +1,5 @@
use crate::model::{__EnumValue, __Field, __InputValue, __TypeKind};
use crate::registry;
use async_graphql_derive::Object;
use crate::{registry, GQLObject};
use itertools::Itertools;
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.
///
/// 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> {
async fn kind(&self) -> __TypeKind {
match &self.detail {

View File

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

View File

@ -1,5 +1,4 @@
use crate::{InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use crate::{GQLScalar, InputValueResult, ScalarType, Value};
use serde::de::DeserializeOwned;
/// Any scalar
@ -9,7 +8,7 @@ use serde::de::DeserializeOwned;
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.
#[Scalar(internal, name = "_Any")]
#[GQLScalar(internal, name = "_Any")]
impl ScalarType for Any {
fn parse(value: Value) -> InputValueResult<Self> {
Ok(Self(value))

View File

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

View File

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

View File

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

View File

@ -1,8 +1,7 @@
use crate::{InputValueError, InputValueResult, ScalarType, Value};
use async_graphql_derive::Scalar;
use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
/// 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 {
fn parse(value: Value) -> InputValueResult<Self> {
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).
#[Scalar(internal, name = "Float")]
#[GQLScalar(internal, name = "Float")]
impl ScalarType for f64 {
fn parse(value: Value) -> InputValueResult<Self> {
match value {

View File

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

View File

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

View File

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

View File

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

View File

@ -1,13 +1,12 @@
use crate::parser::types::Field;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, OutputValueType, Positioned,
Result, ScalarType, Type, Value,
registry, ContextSelectionSet, GQLScalar, InputValueError, InputValueResult, OutputValueType,
Positioned, Result, ScalarType, Type, Value,
};
use async_graphql_derive::Scalar;
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.
#[Scalar(internal)]
#[GQLScalar(internal)]
impl ScalarType for String {
fn parse(value: Value) -> InputValueResult<Self> {
match value {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,15 +3,16 @@ use crate::parser::types::Field;
use crate::resolver_utils::{resolve_object, ObjectType};
use crate::scalars::Any;
use crate::{
registry, Context, ContextSelectionSet, Error, OutputValueType, Positioned, QueryError, Result,
Type,
registry, Context, ContextSelectionSet, Error, GQLSimpleObject, OutputValueType, Positioned,
QueryError, Result, Type,
};
use async_graphql_derive::SimpleObject;
use indexmap::map::IndexMap;
use std::borrow::Cow;
/// Federation service
#[SimpleObject(internal, name = "_Service")]
#[derive(GQLSimpleObject)]
#[graphql(internal, name = "_Service")]
struct Service {
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>)*
///
/// ```
/// use async_graphql::Upload;
/// use async_graphql::*;
///
/// struct MutationRoot;
///
/// #[async_graphql::Object]
/// #[GQLObject]
/// impl MutationRoot {
/// async fn upload(&self, file: Upload) -> bool {
/// println!("upload: filename={}", file.filename());

View File

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

View File

@ -22,7 +22,7 @@ pub use string_validators::{Email, StringMaxLength, StringMinLength, MAC};
///
/// struct QueryRoot;
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// // Input is email address
/// 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;
#[Object]
#[GQLObject]
impl MyObj {
async fn a(&self) -> i32 {
1
@ -21,7 +21,7 @@ pub async fn test_complexity_and_depth() {
}
}
#[Object]
#[GQLObject]
impl Query {
async fn value(&self) -> i32 {
1

View File

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

View File

@ -4,7 +4,7 @@ use async_graphql::*;
pub async fn test_default_value_arg() {
struct Query;
#[Object]
#[GQLObject]
impl Query {
async fn value1(&self, #[arg(default = 100)] input: i32) -> i32 {
input
@ -44,7 +44,7 @@ pub async fn test_default_value_arg() {
#[async_std::test]
pub async fn test_default_value_inputobject() {
#[InputObject]
#[derive(GQLInputObject)]
struct MyInput {
#[field(default = 100)]
value1: i32,
@ -56,7 +56,7 @@ pub async fn test_default_value_inputobject() {
value3: i32,
}
#[SimpleObject]
#[derive(GQLSimpleObject)]
struct MyOutput {
value1: i32,
value2: i32,
@ -65,7 +65,7 @@ pub async fn test_default_value_inputobject() {
struct Query;
#[Object]
#[GQLObject]
impl Query {
async fn value(&self, input: MyInput) -> 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() {
struct QueryRoot;
#[Object]
#[GQLObject]
impl QueryRoot {
pub async fn value(&self) -> i32 {
10
@ -34,7 +34,7 @@ pub async fn test_directive_skip() {
pub async fn test_directive_include() {
struct QueryRoot;
#[Object]
#[GQLObject]
impl QueryRoot {
pub async fn value(&self) -> i32 {
10
@ -64,7 +64,7 @@ pub async fn test_directive_include() {
pub async fn test_directive_ifdef() {
struct QueryRoot;
#[Object]
#[GQLObject]
impl QueryRoot {
pub async fn value1(&self) -> i32 {
10
@ -73,7 +73,7 @@ pub async fn test_directive_ifdef() {
struct MutationRoot;
#[Object]
#[GQLObject]
impl MutationRoot {
pub async fn action1(&self) -> i32 {
10

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ use async_graphql::*;
#[async_std::test]
pub async fn test_input_object_default_value() {
#[InputObject]
#[derive(GQLInputObject)]
struct MyInput {
#[field(default = 999)]
a: i32,
@ -28,7 +28,7 @@ pub async fn test_input_object_default_value() {
e: Option<i32>,
}
#[Object]
#[GQLObject]
impl MyOutput {
async fn a(&self) -> i32 {
self.a
@ -53,7 +53,7 @@ pub async fn test_input_object_default_value() {
struct Root;
#[Object]
#[GQLObject]
impl Root {
async fn a(&self, input: MyInput) -> MyOutput {
MyOutput {
@ -91,8 +91,7 @@ pub async fn test_input_object_default_value() {
pub async fn test_inputobject_derive_and_item_attributes() {
use serde::Deserialize;
#[InputObject]
#[derive(Deserialize, PartialEq, Debug)]
#[derive(Deserialize, PartialEq, Debug, GQLInputObject)]
struct MyInputObject {
#[serde(alias = "other")]
real: i32,
@ -164,7 +163,7 @@ pub async fn test_inputobject_flatten_recursive() {
struct Query;
#[Object]
#[GQLObject]
impl Query {
async fn test(&self, input: MyInputObject) -> i32 {
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() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputMaxLength {
#[field(validator(StringMinLength(length = "6")))]
pub id: String,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -125,13 +125,13 @@ pub async fn test_input_validator_string_min_length() {
pub async fn test_input_validator_string_max_length() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputMaxLength {
#[field(validator(StringMaxLength(length = "6")))]
pub id: String,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -235,13 +235,13 @@ pub async fn test_input_validator_string_max_length() {
pub async fn test_input_validator_string_email() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputEmail {
#[field(validator(Email))]
pub email: String,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(&self, #[arg(validator(Email))] _email: String) -> bool {
true
@ -376,19 +376,19 @@ pub async fn test_input_validator_string_mac() {
struct QueryRootWithColon;
struct QueryRootWithoutColon;
#[InputObject]
#[derive(GQLInputObject)]
struct InputMACWithColon {
#[field(validator(MAC(colon = "true")))]
pub mac: String,
}
#[InputObject]
#[derive(GQLInputObject)]
struct InputMACWithoutColon {
#[field(validator(MAC(colon = "false")))]
pub mac: String,
}
#[Object]
#[GQLObject]
impl QueryRootWithColon {
async fn field_parameter(
&self,
@ -402,7 +402,7 @@ pub async fn test_input_validator_string_mac() {
}
}
#[Object]
#[GQLObject]
impl QueryRootWithoutColon {
async fn field_parameter(
&self,
@ -665,13 +665,13 @@ pub async fn test_input_validator_string_mac() {
pub async fn test_input_validator_int_range() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputIntRange {
#[field(validator(IntRange(min = "-2", max = "5")))]
pub id: i32,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -767,13 +767,13 @@ pub async fn test_input_validator_int_range() {
pub async fn test_input_validator_int_less_than() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputIntLessThan {
#[field(validator(IntLessThan(value = "5")))]
pub id: i32,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -872,13 +872,13 @@ pub async fn test_input_validator_int_less_than() {
pub async fn test_input_validator_int_greater_than() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputIntGreaterThan {
#[field(validator(IntGreaterThan(value = "3")))]
pub id: i32,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -979,13 +979,13 @@ pub async fn test_input_validator_int_greater_than() {
pub async fn test_input_validator_int_nonzero() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputIntNonZero {
#[field(validator(IntNonZero))]
pub id: i32,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(&self, #[arg(validator(IntNonZero))] _id: i32) -> bool {
true
@ -1079,13 +1079,13 @@ pub async fn test_input_validator_int_nonzero() {
pub async fn test_input_validator_int_equal() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputIntEqual {
#[field(validator(IntEqual(value = "5")))]
pub id: i32,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(&self, #[arg(validator(IntEqual(value = "5")))] _id: i32) -> bool {
true
@ -1180,13 +1180,13 @@ pub async fn test_input_validator_int_equal() {
pub async fn test_input_validator_list_max_length() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputListMaxLength {
#[field(validator(ListMaxLength(length = "5")))]
pub id: Vec<i32>,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -1296,13 +1296,13 @@ pub async fn test_input_validator_list_max_length() {
pub async fn test_input_validator_list_min_length() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputListMinLength {
#[field(validator(ListMinLength(length = "4")))]
pub id: Vec<i32>,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -1412,13 +1412,13 @@ pub async fn test_input_validator_list_min_length() {
pub async fn test_input_validator_operator_or() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputOrValidator {
#[field(validator(or(Email, MAC(colon = "false"))))]
pub id: String,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -1536,13 +1536,13 @@ pub async fn test_input_validator_operator_or() {
pub async fn test_input_validator_operator_and() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputAndValidator {
#[field(validator(and(Email, StringMinLength(length = "14"))))]
pub email: String,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,
@ -1653,13 +1653,13 @@ pub async fn test_input_validator_operator_and() {
pub async fn test_input_validator_variable() {
struct QueryRoot;
#[InputObject]
#[derive(GQLInputObject)]
struct InputMaxLength {
#[field(validator(StringMinLength(length = "6")))]
pub id: String,
}
#[Object]
#[GQLObject]
impl QueryRoot {
async fn field_parameter(
&self,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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