Rename object proc macro to graphql_object

This commit is contained in:
Christoph Herzog 2019-11-16 02:43:39 +01:00
parent a31d3f3888
commit ce3cf45ca9
47 changed files with 126 additions and 116 deletions

View file

@ -44,7 +44,7 @@ impl juniper::Context for Context {}
struct Query;
#[juniper::object(
#[juniper::graphql_object(
Context = Context,
)]
impl Query {

View file

@ -23,7 +23,7 @@ enum SignUpResult {
Error(Vec<ValidationError>),
}
#[juniper::object]
#[juniper::graphql_object]
impl SignUpResult {
fn user(&self) -> Option<&User> {
match *self {

View file

@ -25,7 +25,7 @@ struct ValidationError {
# #[allow(dead_code)]
struct MutationResult<T>(Result<T, Vec<ValidationError>>);
#[juniper::object(
#[juniper::graphql_object(
name = "UserResult",
)]
impl MutationResult<User> {
@ -38,7 +38,7 @@ impl MutationResult<User> {
}
}
#[juniper::object(
#[juniper::graphql_object(
name = "ForumPostResult",
)]
impl MutationResult<ForumPost> {

View file

@ -74,7 +74,7 @@ impl juniper::Context for Context {}
struct Query;
#[juniper::object(
#[juniper::graphql_object(
// Here we specify the context type for the object.
// We need to do this in every type that
// needs access to the context.
@ -105,7 +105,7 @@ impl Query {
struct Mutation;
#[juniper::object(
#[juniper::graphql_object(
Context = Context,
)]
impl Mutation {
@ -156,7 +156,7 @@ impl juniper::Context for Ctx {}
struct Query;
#[juniper::object(
#[juniper::graphql_object(
Context = Ctx,
)]
impl Query {

View file

@ -27,7 +27,7 @@ object in Juniper, most commonly using the `object` proc macro:
# #[derive(juniper::GraphQLObject)] struct User { name: String }
struct Root;
#[juniper::object]
#[juniper::graphql_object]
impl Root {
fn userWithUsername(username: String) -> FieldResult<Option<User>> {
// Look up user in database...
@ -48,7 +48,7 @@ usually performs some mutating side-effect, such as updating a database.
# #[derive(juniper::GraphQLObject)] struct User { name: String }
struct Mutations;
#[juniper::object]
#[juniper::graphql_object]
impl Mutations {
fn signUpUser(name: String, email: String) -> FieldResult<User> {
// Validate inputs and save user in database...

View file

@ -47,7 +47,7 @@ fn context_factory(_: &mut Request) -> IronResult<()> {
struct Root;
#[juniper::object]
#[juniper::graphql_object]
impl Root {
fn foo() -> String {
"Bar".to_owned()
@ -99,7 +99,7 @@ fn context_factory(req: &mut Request) -> IronResult<Context> {
struct Root;
#[juniper::object(
#[juniper::graphql_object(
Context = Context,
)]
impl Root {

View file

@ -14,7 +14,7 @@ struct Coordinate {
struct Root;
# #[derive(juniper::GraphQLObject)] struct User { name: String }
#[juniper::object]
#[juniper::graphql_object]
impl Root {
fn users_at_location(coordinate: Coordinate, radius: f64) -> Vec<User> {
// Send coordinate to database
@ -45,7 +45,7 @@ struct WorldCoordinate {
struct Root;
# #[derive(juniper::GraphQLObject)] struct User { name: String }
#[juniper::object]
#[juniper::graphql_object]
impl Root {
fn users_at_location(coordinate: WorldCoordinate, radius: f64) -> Vec<User> {
// Send coordinate to database

View file

@ -14,7 +14,7 @@ struct Person {
age: i32,
}
#[juniper::object]
#[juniper::graphql_object]
impl Person {
fn name(&self) -> &str {
self.name.as_str()
@ -43,7 +43,7 @@ struct House {
inhabitants: Vec<Person>,
}
#[juniper::object]
#[juniper::graphql_object]
impl House {
// Creates the field inhabitantWithName(name), returning a nullable person
fn inhabitant_with_name(&self, name: String) -> Option<&Person> {
@ -70,7 +70,7 @@ struct Person {
}
/// Doc comments are used as descriptions for GraphQL.
#[juniper::object(
#[juniper::graphql_object(
// With this attribtue you can change the public GraphQL name of the type.
name = "PersonObject",
// You can also specify a description here, which will overwrite
@ -125,7 +125,7 @@ This will become better once the [Rust RFC 2565](https://github.com/rust-lang/ru
struct Person {}
#[juniper::object]
#[juniper::graphql_object]
impl Person {
#[graphql(
arguments(

View file

@ -25,7 +25,7 @@ struct Example {
filename: PathBuf,
}
#[juniper::object]
#[juniper::graphql_object]
impl Example {
fn contents() -> FieldResult<String> {
let mut file = File::open(&self.filename)?;
@ -143,7 +143,7 @@ struct Example {
whatever: Option<bool>,
}
#[juniper::object]
#[juniper::graphql_object]
impl Example {
fn whatever() -> Result<bool, CustomError> {
if let Some(value) = self.whatever {

View file

@ -57,7 +57,7 @@ struct User {
// Assign Database as the context type for User
#[juniper::object(
#[juniper::graphql_object(
Context = Database,
)]
impl User {

View file

@ -24,7 +24,7 @@ struct User {
name: String,
}
#[juniper::object(Context = Context)]
#[juniper::graphql_object(Context = Context)]
impl User {
fn id(&self) -> i32 {
self.id
@ -45,7 +45,7 @@ impl User {
struct Query;
#[juniper::object(Context = Context)]
#[juniper::graphql_object(Context = Context)]
impl Query {
async fn users() -> Vec<User> {
vec![

View file

@ -13,7 +13,7 @@ struct User {
kind: UserKind,
}
#[juniper::object]
#[juniper::graphql_object]
impl User {
async fn name(&self) -> &str {
&self.name
@ -43,7 +43,7 @@ impl User {
struct Query;
#[juniper::object]
#[juniper::graphql_object]
impl Query {
fn field_sync(&self) -> &'static str {
"field_sync"
@ -70,7 +70,7 @@ impl Query {
struct Mutation;
#[juniper::object]
#[juniper::graphql_object]
impl Mutation {}
fn run<O>(f: impl std::future::Future<Output = O>) -> O {

View file

@ -79,7 +79,7 @@ struct WithCustomContext {
a: bool,
}
#[juniper::object]
#[juniper::graphql_object]
impl Query {
fn obj() -> Obj {
Obj {

View file

@ -11,7 +11,7 @@ use juniper::{
pub struct Query;
#[juniper::object]
#[juniper::graphql_object]
impl Query {
fn r#type(r#fn: MyInputType) -> Vec<String> {
unimplemented!()

View file

@ -22,7 +22,7 @@ struct User {
struct User2;
#[juniper::object]
#[juniper::graphql_object]
impl User2 {
fn id(&self) -> UserId {
UserId("id".to_string())

View file

@ -160,7 +160,7 @@ juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue {
struct TestType;
#[juniper::object(
#[juniper::graphql_object(
Scalar = MyScalarValue
)]
impl TestType {

View file

@ -7,37 +7,44 @@ impl juniper::Context for Context {}
pub struct Query;
graphql_object!(Query: Context |&self| {
field users(&executor) -> Vec<User> {
#[graphql_object(
Context = Context
)]
impl Query {
fn users(exec: &Executor) -> Vec<User> {
let lh = executor.look_ahead();
assert_eq!(lh.field_name(), "users");
vec![User]
}
field countries(&executor) -> Vec<Country> {
fn countries(exec: &Executor) -> Vec<Country> {
let lh = executor.look_ahead();
assert_eq!(lh.field_name(), "countries");
vec![Country]
}
});
}
#[derive(Clone)]
pub struct User;
graphql_object!(User: Context |&self| {
field id() -> i32 {
#[graphql_object(
Context = Context
)]
impl User {
fn id() -> i32 {
1
}
});
}
#[derive(Clone)]
pub struct Country;
graphql_object!(Country: Context |&self| {
field id() -> i32 {
#[graphql_object]
impl Country {
fn id() -> i32 {
2
}
});
}
type Schema = juniper::RootNode<'static, Query, EmptyMutation<Context>>;

View file

@ -3,7 +3,7 @@ use juniper::*;
struct Query;
#[juniper::object]
#[juniper::graphql_object]
impl Query {
fn users(executor: &Executor) -> Vec<User> {
// This doesn't cause a panic
@ -19,7 +19,7 @@ struct User {
country: Country,
}
#[juniper::object]
#[juniper::graphql_object]
impl User {
fn country(&self, executor: &Executor) -> &Country {
// This panics!
@ -33,7 +33,7 @@ struct Country {
id: i32,
}
#[juniper::object]
#[juniper::graphql_object]
impl Country {
fn id(&self) -> i32 {
self.id

View file

@ -6,6 +6,8 @@
## Breaking Changes
- remove old `graphql_object!` macro, rename `object` proc macro to `graphql_object`
- Remove deprecated `ScalarValue` custom derive (renamed to GraphQLScalarValue)
- `graphql_union!` macro removed, replaced by `#[graphql_union]` proc macro

View file

@ -13,7 +13,7 @@ struct User {
kind: UserKind,
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl User {
async fn name(&self) -> &str {
&self.name
@ -43,7 +43,7 @@ impl User {
struct Query;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Query {
fn field_sync(&self) -> &'static str {
"field_sync"
@ -70,7 +70,7 @@ impl Query {
struct Mutation;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Mutation {}
fn run<O>(f: impl std::future::Future<Output = O>) -> O {

View file

@ -7,7 +7,7 @@ use crate::{
struct TestType;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl TestType {
fn a() -> &str {
"a"

View file

@ -19,7 +19,7 @@ enum Color {
}
struct TestType;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl TestType {
fn to_string(color: Color) -> String {
format!("Color::{:?}", color)

View file

@ -6,7 +6,7 @@ mod field_execution {
struct DataType;
struct DeepDataType;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl DataType {
fn a() -> &str {
"Apple"
@ -36,7 +36,7 @@ mod field_execution {
}
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl DeepDataType {
fn a() -> &str {
"Already Been Done"
@ -159,7 +159,7 @@ mod merge_parallel_fragments {
struct Type;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Type {
fn a() -> &str {
"Apple"
@ -241,7 +241,7 @@ mod merge_parallel_inline_fragments {
struct Type;
struct Other;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Type {
fn a() -> &str {
"Apple"
@ -260,7 +260,7 @@ mod merge_parallel_inline_fragments {
}
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Other {
fn a() -> &str {
"Apple"
@ -390,7 +390,7 @@ mod threads_context_correctly {
impl Context for TestContext {}
#[crate::object_internal(
#[crate::graphql_object_internal(
Context = TestContext,
)]
impl Schema {
@ -458,7 +458,7 @@ mod dynamic_context_switching {
struct ItemRef;
#[crate::object_internal(Context = OuterContext)]
#[crate::graphql_object_internal(Context = OuterContext)]
impl Schema {
fn item_opt(context: &OuterContext, key: i32) -> Option<(&InnerContext, ItemRef)> {
executor.context().items.get(&key).map(|c| (c, ItemRef))
@ -488,7 +488,7 @@ mod dynamic_context_switching {
}
}
#[crate::object_internal(Context = InnerContext)]
#[crate::graphql_object_internal(Context = InnerContext)]
impl ItemRef {
fn value(context: &InnerContext) -> String {
context.value.clone()
@ -799,7 +799,7 @@ mod propagates_errors_to_nullable_fields {
}
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Schema {
fn inner() -> Inner {
Inner
@ -812,7 +812,7 @@ mod propagates_errors_to_nullable_fields {
}
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Inner {
fn nullable_field() -> Option<Inner> {
Some(Inner)
@ -1065,7 +1065,7 @@ mod named_operations {
struct Schema;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Schema {
fn a() -> &str {
"b"

View file

@ -35,7 +35,7 @@ mod interface {
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
interfaces = [&dyn Pet]
)]
impl Dog {
@ -61,7 +61,7 @@ mod interface {
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
interfaces = [&dyn Pet]
)]
impl Cat {
@ -77,7 +77,7 @@ mod interface {
pets: Vec<Box<dyn Pet>>,
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Schema {
fn pets(&self) -> Vec<&dyn Pet> {
self.pets.iter().map(|p| p.as_ref()).collect()
@ -187,7 +187,7 @@ mod union {
}
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Dog {
fn name(&self) -> &str {
&self.name
@ -208,7 +208,7 @@ mod union {
}
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Cat {
fn name(&self) -> &str {
&self.name
@ -222,7 +222,7 @@ mod union {
pets: Vec<Box<dyn Pet>>,
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Schema {
fn pets(&self) -> Vec<&dyn Pet> {
self.pets.iter().map(|p| p.as_ref()).collect()

View file

@ -66,7 +66,7 @@ enum EnumDeprecation {
struct Root;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Root {
fn default_name() -> DefaultName {
DefaultName::Foo

View file

@ -81,7 +81,7 @@ struct FieldWithDefaults {
field_two: i32,
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Root {
fn test_field(
a1: DefaultName,

View file

@ -54,7 +54,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| {
});
/// The root query object in the schema
#[crate::object_internal(
#[crate::graphql_object_internal(
interfaces = [&Interface]
Scalar = crate::DefaultScalarValue,
)]

View file

@ -64,7 +64,7 @@ struct InputWithDefaults {
a: i32,
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl TestType {
fn field_with_object_input(input: Option<TestInputObject>) -> String {
format!("{:?}", input)

View file

@ -210,7 +210,7 @@ mod integration_test {
fn test_serialization() {
struct Root;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Root {
fn exampleNaiveDate() -> NaiveDate {
NaiveDate::from_ymd(2015, 3, 14)

View file

@ -110,14 +110,15 @@ extern crate uuid;
// This allows users to just depend on juniper and get the derive
// functionality automatically.
pub use juniper_codegen::{
graphql_union, object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue,
graphql_object, graphql_union, GraphQLEnum, GraphQLInputObject, GraphQLObject,
GraphQLScalarValue,
};
// Internal macros are not exported,
// but declared at the root to make them easier to use.
#[allow(unused_imports)]
use juniper_codegen::{
graphql_union_internal, object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal,
GraphQLScalarValueInternal,
graphql_object_internal, graphql_union_internal, GraphQLEnumInternal,
GraphQLInputObjectInternal, GraphQLScalarValueInternal,
};
#[macro_use]

View file

@ -61,12 +61,12 @@ impl Character for Droid {
fn id(&self) -> &str { &self.id }
}
#[juniper::object(Context = Database)]
#[juniper::graphql_object(Context = Database)]
impl Human {
fn id(&self) -> &str { &self.id }
}
#[juniper::object(
#[juniper::graphql_object(
name = "Droid",
Context = Database,
)]

View file

@ -28,7 +28,7 @@ struct Point {
x: i32,
}
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Root {
fn simple() -> i32 {
0

View file

@ -22,7 +22,7 @@ Syntax to validate:
*/
#[crate::object_internal(
#[crate::graphql_object_internal(
interfaces = [&Interface],
)]
impl Root {

View file

@ -12,7 +12,7 @@ struct WithLifetime<'a> {
value: &'a str,
}
#[crate::object_internal(Context=Context)]
#[crate::graphql_object_internal(Context=Context)]
impl<'a> WithLifetime<'a> {
fn value(&'a self) -> &'a str {
self.value
@ -21,7 +21,7 @@ impl<'a> WithLifetime<'a> {
struct WithContext;
#[crate::object_internal(Context=Context)]
#[crate::graphql_object_internal(Context=Context)]
impl WithContext {
fn ctx(ctx: &Context) -> bool {
ctx.flag1
@ -33,7 +33,7 @@ struct Query {
b: bool,
}
#[crate::object_internal(
#[crate::graphql_object_internal(
scalar = crate::DefaultScalarValue,
name = "Query",
context = Context,
@ -115,7 +115,7 @@ impl<'a> Query {
#[derive(Default)]
struct Mutation;
#[crate::object_internal(context = Context)]
#[crate::graphql_object_internal(context = Context)]
impl Mutation {
fn empty() -> bool {
true

View file

@ -44,7 +44,7 @@ struct ResolversWithTrailingComma;
struct Root;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Concrete {
fn simple() -> i32 {
0
@ -113,7 +113,7 @@ graphql_interface!(ResolversWithTrailingComma: () |&self| {
field simple() -> i32 { 0 }
});
#[crate::object_internal(
#[crate::graphql_object_internal(
// FIXME: make async work
noasync
)]

View file

@ -1,5 +1,5 @@
// TODO: make sure proc macro tests cover all
// variants of the below
// variants of the below
/*
use std::marker::PhantomData;

View file

@ -80,7 +80,7 @@ graphql_scalar!(ScalarDescription {
}
});
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Root {
fn default_name() -> DefaultName {
DefaultName(0)

View file

@ -38,7 +38,7 @@ enum DescriptionFirst {
struct Root;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl Concrete {
fn simple() -> i32 {
123
@ -90,7 +90,7 @@ impl DescriptionFirst {
}
// FIXME: make async work
#[crate::object_internal(noasync)]
#[crate::graphql_object_internal(noasync)]
impl<'a> Root {
fn custom_name() -> CustomName {
CustomName::Concrete(Concrete)

View file

@ -149,7 +149,7 @@ fn errors() {
fn issue_427_panic_is_not_expected() {
struct QueryWithoutFloat;
#[crate::object_internal]
#[crate::graphql_object_internal]
impl QueryWithoutFloat {
fn echo(value: String) -> String {
value

View file

@ -36,7 +36,7 @@ struct Foo {
struct Query;
#[crate::object_internal(Scalar = S)]
#[crate::graphql_object_internal(Scalar = S)]
impl<'a, S> Query
where
S: crate::ScalarValue + 'a,

View file

@ -106,7 +106,7 @@ where
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
name = "__Schema"
Context = SchemaType<'a, S>,
Scalar = S,
@ -145,7 +145,7 @@ where
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
name = "__Type"
Context = SchemaType<'a, S>,
Scalar = S,
@ -278,7 +278,7 @@ where
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
name = "__Field",
Context = SchemaType<'a, S>,
Scalar = S,
@ -317,7 +317,7 @@ where
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
name = "__InputValue",
Context = SchemaType<'a, S>,
Scalar = S,
@ -346,7 +346,7 @@ where
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
name = "__EnumValue",
Scalar = S,
// FIXME: make this redundant.
@ -373,7 +373,7 @@ where
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
name = "__Directive",
Context = SchemaType<'a, S>,
Scalar = S,

View file

@ -33,7 +33,7 @@ graphql_interface!(<'a> &'a dyn Character: Database as "Character" |&self| {
}
});
#[crate::object_internal(
#[crate::graphql_object_internal(
Context = Database,
Scalar = crate::DefaultScalarValue,
interfaces = [&dyn Character],
@ -68,7 +68,7 @@ impl<'a> &'a dyn Human {
}
}
#[crate::object_internal(
#[crate::graphql_object_internal(
Context = Database,
Scalar = crate::DefaultScalarValue,
interfaces = [&dyn Character],
@ -105,7 +105,7 @@ impl<'a> &'a dyn Droid {
pub struct Query;
#[crate::object_internal(
#[crate::graphql_object_internal(
Context = Database,
Scalar = crate::DefaultScalarValue,
// FIXME: make async work

View file

@ -1,5 +1,5 @@
use juniper::{
object, DefaultScalarValue, ExecutionError, FieldError, GraphQLEnum, Value, Variables,
graphql_object, DefaultScalarValue, ExecutionError, FieldError, GraphQLEnum, Value, Variables,
};
pub type QueryResult = Result<
@ -56,12 +56,12 @@ impl User {
}
}
#[object(Context = Context)]
#[graphql_object(Context = Context)]
impl User {}
pub struct Query;
#[object(Context = Context)]
#[graphql_object(Context = Context)]
impl Query {
fn user_sync_instant(id: i32) -> Result<User, FieldError> {
Ok(User::new(id))
@ -92,7 +92,7 @@ impl Query {
pub struct Mutation;
#[object(Context = Context)]
#[graphql_object(Context = Context)]
impl Mutation {}
pub fn new_schema() -> juniper::RootNode<'static, Query, Mutation> {

View file

@ -2,7 +2,7 @@ use crate::util;
use proc_macro::TokenStream;
use quote::quote;
/// Generate code for the juniper::object macro.
/// Generate code for the juniper::graphql_object macro.
pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) -> TokenStream {
let impl_attrs = match syn::parse::<util::ObjectAttributes>(args) {
Ok(attrs) => attrs,
@ -20,7 +20,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
let mut _impl = match item {
syn::Item::Impl(_impl) => _impl,
_ => {
panic!("#[juniper::object] can only be applied to impl blocks");
panic!("#[juniper::graphql_object] can only be applied to impl blocks");
}
};
@ -47,7 +47,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
if let Some(ident) = util::name_of_type(&*_impl.self_ty) {
ident.to_string()
} else {
panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")");
panic!("Could not determine a name for the object type: specify one with #[juniper::graphql_object(name = \"SomeName\")");
}
};

View file

@ -135,7 +135,7 @@ More advanced use cases are introduced step by step.
struct Query;
// We prefix the impl Block with the procedural macro.
#[juniper::object]
#[juniper::graphql_object]
impl Query {
// A **warning**: only GraphQL fields can be specified in this impl block.
@ -186,7 +186,7 @@ impl Person {
}
}
#[juniper::object]
#[juniper::graphql_object]
impl Person {
fn first_name(&self) -> &str {
&self.first_name
@ -226,7 +226,7 @@ impl juniper::Context for Context {}
struct Query;
#[juniper::object(
#[juniper::graphql_object(
// Here we specify the context type for this object.
Context = Context,
)]
@ -256,7 +256,7 @@ struct InternalQuery;
// Doc comments can be used to specify graphql documentation.
/// GRAPHQL DOCUMENTATION.
/// More info for GraphQL users....
#[juniper::object(
#[juniper::graphql_object(
// You can rename the type for GraphQL by specifying the name here.
name = "Query",
// You can also specify a description here.
@ -319,7 +319,7 @@ struct WithLifetime<'a> {
value: &'a str,
}
#[juniper::object]
#[juniper::graphql_object]
impl<'a> WithLifetime<'a> {
fn value(&self) -> &str {
self.value
@ -340,7 +340,7 @@ You can easily specify a custom scalar though.
struct Query;
#[juniper::object(
#[juniper::graphql_object(
Scalar = MyCustomScalar,
)]
impl Query {
@ -358,7 +358,7 @@ struct User {
r#type: String,
}
#[juniper::object]
#[juniper::graphql_object]
impl User {
fn r#type(&self) -> &str {
&self.r#type
@ -368,7 +368,7 @@ impl User {
*/
#[proc_macro_attribute]
pub fn object(args: TokenStream, input: TokenStream) -> TokenStream {
pub fn graphql_object(args: TokenStream, input: TokenStream) -> TokenStream {
let gen = impl_object::build_object(args, input, false);
gen.into()
}
@ -376,7 +376,7 @@ pub fn object(args: TokenStream, input: TokenStream) -> TokenStream {
/// A proc macro for defining a GraphQL object.
#[doc(hidden)]
#[proc_macro_attribute]
pub fn object_internal(args: TokenStream, input: TokenStream) -> TokenStream {
pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenStream {
let gen = impl_object::build_object(args, input, true);
gen.into()
}

View file

@ -37,7 +37,7 @@ use juniper::{Context, EmptyMutation};
# struct QueryRoot;
# struct Database { users: HashMap<String, User> }
#
# #[juniper::object( Context = Database )]
# #[juniper::graphql_object( Context = Database )]
# impl User {
# fn id(&self) -> FieldResult<&String> {
# Ok(&self.id)
@ -54,7 +54,7 @@ use juniper::{Context, EmptyMutation};
# }
# }
#
# #[juniper::object( Context = Database )]
# #[juniper::graphql_object( Context = Database )]
# impl QueryRoot {
# fn user(context: &Database, id: String) -> FieldResult<Option<&User>> {
# Ok(executor.context().users.get(&id))

View file

@ -169,7 +169,7 @@ where
///
/// struct QueryRoot;
///
/// #[juniper::object(
/// #[juniper::graphql_object(
/// Context = ExampleContext
/// )]
/// impl QueryRoot {