Rename impl_object to object.
This commit is contained in:
parent
520cac29a0
commit
29025e6cae
39 changed files with 103 additions and 104 deletions
|
@ -44,7 +44,7 @@ impl juniper::Context for Context {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::object(
|
||||||
Context = Context,
|
Context = Context,
|
||||||
)]
|
)]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
|
|
@ -23,7 +23,7 @@ enum SignUpResult {
|
||||||
Error(Vec<ValidationError>),
|
Error(Vec<ValidationError>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object]
|
#[juniper::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::impl_object(
|
#[juniper::object(
|
||||||
name = "UserResult",
|
name = "UserResult",
|
||||||
)]
|
)]
|
||||||
impl MutationResult<User> {
|
impl MutationResult<User> {
|
||||||
|
@ -38,7 +38,7 @@ impl MutationResult<User> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::object(
|
||||||
name = "ForumPostResult",
|
name = "ForumPostResult",
|
||||||
)]
|
)]
|
||||||
impl MutationResult<ForumPost> {
|
impl MutationResult<ForumPost> {
|
||||||
|
|
|
@ -20,7 +20,7 @@ naturally map to GraphQL features, such as `Option<T>`, `Vec<T>`, `Box<T>`,
|
||||||
|
|
||||||
For more advanced mappings, Juniper provides multiple macros to map your Rust
|
For more advanced mappings, Juniper provides multiple macros to map your Rust
|
||||||
types to a GraphQL schema. The most important one is the
|
types to a GraphQL schema. The most important one is the
|
||||||
[impl_object][jp_impl_object] procedural macro that is used for declaring an object with
|
[object][jp_object] procedural macro that is used for declaring an object with
|
||||||
resolvers, which you will use for the `Query` and `Mutation` roots.
|
resolvers, which you will use for the `Query` and `Mutation` roots.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
@ -60,7 +60,7 @@ struct NewHuman {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, we create our root Query and Mutation types with resolvers by using the
|
// Now, we create our root Query and Mutation types with resolvers by using the
|
||||||
// impl_object macro.
|
// object macro.
|
||||||
// Objects can have contexts that allow accessing shared state like a database
|
// Objects can have contexts that allow accessing shared state like a database
|
||||||
// pool.
|
// pool.
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ impl juniper::Context for Context {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::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::impl_object(
|
#[juniper::object(
|
||||||
Context = Context,
|
Context = Context,
|
||||||
)]
|
)]
|
||||||
impl Mutation {
|
impl Mutation {
|
||||||
|
@ -156,7 +156,7 @@ impl juniper::Context for Ctx {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::object(
|
||||||
Context = Ctx,
|
Context = Ctx,
|
||||||
)]
|
)]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
@ -198,4 +198,4 @@ fn main() {
|
||||||
[rocket]: servers/rocket.md
|
[rocket]: servers/rocket.md
|
||||||
[iron]: servers/iron.md
|
[iron]: servers/iron.md
|
||||||
[tutorial]: ./tutorial.html
|
[tutorial]: ./tutorial.html
|
||||||
[jp_obj_macro]: https://docs.rs/juniper/latest/juniper/macro.impl_object.html
|
[jp_obj_macro]: https://docs.rs/juniper/latest/juniper/macro.object.html
|
||||||
|
|
|
@ -20,14 +20,14 @@ object somewhere but never references it, it will not be exposed in a schema.
|
||||||
## The query root
|
## The query root
|
||||||
|
|
||||||
The query root is just a GraphQL object. You define it like any other GraphQL
|
The query root is just a GraphQL object. You define it like any other GraphQL
|
||||||
object in Juniper, most commonly using the `impl_object` proc macro:
|
object in Juniper, most commonly using the `object` proc macro:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# use juniper::FieldResult;
|
# use juniper::FieldResult;
|
||||||
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[juniper::impl_object]
|
#[juniper::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::impl_object]
|
#[juniper::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::impl_object]
|
#[juniper::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::impl_object(
|
#[juniper::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::impl_object]
|
#[juniper::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::impl_object]
|
#[juniper::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
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
If you've got a struct that can't be mapped directly to GraphQL, that contains
|
If you've got a struct that can't be mapped directly to GraphQL, that contains
|
||||||
computed fields or circular structures, you have to use a more powerful tool:
|
computed fields or circular structures, you have to use a more powerful tool:
|
||||||
the `impl_object` procedural macro. This macro lets you define GraphQL object
|
the `object` procedural macro. This macro lets you define GraphQL object
|
||||||
fields in a Rust `impl` block for a type. Continuing with the
|
fields in a Rust `impl` block for a type. Continuing with the
|
||||||
example from the last chapter, this is how you would define `Person` using the
|
example from the last chapter, this is how you would define `Person` using the
|
||||||
macro:
|
macro:
|
||||||
|
@ -14,7 +14,7 @@ struct Person {
|
||||||
age: i32,
|
age: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object]
|
#[juniper::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::impl_object]
|
#[juniper::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 {
|
||||||
website_url: String,
|
website_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::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",
|
||||||
)]
|
)]
|
||||||
|
@ -96,4 +96,4 @@ GraphQL fields expose more features than Rust's standard method syntax gives us:
|
||||||
* Per-argument descriptions
|
* Per-argument descriptions
|
||||||
|
|
||||||
These, and more features, are described more thorougly in [the reference
|
These, and more features, are described more thorougly in [the reference
|
||||||
documentation](https://docs.rs/juniper/latest/juniper/macro.impl_object.html).
|
documentation](https://docs.rs/juniper/latest/juniper/macro.object.html).
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct Example {
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object]
|
#[juniper::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::impl_object]
|
#[juniper::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::impl_object(
|
#[juniper::object(
|
||||||
Context = Database,
|
Context = Database,
|
||||||
)]
|
)]
|
||||||
impl User {
|
impl User {
|
||||||
|
|
|
@ -80,7 +80,7 @@ struct WithCustomContext {
|
||||||
a: bool,
|
a: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object]
|
#[juniper::object]
|
||||||
impl Query {
|
impl Query {
|
||||||
fn obj() -> Obj {
|
fn obj() -> Obj {
|
||||||
Obj {
|
Obj {
|
||||||
|
|
|
@ -151,7 +151,7 @@ juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue {
|
||||||
|
|
||||||
struct TestType;
|
struct TestType;
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::object(
|
||||||
Scalar = MyScalarValue
|
Scalar = MyScalarValue
|
||||||
)]
|
)]
|
||||||
impl TestType {
|
impl TestType {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# master
|
# master
|
||||||
|
|
||||||
### impl_object macro
|
### object macro
|
||||||
|
|
||||||
The `graphql_object!` macro is deprecated and will be removed in the future.
|
The `graphql_object!` macro is deprecated and will be removed in the future.
|
||||||
It is replaced by the new [impl_object](https://docs.rs/juniper/latest/juniper/macro.impl_object.html) procedural macro.
|
It is replaced by the new [object](https://docs.rs/juniper/latest/juniper/macro.object.html) procedural macro.
|
||||||
|
|
||||||
[#333](https://github.com/graphql-rust/juniper/pull/333)
|
[#333](https://github.com/graphql-rust/juniper/pull/333)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::value::{DefaultScalarValue, Object, Value};
|
||||||
|
|
||||||
struct TestType;
|
struct TestType;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl TestType {
|
impl TestType {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"a"
|
"a"
|
||||||
|
|
|
@ -17,7 +17,7 @@ enum Color {
|
||||||
}
|
}
|
||||||
struct TestType;
|
struct TestType;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl TestType {
|
impl TestType {
|
||||||
fn to_string(color: Color) -> String {
|
fn to_string(color: Color) -> String {
|
||||||
format!("Color::{:?}", color)
|
format!("Color::{:?}", color)
|
||||||
|
|
|
@ -7,7 +7,7 @@ mod field_execution {
|
||||||
struct DataType;
|
struct DataType;
|
||||||
struct DeepDataType;
|
struct DeepDataType;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl DataType {
|
impl DataType {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -37,7 +37,7 @@ mod field_execution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl DeepDataType {
|
impl DeepDataType {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Already Been Done"
|
"Already Been Done"
|
||||||
|
@ -162,7 +162,7 @@ mod merge_parallel_fragments {
|
||||||
|
|
||||||
struct Type;
|
struct Type;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Type {
|
impl Type {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -246,7 +246,7 @@ mod merge_parallel_inline_fragments {
|
||||||
struct Type;
|
struct Type;
|
||||||
struct Other;
|
struct Other;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Type {
|
impl Type {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -265,7 +265,7 @@ mod merge_parallel_inline_fragments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Other {
|
impl Other {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -396,7 +396,7 @@ mod threads_context_correctly {
|
||||||
|
|
||||||
impl Context for TestContext {}
|
impl Context for TestContext {}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
Context = TestContext,
|
Context = TestContext,
|
||||||
)]
|
)]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
|
@ -462,7 +462,7 @@ mod dynamic_context_switching {
|
||||||
|
|
||||||
struct ItemRef;
|
struct ItemRef;
|
||||||
|
|
||||||
#[crate::impl_object_internal(Context = OuterContext)]
|
#[crate::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))
|
||||||
|
@ -492,7 +492,7 @@ mod dynamic_context_switching {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(Context = InnerContext)]
|
#[crate::object_internal(Context = InnerContext)]
|
||||||
impl ItemRef {
|
impl ItemRef {
|
||||||
fn value(context: &InnerContext) -> String {
|
fn value(context: &InnerContext) -> String {
|
||||||
context.value.clone()
|
context.value.clone()
|
||||||
|
@ -801,7 +801,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn inner() -> Inner {
|
fn inner() -> Inner {
|
||||||
Inner
|
Inner
|
||||||
|
@ -814,7 +814,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Inner {
|
impl Inner {
|
||||||
fn nullable_field() -> Option<Inner> {
|
fn nullable_field() -> Option<Inner> {
|
||||||
Some(Inner)
|
Some(Inner)
|
||||||
|
@ -1068,7 +1068,7 @@ mod named_operations {
|
||||||
|
|
||||||
struct Schema;
|
struct Schema;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn a() -> &str {
|
fn a() -> &str {
|
||||||
"b"
|
"b"
|
||||||
|
|
|
@ -37,7 +37,7 @@ mod interface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
interfaces = [&Pet]
|
interfaces = [&Pet]
|
||||||
)]
|
)]
|
||||||
impl Dog {
|
impl Dog {
|
||||||
|
@ -63,7 +63,7 @@ mod interface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
interfaces = [&Pet]
|
interfaces = [&Pet]
|
||||||
)]
|
)]
|
||||||
impl Cat {
|
impl Cat {
|
||||||
|
@ -79,7 +79,7 @@ mod interface {
|
||||||
pets: Vec<Box<Pet>>,
|
pets: Vec<Box<Pet>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn pets(&self) -> Vec<&Pet> {
|
fn pets(&self) -> Vec<&Pet> {
|
||||||
self.pets.iter().map(|p| p.as_ref()).collect()
|
self.pets.iter().map(|p| p.as_ref()).collect()
|
||||||
|
@ -188,7 +188,7 @@ mod union {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Dog {
|
impl Dog {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
|
@ -209,7 +209,7 @@ mod union {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Cat {
|
impl Cat {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
|
@ -223,7 +223,7 @@ mod union {
|
||||||
pets: Vec<Box<Pet>>,
|
pets: Vec<Box<Pet>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn pets(&self) -> Vec<&Pet> {
|
fn pets(&self) -> Vec<&Pet> {
|
||||||
self.pets.iter().map(|p| p.as_ref()).collect()
|
self.pets.iter().map(|p| p.as_ref()).collect()
|
||||||
|
|
|
@ -64,7 +64,7 @@ enum EnumDeprecation {
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn default_name() -> DefaultName {
|
fn default_name() -> DefaultName {
|
||||||
DefaultName::Foo
|
DefaultName::Foo
|
||||||
|
|
|
@ -79,7 +79,7 @@ struct FieldWithDefaults {
|
||||||
field_two: i32,
|
field_two: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn test_field(
|
fn test_field(
|
||||||
a1: DefaultName,
|
a1: DefaultName,
|
||||||
|
|
|
@ -52,7 +52,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| {
|
||||||
});
|
});
|
||||||
|
|
||||||
/// The root query object in the schema
|
/// The root query object in the schema
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
interfaces = [&Interface]
|
interfaces = [&Interface]
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct InputWithDefaults {
|
||||||
a: i32,
|
a: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::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::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn exampleNaiveDate() -> NaiveDate {
|
fn exampleNaiveDate() -> NaiveDate {
|
||||||
NaiveDate::from_ymd(2015, 3, 14)
|
NaiveDate::from_ymd(2015, 3, 14)
|
||||||
|
|
|
@ -109,14 +109,13 @@ 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::{
|
||||||
impl_object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue,
|
object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue,
|
||||||
};
|
};
|
||||||
// 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::{
|
||||||
impl_object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal,
|
object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal, GraphQLScalarValueInternal,
|
||||||
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::impl_object(Context = Database)]
|
#[juniper::object(Context = Database)]
|
||||||
impl Human {
|
impl Human {
|
||||||
fn id(&self) -> &str { &self.id }
|
fn id(&self) -> &str { &self.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::object(
|
||||||
name = "Droid",
|
name = "Droid",
|
||||||
Context = Database,
|
Context = Database,
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
## DEPRECATION WARNING
|
## DEPRECATION WARNING
|
||||||
|
|
||||||
The `graphql_object!` macro is deprecated and will be removed soon.
|
The `graphql_object!` macro is deprecated and will be removed soon.
|
||||||
Use the new[impl_object](https://docs.rs/juniper/latest/juniper/macro.impl_object.html) macro instead.
|
Use the new[object](https://docs.rs/juniper/latest/juniper/macro.object.html) macro instead.
|
||||||
|
|
||||||
Expose GraphQL objects
|
Expose GraphQL objects
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct Point {
|
||||||
x: i32,
|
x: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn simple() -> i32 {
|
fn simple() -> i32 {
|
||||||
0
|
0
|
||||||
|
|
|
@ -20,7 +20,7 @@ Syntax to validate:
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
interfaces = [&Interface],
|
interfaces = [&Interface],
|
||||||
)]
|
)]
|
||||||
impl Root {
|
impl Root {
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct WithLifetime<'a> {
|
||||||
value: &'a str,
|
value: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(Context=Context)]
|
#[crate::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::impl_object_internal(Context=Context)]
|
#[crate::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::impl_object_internal(
|
#[crate::object_internal(
|
||||||
scalar = crate::DefaultScalarValue,
|
scalar = crate::DefaultScalarValue,
|
||||||
name = "Query",
|
name = "Query",
|
||||||
context = Context,
|
context = Context,
|
||||||
|
@ -106,7 +106,7 @@ impl<'a> Query {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Mutation;
|
struct Mutation;
|
||||||
|
|
||||||
#[crate::impl_object_internal(context = Context)]
|
#[crate::object_internal(context = Context)]
|
||||||
impl Mutation {
|
impl Mutation {
|
||||||
fn empty() -> bool {
|
fn empty() -> bool {
|
||||||
true
|
true
|
||||||
|
@ -114,7 +114,7 @@ impl Mutation {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn impl_object_introspect() {
|
fn object_introspect() {
|
||||||
let res = util::run_info_query::<Query, Mutation, Context>("Query");
|
let res = util::run_info_query::<Query, Mutation, Context>("Query");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
|
@ -222,7 +222,7 @@ fn impl_object_introspect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn impl_object_query() {
|
fn object_query() {
|
||||||
let doc = r#"
|
let doc = r#"
|
||||||
query {
|
query {
|
||||||
withSelf
|
withSelf
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct ResolversWithTrailingComma;
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Concrete {
|
impl Concrete {
|
||||||
fn simple() -> i32 {
|
fn simple() -> i32 {
|
||||||
0
|
0
|
||||||
|
@ -111,7 +111,7 @@ graphql_interface!(ResolversWithTrailingComma: () |&self| {
|
||||||
field simple() -> i32 { 0 }
|
field simple() -> i32 { 0 }
|
||||||
});
|
});
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl<'a> Root {
|
impl<'a> Root {
|
||||||
fn custom_name() -> CustomName {
|
fn custom_name() -> CustomName {
|
||||||
CustomName {}
|
CustomName {}
|
||||||
|
|
|
@ -78,7 +78,7 @@ graphql_scalar!(ScalarDescription {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn default_name() -> DefaultName {
|
fn default_name() -> DefaultName {
|
||||||
DefaultName(0)
|
DefaultName(0)
|
||||||
|
|
|
@ -46,7 +46,7 @@ enum ResolversWithTrailingComma {
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl Concrete {
|
impl Concrete {
|
||||||
fn simple() -> i32 {
|
fn simple() -> i32 {
|
||||||
123
|
123
|
||||||
|
@ -99,7 +99,7 @@ graphql_union!(ResolversWithTrailingComma: () |&self| {
|
||||||
description: "A description"
|
description: "A description"
|
||||||
});
|
});
|
||||||
|
|
||||||
#[crate::impl_object_internal]
|
#[crate::object_internal]
|
||||||
impl<'a> Root {
|
impl<'a> Root {
|
||||||
fn custom_name() -> CustomName {
|
fn custom_name() -> CustomName {
|
||||||
CustomName::Concrete(Concrete)
|
CustomName::Concrete(Concrete)
|
||||||
|
|
|
@ -31,7 +31,7 @@ struct Foo {
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[crate::impl_object_internal(Scalar = S)]
|
#[crate::object_internal(Scalar = S)]
|
||||||
impl<'a, S> Query
|
impl<'a, S> Query
|
||||||
where
|
where
|
||||||
S: crate::ScalarValue + 'a,
|
S: crate::ScalarValue + 'a,
|
||||||
|
|
|
@ -73,7 +73,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
name = "__Schema"
|
name = "__Schema"
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -111,7 +111,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
name = "__Type"
|
name = "__Type"
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -242,7 +242,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
name = "__Field",
|
name = "__Field",
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -279,7 +279,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
name = "__InputValue",
|
name = "__InputValue",
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
@ -306,7 +306,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
name = "__EnumValue",
|
name = "__EnumValue",
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
)]
|
)]
|
||||||
|
@ -331,7 +331,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
name = "__Directive",
|
name = "__Directive",
|
||||||
Context = SchemaType<'a, S>,
|
Context = SchemaType<'a, S>,
|
||||||
Scalar = S,
|
Scalar = S,
|
||||||
|
|
|
@ -29,7 +29,7 @@ graphql_interface!(<'a> &'a Character: Database as "Character" |&self| {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
Context = Database,
|
Context = Database,
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
interfaces = [&dyn Character],
|
interfaces = [&dyn Character],
|
||||||
|
@ -62,7 +62,7 @@ impl<'a> &'a Human {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
Context = Database,
|
Context = Database,
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
interfaces = [&dyn Character],
|
interfaces = [&dyn Character],
|
||||||
|
@ -95,7 +95,7 @@ impl<'a> &'a Droid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::impl_object_internal(
|
#[crate::object_internal(
|
||||||
name = "Query",
|
name = "Query",
|
||||||
Context = Database,
|
Context = Database,
|
||||||
Scalar = crate::DefaultScalarValue,
|
Scalar = crate::DefaultScalarValue,
|
||||||
|
|
|
@ -2,8 +2,8 @@ use crate::util;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
/// Generate code for the juniper::impl_object macro.
|
/// Generate code for the juniper::object macro.
|
||||||
pub fn build_impl_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,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -62,11 +62,11 @@ pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool
|
||||||
.ident
|
.ident
|
||||||
.to_string(),
|
.to_string(),
|
||||||
_ => {
|
_ => {
|
||||||
panic!("Could not determine a name for the object type: specify one with #[juniper::impl_object(name = \"SomeName\")");
|
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::impl_object(name = \"SomeName\")");
|
panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -76,19 +76,19 @@ pub fn derive_scalar_value_internal(input: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `impl_object` proc macro is the primary way of defining GraphQL resolvers
|
The `object` proc macro is the primary way of defining GraphQL resolvers
|
||||||
that can not be implemented with the GraphQLObject derive.
|
that can not be implemented with the GraphQLObject derive.
|
||||||
|
|
||||||
It enables you to write GraphQL field resolvers for a type by declaring a
|
It enables you to write GraphQL field resolvers for a type by declaring a
|
||||||
regular Rust `impl` block. Under the hood, the procedural macro implements
|
regular Rust `impl` block. Under the hood, the procedural macro implements
|
||||||
the GraphQLType trait.
|
the GraphQLType trait.
|
||||||
|
|
||||||
`impl_object` comes with many features that allow customization of
|
`object` comes with many features that allow customization of
|
||||||
your fields, all of which are detailed below.
|
your fields, all of which are detailed below.
|
||||||
|
|
||||||
### Getting Started
|
### Getting Started
|
||||||
|
|
||||||
This simple example will show you the most basic use of `impl_object`.
|
This simple example will show you the most basic use of `object`.
|
||||||
More advanced use cases are introduced step by step.
|
More advanced use cases are introduced step by step.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -96,7 +96,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::impl_object]
|
#[juniper::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.
|
||||||
|
@ -110,7 +110,7 @@ impl Query {
|
||||||
// - basic scalar types like bool, &str, String, i32, f64
|
// - basic scalar types like bool, &str, String, i32, f64
|
||||||
// - GraphQL compatible wrappers like Option<_>, Vec<_>.
|
// - GraphQL compatible wrappers like Option<_>, Vec<_>.
|
||||||
// - types which use the `#derive[juniper::GraphQLObject]`
|
// - types which use the `#derive[juniper::GraphQLObject]`
|
||||||
// - `impl_object` structs.
|
// - `object` structs.
|
||||||
//
|
//
|
||||||
// An important note regarding naming:
|
// An important note regarding naming:
|
||||||
// By default, field names will be converted to camel case.
|
// By default, field names will be converted to camel case.
|
||||||
|
@ -147,7 +147,7 @@ impl Person {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object]
|
#[juniper::object]
|
||||||
impl Person {
|
impl Person {
|
||||||
fn first_name(&self) -> &str {
|
fn first_name(&self) -> &str {
|
||||||
&self.first_name
|
&self.first_name
|
||||||
|
@ -187,7 +187,7 @@ impl juniper::Context for Context {}
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::object(
|
||||||
// Here we specify the context type for this object.
|
// Here we specify the context type for this object.
|
||||||
Context = Context,
|
Context = Context,
|
||||||
)]
|
)]
|
||||||
|
@ -217,7 +217,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::impl_object(
|
#[juniper::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.
|
||||||
|
@ -280,7 +280,7 @@ struct WithLifetime<'a> {
|
||||||
value: &'a str,
|
value: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::impl_object]
|
#[juniper::object]
|
||||||
impl<'a> WithLifetime<'a> {
|
impl<'a> WithLifetime<'a> {
|
||||||
fn value(&self) -> &str {
|
fn value(&self) -> &str {
|
||||||
self.value
|
self.value
|
||||||
|
@ -301,7 +301,7 @@ You can easily specify a custom scalar though.
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
#[juniper::impl_object(
|
#[juniper::object(
|
||||||
Scalar = MyCustomScalar,
|
Scalar = MyCustomScalar,
|
||||||
)]
|
)]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
@ -311,15 +311,15 @@ impl Query {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn impl_object(args: TokenStream, input: TokenStream) -> TokenStream {
|
pub fn object(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
let gen = impl_object::build_impl_object(args, input, false);
|
let gen = impl_object::build_object(args, input, false);
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 impl_object_internal(args: TokenStream, input: TokenStream) -> TokenStream {
|
pub fn object_internal(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
let gen = impl_object::build_impl_object(args, input, true);
|
let gen = impl_object::build_object(args, input, true);
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,7 +508,7 @@ pub struct FieldAttributes {
|
||||||
pub deprecation: Option<DeprecationAttr>,
|
pub deprecation: Option<DeprecationAttr>,
|
||||||
// Only relevant for GraphQLObject derive.
|
// Only relevant for GraphQLObject derive.
|
||||||
pub skip: bool,
|
pub skip: bool,
|
||||||
/// Only relevant for impl_object macro.
|
/// Only relevant for object macro.
|
||||||
pub arguments: HashMap<String, FieldAttributeArgument>,
|
pub arguments: HashMap<String, FieldAttributeArgument>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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::impl_object( Context = Database )]
|
# #[juniper::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::impl_object( Context = Database )]
|
# #[juniper::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))
|
||||||
|
|
|
@ -134,7 +134,7 @@ where
|
||||||
///
|
///
|
||||||
/// struct QueryRoot;
|
/// struct QueryRoot;
|
||||||
///
|
///
|
||||||
/// #[juniper::impl_object(
|
/// #[juniper::object(
|
||||||
/// Context = ExampleContext
|
/// Context = ExampleContext
|
||||||
/// )]
|
/// )]
|
||||||
/// impl QueryRoot {
|
/// impl QueryRoot {
|
||||||
|
|
Loading…
Reference in a new issue