Rename object
proc macro to graphql_object
This commit is contained in:
parent
a31d3f3888
commit
ce3cf45ca9
47 changed files with 126 additions and 116 deletions
|
@ -44,7 +44,7 @@ impl juniper::Context for Context {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
Context = Context,
|
Context = Context,
|
||||||
)]
|
)]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
|
|
@ -23,7 +23,7 @@ enum SignUpResult {
|
||||||
Error(Vec<ValidationError>),
|
Error(Vec<ValidationError>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl SignUpResult {
|
impl SignUpResult {
|
||||||
fn user(&self) -> Option<&User> {
|
fn user(&self) -> Option<&User> {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct ValidationError {
|
||||||
# #[allow(dead_code)]
|
# #[allow(dead_code)]
|
||||||
struct MutationResult<T>(Result<T, Vec<ValidationError>>);
|
struct MutationResult<T>(Result<T, Vec<ValidationError>>);
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
name = "UserResult",
|
name = "UserResult",
|
||||||
)]
|
)]
|
||||||
impl MutationResult<User> {
|
impl MutationResult<User> {
|
||||||
|
@ -38,7 +38,7 @@ impl MutationResult<User> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
name = "ForumPostResult",
|
name = "ForumPostResult",
|
||||||
)]
|
)]
|
||||||
impl MutationResult<ForumPost> {
|
impl MutationResult<ForumPost> {
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl juniper::Context for Context {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
// Here we specify the context type for the object.
|
// Here we specify the context type for the object.
|
||||||
// We need to do this in every type that
|
// We need to do this in every type that
|
||||||
// needs access to the context.
|
// needs access to the context.
|
||||||
|
@ -105,7 +105,7 @@ impl Query {
|
||||||
|
|
||||||
struct Mutation;
|
struct Mutation;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
Context = Context,
|
Context = Context,
|
||||||
)]
|
)]
|
||||||
impl Mutation {
|
impl Mutation {
|
||||||
|
@ -156,7 +156,7 @@ impl juniper::Context for Ctx {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
Context = Ctx,
|
Context = Ctx,
|
||||||
)]
|
)]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
|
|
@ -27,7 +27,7 @@ object in Juniper, most commonly using the `object` proc macro:
|
||||||
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn userWithUsername(username: String) -> FieldResult<Option<User>> {
|
fn userWithUsername(username: String) -> FieldResult<Option<User>> {
|
||||||
// Look up user in database...
|
// 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 }
|
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
||||||
struct Mutations;
|
struct Mutations;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Mutations {
|
impl Mutations {
|
||||||
fn signUpUser(name: String, email: String) -> FieldResult<User> {
|
fn signUpUser(name: String, email: String) -> FieldResult<User> {
|
||||||
// Validate inputs and save user in database...
|
// Validate inputs and save user in database...
|
||||||
|
|
|
@ -47,7 +47,7 @@ fn context_factory(_: &mut Request) -> IronResult<()> {
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn foo() -> String {
|
fn foo() -> String {
|
||||||
"Bar".to_owned()
|
"Bar".to_owned()
|
||||||
|
@ -99,7 +99,7 @@ fn context_factory(req: &mut Request) -> IronResult<Context> {
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
Context = Context,
|
Context = Context,
|
||||||
)]
|
)]
|
||||||
impl Root {
|
impl Root {
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct Coordinate {
|
||||||
struct Root;
|
struct Root;
|
||||||
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn users_at_location(coordinate: Coordinate, radius: f64) -> Vec<User> {
|
fn users_at_location(coordinate: Coordinate, radius: f64) -> Vec<User> {
|
||||||
// Send coordinate to database
|
// Send coordinate to database
|
||||||
|
@ -45,7 +45,7 @@ struct WorldCoordinate {
|
||||||
struct Root;
|
struct Root;
|
||||||
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn users_at_location(coordinate: WorldCoordinate, radius: f64) -> Vec<User> {
|
fn users_at_location(coordinate: WorldCoordinate, radius: f64) -> Vec<User> {
|
||||||
// Send coordinate to database
|
// Send coordinate to database
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct Person {
|
||||||
age: i32,
|
age: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Person {
|
impl Person {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
self.name.as_str()
|
self.name.as_str()
|
||||||
|
@ -43,7 +43,7 @@ struct House {
|
||||||
inhabitants: Vec<Person>,
|
inhabitants: Vec<Person>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl House {
|
impl House {
|
||||||
// Creates the field inhabitantWithName(name), returning a nullable person
|
// Creates the field inhabitantWithName(name), returning a nullable person
|
||||||
fn inhabitant_with_name(&self, name: String) -> Option<&Person> {
|
fn inhabitant_with_name(&self, name: String) -> Option<&Person> {
|
||||||
|
@ -70,7 +70,7 @@ struct Person {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Doc comments are used as descriptions for GraphQL.
|
/// 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.
|
// With this attribtue you can change the public GraphQL name of the type.
|
||||||
name = "PersonObject",
|
name = "PersonObject",
|
||||||
// You can also specify a description here, which will overwrite
|
// 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 {}
|
struct Person {}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Person {
|
impl Person {
|
||||||
#[graphql(
|
#[graphql(
|
||||||
arguments(
|
arguments(
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct Example {
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Example {
|
impl Example {
|
||||||
fn contents() -> FieldResult<String> {
|
fn contents() -> FieldResult<String> {
|
||||||
let mut file = File::open(&self.filename)?;
|
let mut file = File::open(&self.filename)?;
|
||||||
|
@ -143,7 +143,7 @@ struct Example {
|
||||||
whatever: Option<bool>,
|
whatever: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Example {
|
impl Example {
|
||||||
fn whatever() -> Result<bool, CustomError> {
|
fn whatever() -> Result<bool, CustomError> {
|
||||||
if let Some(value) = self.whatever {
|
if let Some(value) = self.whatever {
|
||||||
|
|
|
@ -57,7 +57,7 @@ struct User {
|
||||||
|
|
||||||
|
|
||||||
// Assign Database as the context type for User
|
// Assign Database as the context type for User
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
Context = Database,
|
Context = Database,
|
||||||
)]
|
)]
|
||||||
impl User {
|
impl User {
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct User {
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object(Context = Context)]
|
#[juniper::graphql_object(Context = Context)]
|
||||||
impl User {
|
impl User {
|
||||||
fn id(&self) -> i32 {
|
fn id(&self) -> i32 {
|
||||||
self.id
|
self.id
|
||||||
|
@ -45,7 +45,7 @@ impl User {
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object(Context = Context)]
|
#[juniper::graphql_object(Context = Context)]
|
||||||
impl Query {
|
impl Query {
|
||||||
async fn users() -> Vec<User> {
|
async fn users() -> Vec<User> {
|
||||||
vec![
|
vec![
|
||||||
|
|
|
@ -13,7 +13,7 @@ struct User {
|
||||||
kind: UserKind,
|
kind: UserKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl User {
|
impl User {
|
||||||
async fn name(&self) -> &str {
|
async fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
|
@ -43,7 +43,7 @@ impl User {
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Query {
|
impl Query {
|
||||||
fn field_sync(&self) -> &'static str {
|
fn field_sync(&self) -> &'static str {
|
||||||
"field_sync"
|
"field_sync"
|
||||||
|
@ -70,7 +70,7 @@ impl Query {
|
||||||
|
|
||||||
struct Mutation;
|
struct Mutation;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Mutation {}
|
impl Mutation {}
|
||||||
|
|
||||||
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
|
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
|
||||||
|
|
|
@ -79,7 +79,7 @@ struct WithCustomContext {
|
||||||
a: bool,
|
a: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Query {
|
impl Query {
|
||||||
fn obj() -> Obj {
|
fn obj() -> Obj {
|
||||||
Obj {
|
Obj {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use juniper::{
|
||||||
|
|
||||||
pub struct Query;
|
pub struct Query;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Query {
|
impl Query {
|
||||||
fn r#type(r#fn: MyInputType) -> Vec<String> {
|
fn r#type(r#fn: MyInputType) -> Vec<String> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
|
|
@ -22,7 +22,7 @@ struct User {
|
||||||
|
|
||||||
struct User2;
|
struct User2;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl User2 {
|
impl User2 {
|
||||||
fn id(&self) -> UserId {
|
fn id(&self) -> UserId {
|
||||||
UserId("id".to_string())
|
UserId("id".to_string())
|
||||||
|
|
|
@ -160,7 +160,7 @@ juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue {
|
||||||
|
|
||||||
struct TestType;
|
struct TestType;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
Scalar = MyScalarValue
|
Scalar = MyScalarValue
|
||||||
)]
|
)]
|
||||||
impl TestType {
|
impl TestType {
|
||||||
|
|
|
@ -7,37 +7,44 @@ impl juniper::Context for Context {}
|
||||||
|
|
||||||
pub struct Query;
|
pub struct Query;
|
||||||
|
|
||||||
graphql_object!(Query: Context |&self| {
|
#[graphql_object(
|
||||||
field users(&executor) -> Vec<User> {
|
Context = Context
|
||||||
|
)]
|
||||||
|
impl Query {
|
||||||
|
fn users(exec: &Executor) -> Vec<User> {
|
||||||
let lh = executor.look_ahead();
|
let lh = executor.look_ahead();
|
||||||
assert_eq!(lh.field_name(), "users");
|
assert_eq!(lh.field_name(), "users");
|
||||||
vec![User]
|
vec![User]
|
||||||
}
|
}
|
||||||
|
|
||||||
field countries(&executor) -> Vec<Country> {
|
fn countries(exec: &Executor) -> Vec<Country> {
|
||||||
let lh = executor.look_ahead();
|
let lh = executor.look_ahead();
|
||||||
assert_eq!(lh.field_name(), "countries");
|
assert_eq!(lh.field_name(), "countries");
|
||||||
vec![Country]
|
vec![Country]
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct User;
|
pub struct User;
|
||||||
|
|
||||||
graphql_object!(User: Context |&self| {
|
#[graphql_object(
|
||||||
field id() -> i32 {
|
Context = Context
|
||||||
|
)]
|
||||||
|
impl User {
|
||||||
|
fn id() -> i32 {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Country;
|
pub struct Country;
|
||||||
|
|
||||||
graphql_object!(Country: Context |&self| {
|
#[graphql_object]
|
||||||
field id() -> i32 {
|
impl Country {
|
||||||
|
fn id() -> i32 {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
type Schema = juniper::RootNode<'static, Query, EmptyMutation<Context>>;
|
type Schema = juniper::RootNode<'static, Query, EmptyMutation<Context>>;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use juniper::*;
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Query {
|
impl Query {
|
||||||
fn users(executor: &Executor) -> Vec<User> {
|
fn users(executor: &Executor) -> Vec<User> {
|
||||||
// This doesn't cause a panic
|
// This doesn't cause a panic
|
||||||
|
@ -19,7 +19,7 @@ struct User {
|
||||||
country: Country,
|
country: Country,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl User {
|
impl User {
|
||||||
fn country(&self, executor: &Executor) -> &Country {
|
fn country(&self, executor: &Executor) -> &Country {
|
||||||
// This panics!
|
// This panics!
|
||||||
|
@ -33,7 +33,7 @@ struct Country {
|
||||||
id: i32,
|
id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Country {
|
impl Country {
|
||||||
fn id(&self) -> i32 {
|
fn id(&self) -> i32 {
|
||||||
self.id
|
self.id
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
## Breaking Changes
|
## Breaking Changes
|
||||||
|
|
||||||
|
- remove old `graphql_object!` macro, rename `object` proc macro to `graphql_object`
|
||||||
|
|
||||||
- Remove deprecated `ScalarValue` custom derive (renamed to GraphQLScalarValue)
|
- Remove deprecated `ScalarValue` custom derive (renamed to GraphQLScalarValue)
|
||||||
|
|
||||||
- `graphql_union!` macro removed, replaced by `#[graphql_union]` proc macro
|
- `graphql_union!` macro removed, replaced by `#[graphql_union]` proc macro
|
||||||
|
|
|
@ -13,7 +13,7 @@ struct User {
|
||||||
kind: UserKind,
|
kind: UserKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl User {
|
impl User {
|
||||||
async fn name(&self) -> &str {
|
async fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
|
@ -43,7 +43,7 @@ impl User {
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Query {
|
impl Query {
|
||||||
fn field_sync(&self) -> &'static str {
|
fn field_sync(&self) -> &'static str {
|
||||||
"field_sync"
|
"field_sync"
|
||||||
|
@ -70,7 +70,7 @@ impl Query {
|
||||||
|
|
||||||
struct Mutation;
|
struct Mutation;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Mutation {}
|
impl Mutation {}
|
||||||
|
|
||||||
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
|
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
|
|
||||||
struct TestType;
|
struct TestType;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl TestType {
|
impl TestType {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"a"
|
"a"
|
||||||
|
|
|
@ -19,7 +19,7 @@ enum Color {
|
||||||
}
|
}
|
||||||
struct TestType;
|
struct TestType;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl TestType {
|
impl TestType {
|
||||||
fn to_string(color: Color) -> String {
|
fn to_string(color: Color) -> String {
|
||||||
format!("Color::{:?}", color)
|
format!("Color::{:?}", color)
|
||||||
|
|
|
@ -6,7 +6,7 @@ mod field_execution {
|
||||||
struct DataType;
|
struct DataType;
|
||||||
struct DeepDataType;
|
struct DeepDataType;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl DataType {
|
impl DataType {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -36,7 +36,7 @@ mod field_execution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl DeepDataType {
|
impl DeepDataType {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Already Been Done"
|
"Already Been Done"
|
||||||
|
@ -159,7 +159,7 @@ mod merge_parallel_fragments {
|
||||||
|
|
||||||
struct Type;
|
struct Type;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Type {
|
impl Type {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -241,7 +241,7 @@ mod merge_parallel_inline_fragments {
|
||||||
struct Type;
|
struct Type;
|
||||||
struct Other;
|
struct Other;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Type {
|
impl Type {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -260,7 +260,7 @@ mod merge_parallel_inline_fragments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Other {
|
impl Other {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -390,7 +390,7 @@ mod threads_context_correctly {
|
||||||
|
|
||||||
impl Context for TestContext {}
|
impl Context for TestContext {}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
Context = TestContext,
|
Context = TestContext,
|
||||||
)]
|
)]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
|
@ -458,7 +458,7 @@ mod dynamic_context_switching {
|
||||||
|
|
||||||
struct ItemRef;
|
struct ItemRef;
|
||||||
|
|
||||||
#[crate::object_internal(Context = OuterContext)]
|
#[crate::graphql_object_internal(Context = OuterContext)]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn item_opt(context: &OuterContext, key: i32) -> Option<(&InnerContext, ItemRef)> {
|
fn item_opt(context: &OuterContext, key: i32) -> Option<(&InnerContext, ItemRef)> {
|
||||||
executor.context().items.get(&key).map(|c| (c, 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 {
|
impl ItemRef {
|
||||||
fn value(context: &InnerContext) -> String {
|
fn value(context: &InnerContext) -> String {
|
||||||
context.value.clone()
|
context.value.clone()
|
||||||
|
@ -799,7 +799,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn inner() -> Inner {
|
fn inner() -> Inner {
|
||||||
Inner
|
Inner
|
||||||
|
@ -812,7 +812,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Inner {
|
impl Inner {
|
||||||
fn nullable_field() -> Option<Inner> {
|
fn nullable_field() -> Option<Inner> {
|
||||||
Some(Inner)
|
Some(Inner)
|
||||||
|
@ -1065,7 +1065,7 @@ mod named_operations {
|
||||||
|
|
||||||
struct Schema;
|
struct Schema;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"b"
|
"b"
|
||||||
|
|
|
@ -35,7 +35,7 @@ mod interface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
interfaces = [&dyn Pet]
|
interfaces = [&dyn Pet]
|
||||||
)]
|
)]
|
||||||
impl Dog {
|
impl Dog {
|
||||||
|
@ -61,7 +61,7 @@ mod interface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
interfaces = [&dyn Pet]
|
interfaces = [&dyn Pet]
|
||||||
)]
|
)]
|
||||||
impl Cat {
|
impl Cat {
|
||||||
|
@ -77,7 +77,7 @@ mod interface {
|
||||||
pets: Vec<Box<dyn Pet>>,
|
pets: Vec<Box<dyn Pet>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn pets(&self) -> Vec<&dyn Pet> {
|
fn pets(&self) -> Vec<&dyn Pet> {
|
||||||
self.pets.iter().map(|p| p.as_ref()).collect()
|
self.pets.iter().map(|p| p.as_ref()).collect()
|
||||||
|
@ -187,7 +187,7 @@ mod union {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Dog {
|
impl Dog {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
|
@ -208,7 +208,7 @@ mod union {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Cat {
|
impl Cat {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
|
@ -222,7 +222,7 @@ mod union {
|
||||||
pets: Vec<Box<dyn Pet>>,
|
pets: Vec<Box<dyn Pet>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn pets(&self) -> Vec<&dyn Pet> {
|
fn pets(&self) -> Vec<&dyn Pet> {
|
||||||
self.pets.iter().map(|p| p.as_ref()).collect()
|
self.pets.iter().map(|p| p.as_ref()).collect()
|
||||||
|
|
|
@ -66,7 +66,7 @@ enum EnumDeprecation {
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn default_name() -> DefaultName {
|
fn default_name() -> DefaultName {
|
||||||
DefaultName::Foo
|
DefaultName::Foo
|
||||||
|
|
|
@ -81,7 +81,7 @@ struct FieldWithDefaults {
|
||||||
field_two: i32,
|
field_two: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn test_field(
|
fn test_field(
|
||||||
a1: DefaultName,
|
a1: DefaultName,
|
||||||
|
|
|
@ -54,7 +54,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| {
|
||||||
});
|
});
|
||||||
|
|
||||||
/// The root query object in the schema
|
/// The root query object in the schema
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
interfaces = [&Interface]
|
interfaces = [&Interface]
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -64,7 +64,7 @@ struct InputWithDefaults {
|
||||||
a: i32,
|
a: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl TestType {
|
impl TestType {
|
||||||
fn field_with_object_input(input: Option<TestInputObject>) -> String {
|
fn field_with_object_input(input: Option<TestInputObject>) -> String {
|
||||||
format!("{:?}", input)
|
format!("{:?}", input)
|
||||||
|
|
|
@ -210,7 +210,7 @@ mod integration_test {
|
||||||
fn test_serialization() {
|
fn test_serialization() {
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn exampleNaiveDate() -> NaiveDate {
|
fn exampleNaiveDate() -> NaiveDate {
|
||||||
NaiveDate::from_ymd(2015, 3, 14)
|
NaiveDate::from_ymd(2015, 3, 14)
|
||||||
|
|
|
@ -110,14 +110,15 @@ extern crate uuid;
|
||||||
// This allows users to just depend on juniper and get the derive
|
// This allows users to just depend on juniper and get the derive
|
||||||
// functionality automatically.
|
// functionality automatically.
|
||||||
pub use juniper_codegen::{
|
pub use juniper_codegen::{
|
||||||
graphql_union, object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue,
|
graphql_object, graphql_union, GraphQLEnum, GraphQLInputObject, GraphQLObject,
|
||||||
|
GraphQLScalarValue,
|
||||||
};
|
};
|
||||||
// Internal macros are not exported,
|
// Internal macros are not exported,
|
||||||
// but declared at the root to make them easier to use.
|
// but declared at the root to make them easier to use.
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use juniper_codegen::{
|
use juniper_codegen::{
|
||||||
graphql_union_internal, object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal,
|
graphql_object_internal, graphql_union_internal, GraphQLEnumInternal,
|
||||||
GraphQLScalarValueInternal,
|
GraphQLInputObjectInternal, GraphQLScalarValueInternal,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -61,12 +61,12 @@ impl Character for Droid {
|
||||||
fn id(&self) -> &str { &self.id }
|
fn id(&self) -> &str { &self.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object(Context = Database)]
|
#[juniper::graphql_object(Context = Database)]
|
||||||
impl Human {
|
impl Human {
|
||||||
fn id(&self) -> &str { &self.id }
|
fn id(&self) -> &str { &self.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
name = "Droid",
|
name = "Droid",
|
||||||
Context = Database,
|
Context = Database,
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct Point {
|
||||||
x: i32,
|
x: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn simple() -> i32 {
|
fn simple() -> i32 {
|
||||||
0
|
0
|
||||||
|
|
|
@ -22,7 +22,7 @@ Syntax to validate:
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
interfaces = [&Interface],
|
interfaces = [&Interface],
|
||||||
)]
|
)]
|
||||||
impl Root {
|
impl Root {
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct WithLifetime<'a> {
|
||||||
value: &'a str,
|
value: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(Context=Context)]
|
#[crate::graphql_object_internal(Context=Context)]
|
||||||
impl<'a> WithLifetime<'a> {
|
impl<'a> WithLifetime<'a> {
|
||||||
fn value(&'a self) -> &'a str {
|
fn value(&'a self) -> &'a str {
|
||||||
self.value
|
self.value
|
||||||
|
@ -21,7 +21,7 @@ impl<'a> WithLifetime<'a> {
|
||||||
|
|
||||||
struct WithContext;
|
struct WithContext;
|
||||||
|
|
||||||
#[crate::object_internal(Context=Context)]
|
#[crate::graphql_object_internal(Context=Context)]
|
||||||
impl WithContext {
|
impl WithContext {
|
||||||
fn ctx(ctx: &Context) -> bool {
|
fn ctx(ctx: &Context) -> bool {
|
||||||
ctx.flag1
|
ctx.flag1
|
||||||
|
@ -33,7 +33,7 @@ struct Query {
|
||||||
b: bool,
|
b: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
scalar = crate::DefaultScalarValue,
|
scalar = crate::DefaultScalarValue,
|
||||||
name = "Query",
|
name = "Query",
|
||||||
context = Context,
|
context = Context,
|
||||||
|
@ -115,7 +115,7 @@ impl<'a> Query {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Mutation;
|
struct Mutation;
|
||||||
|
|
||||||
#[crate::object_internal(context = Context)]
|
#[crate::graphql_object_internal(context = Context)]
|
||||||
impl Mutation {
|
impl Mutation {
|
||||||
fn empty() -> bool {
|
fn empty() -> bool {
|
||||||
true
|
true
|
||||||
|
|
|
@ -44,7 +44,7 @@ struct ResolversWithTrailingComma;
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Concrete {
|
impl Concrete {
|
||||||
fn simple() -> i32 {
|
fn simple() -> i32 {
|
||||||
0
|
0
|
||||||
|
@ -113,7 +113,7 @@ graphql_interface!(ResolversWithTrailingComma: () |&self| {
|
||||||
field simple() -> i32 { 0 }
|
field simple() -> i32 { 0 }
|
||||||
});
|
});
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
// FIXME: make async work
|
// FIXME: make async work
|
||||||
noasync
|
noasync
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -80,7 +80,7 @@ graphql_scalar!(ScalarDescription {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn default_name() -> DefaultName {
|
fn default_name() -> DefaultName {
|
||||||
DefaultName(0)
|
DefaultName(0)
|
||||||
|
|
|
@ -38,7 +38,7 @@ enum DescriptionFirst {
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl Concrete {
|
impl Concrete {
|
||||||
fn simple() -> i32 {
|
fn simple() -> i32 {
|
||||||
123
|
123
|
||||||
|
@ -90,7 +90,7 @@ impl DescriptionFirst {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: make async work
|
// FIXME: make async work
|
||||||
#[crate::object_internal(noasync)]
|
#[crate::graphql_object_internal(noasync)]
|
||||||
impl<'a> Root {
|
impl<'a> Root {
|
||||||
fn custom_name() -> CustomName {
|
fn custom_name() -> CustomName {
|
||||||
CustomName::Concrete(Concrete)
|
CustomName::Concrete(Concrete)
|
||||||
|
|
|
@ -149,7 +149,7 @@ fn errors() {
|
||||||
fn issue_427_panic_is_not_expected() {
|
fn issue_427_panic_is_not_expected() {
|
||||||
struct QueryWithoutFloat;
|
struct QueryWithoutFloat;
|
||||||
|
|
||||||
#[crate::object_internal]
|
#[crate::graphql_object_internal]
|
||||||
impl QueryWithoutFloat {
|
impl QueryWithoutFloat {
|
||||||
fn echo(value: String) -> String {
|
fn echo(value: String) -> String {
|
||||||
value
|
value
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct Foo {
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[crate::object_internal(Scalar = S)]
|
#[crate::graphql_object_internal(Scalar = S)]
|
||||||
impl<'a, S> Query
|
impl<'a, S> Query
|
||||||
where
|
where
|
||||||
S: crate::ScalarValue + 'a,
|
S: crate::ScalarValue + 'a,
|
||||||
|
|
|
@ -106,7 +106,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
name = "__Schema"
|
name = "__Schema"
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -145,7 +145,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
name = "__Type"
|
name = "__Type"
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -278,7 +278,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
name = "__Field",
|
name = "__Field",
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -317,7 +317,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
name = "__InputValue",
|
name = "__InputValue",
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -346,7 +346,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
name = "__EnumValue",
|
name = "__EnumValue",
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
// FIXME: make this redundant.
|
// FIXME: make this redundant.
|
||||||
|
@ -373,7 +373,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
name = "__Directive",
|
name = "__Directive",
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
|
|
@ -33,7 +33,7 @@ graphql_interface!(<'a> &'a dyn Character: Database as "Character" |&self| {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
Context = Database,
|
Context = Database,
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
interfaces = [&dyn Character],
|
interfaces = [&dyn Character],
|
||||||
|
@ -68,7 +68,7 @@ impl<'a> &'a dyn Human {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
Context = Database,
|
Context = Database,
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
interfaces = [&dyn Character],
|
interfaces = [&dyn Character],
|
||||||
|
@ -105,7 +105,7 @@ impl<'a> &'a dyn Droid {
|
||||||
|
|
||||||
pub struct Query;
|
pub struct Query;
|
||||||
|
|
||||||
#[crate::object_internal(
|
#[crate::graphql_object_internal(
|
||||||
Context = Database,
|
Context = Database,
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
// FIXME: make async work
|
// FIXME: make async work
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use juniper::{
|
use juniper::{
|
||||||
object, DefaultScalarValue, ExecutionError, FieldError, GraphQLEnum, Value, Variables,
|
graphql_object, DefaultScalarValue, ExecutionError, FieldError, GraphQLEnum, Value, Variables,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type QueryResult = Result<
|
pub type QueryResult = Result<
|
||||||
|
@ -56,12 +56,12 @@ impl User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[object(Context = Context)]
|
#[graphql_object(Context = Context)]
|
||||||
impl User {}
|
impl User {}
|
||||||
|
|
||||||
pub struct Query;
|
pub struct Query;
|
||||||
|
|
||||||
#[object(Context = Context)]
|
#[graphql_object(Context = Context)]
|
||||||
impl Query {
|
impl Query {
|
||||||
fn user_sync_instant(id: i32) -> Result<User, FieldError> {
|
fn user_sync_instant(id: i32) -> Result<User, FieldError> {
|
||||||
Ok(User::new(id))
|
Ok(User::new(id))
|
||||||
|
@ -92,7 +92,7 @@ impl Query {
|
||||||
|
|
||||||
pub struct Mutation;
|
pub struct Mutation;
|
||||||
|
|
||||||
#[object(Context = Context)]
|
#[graphql_object(Context = Context)]
|
||||||
impl Mutation {}
|
impl Mutation {}
|
||||||
|
|
||||||
pub fn new_schema() -> juniper::RootNode<'static, Query, Mutation> {
|
pub fn new_schema() -> juniper::RootNode<'static, Query, Mutation> {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::util;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
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 {
|
pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) -> TokenStream {
|
||||||
let impl_attrs = match syn::parse::<util::ObjectAttributes>(args) {
|
let impl_attrs = match syn::parse::<util::ObjectAttributes>(args) {
|
||||||
Ok(attrs) => attrs,
|
Ok(attrs) => attrs,
|
||||||
|
@ -20,7 +20,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
|
||||||
let mut _impl = match item {
|
let mut _impl = match item {
|
||||||
syn::Item::Impl(_impl) => _impl,
|
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) {
|
if let Some(ident) = util::name_of_type(&*_impl.self_ty) {
|
||||||
ident.to_string()
|
ident.to_string()
|
||||||
} else {
|
} 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\")");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ More advanced use cases are introduced step by step.
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
// We prefix the impl Block with the procedural macro.
|
// We prefix the impl Block with the procedural macro.
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
|
||||||
// A **warning**: only GraphQL fields can be specified in this impl block.
|
// 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 {
|
impl Person {
|
||||||
fn first_name(&self) -> &str {
|
fn first_name(&self) -> &str {
|
||||||
&self.first_name
|
&self.first_name
|
||||||
|
@ -226,7 +226,7 @@ impl juniper::Context for Context {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
// Here we specify the context type for this object.
|
// Here we specify the context type for this object.
|
||||||
Context = Context,
|
Context = Context,
|
||||||
)]
|
)]
|
||||||
|
@ -256,7 +256,7 @@ struct InternalQuery;
|
||||||
// Doc comments can be used to specify graphql documentation.
|
// Doc comments can be used to specify graphql documentation.
|
||||||
/// GRAPHQL DOCUMENTATION.
|
/// GRAPHQL DOCUMENTATION.
|
||||||
/// More info for GraphQL users....
|
/// More info for GraphQL users....
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
// You can rename the type for GraphQL by specifying the name here.
|
// You can rename the type for GraphQL by specifying the name here.
|
||||||
name = "Query",
|
name = "Query",
|
||||||
// You can also specify a description here.
|
// You can also specify a description here.
|
||||||
|
@ -319,7 +319,7 @@ struct WithLifetime<'a> {
|
||||||
value: &'a str,
|
value: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl<'a> WithLifetime<'a> {
|
impl<'a> WithLifetime<'a> {
|
||||||
fn value(&self) -> &str {
|
fn value(&self) -> &str {
|
||||||
self.value
|
self.value
|
||||||
|
@ -340,7 +340,7 @@ You can easily specify a custom scalar though.
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::object(
|
#[juniper::graphql_object(
|
||||||
Scalar = MyCustomScalar,
|
Scalar = MyCustomScalar,
|
||||||
)]
|
)]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
@ -358,7 +358,7 @@ struct User {
|
||||||
r#type: String,
|
r#type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::object]
|
#[juniper::graphql_object]
|
||||||
impl User {
|
impl User {
|
||||||
fn r#type(&self) -> &str {
|
fn r#type(&self) -> &str {
|
||||||
&self.r#type
|
&self.r#type
|
||||||
|
@ -368,7 +368,7 @@ impl User {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#[proc_macro_attribute]
|
#[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);
|
let gen = impl_object::build_object(args, input, false);
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
@ -376,7 +376,7 @@ pub fn object(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
/// A proc macro for defining a GraphQL object.
|
/// A proc macro for defining a GraphQL object.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[proc_macro_attribute]
|
#[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);
|
let gen = impl_object::build_object(args, input, true);
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ use juniper::{Context, EmptyMutation};
|
||||||
# struct QueryRoot;
|
# struct QueryRoot;
|
||||||
# struct Database { users: HashMap<String, User> }
|
# struct Database { users: HashMap<String, User> }
|
||||||
#
|
#
|
||||||
# #[juniper::object( Context = Database )]
|
# #[juniper::graphql_object( Context = Database )]
|
||||||
# impl User {
|
# impl User {
|
||||||
# fn id(&self) -> FieldResult<&String> {
|
# fn id(&self) -> FieldResult<&String> {
|
||||||
# Ok(&self.id)
|
# Ok(&self.id)
|
||||||
|
@ -54,7 +54,7 @@ use juniper::{Context, EmptyMutation};
|
||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# #[juniper::object( Context = Database )]
|
# #[juniper::graphql_object( Context = Database )]
|
||||||
# impl QueryRoot {
|
# impl QueryRoot {
|
||||||
# fn user(context: &Database, id: String) -> FieldResult<Option<&User>> {
|
# fn user(context: &Database, id: String) -> FieldResult<Option<&User>> {
|
||||||
# Ok(executor.context().users.get(&id))
|
# Ok(executor.context().users.get(&id))
|
||||||
|
|
|
@ -169,7 +169,7 @@ where
|
||||||
///
|
///
|
||||||
/// struct QueryRoot;
|
/// struct QueryRoot;
|
||||||
///
|
///
|
||||||
/// #[juniper::object(
|
/// #[juniper::graphql_object(
|
||||||
/// Context = ExampleContext
|
/// Context = ExampleContext
|
||||||
/// )]
|
/// )]
|
||||||
/// impl QueryRoot {
|
/// impl QueryRoot {
|
||||||
|
|
Loading…
Reference in a new issue