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;
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
Context = Context,
|
||||
)]
|
||||
impl Query {
|
||||
|
|
|
@ -23,7 +23,7 @@ enum SignUpResult {
|
|||
Error(Vec<ValidationError>),
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl SignUpResult {
|
||||
fn user(&self) -> Option<&User> {
|
||||
match *self {
|
||||
|
|
|
@ -25,7 +25,7 @@ struct ValidationError {
|
|||
# #[allow(dead_code)]
|
||||
struct MutationResult<T>(Result<T, Vec<ValidationError>>);
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
name = "UserResult",
|
||||
)]
|
||||
impl MutationResult<User> {
|
||||
|
@ -38,7 +38,7 @@ impl MutationResult<User> {
|
|||
}
|
||||
}
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
name = "ForumPostResult",
|
||||
)]
|
||||
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
|
||||
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.
|
||||
|
||||
```rust
|
||||
|
@ -60,7 +60,7 @@ struct NewHuman {
|
|||
}
|
||||
|
||||
// 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
|
||||
// pool.
|
||||
|
||||
|
@ -74,7 +74,7 @@ impl juniper::Context for Context {}
|
|||
|
||||
struct Query;
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::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::impl_object(
|
||||
#[juniper::object(
|
||||
Context = Context,
|
||||
)]
|
||||
impl Mutation {
|
||||
|
@ -156,7 +156,7 @@ impl juniper::Context for Ctx {}
|
|||
|
||||
struct Query;
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
Context = Ctx,
|
||||
)]
|
||||
impl Query {
|
||||
|
@ -198,4 +198,4 @@ fn main() {
|
|||
[rocket]: servers/rocket.md
|
||||
[iron]: servers/iron.md
|
||||
[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 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
|
||||
# use juniper::FieldResult;
|
||||
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
||||
struct Root;
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::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::impl_object]
|
||||
#[juniper::object]
|
||||
impl Mutations {
|
||||
fn signUpUser(name: String, email: String) -> FieldResult<User> {
|
||||
// Validate inputs and save user in database...
|
||||
|
|
|
@ -47,7 +47,7 @@ fn context_factory(_: &mut Request) -> IronResult<()> {
|
|||
|
||||
struct Root;
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl Root {
|
||||
fn foo() -> String {
|
||||
"Bar".to_owned()
|
||||
|
@ -99,7 +99,7 @@ fn context_factory(req: &mut Request) -> IronResult<Context> {
|
|||
|
||||
struct Root;
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
Context = Context,
|
||||
)]
|
||||
impl Root {
|
||||
|
|
|
@ -14,7 +14,7 @@ struct Coordinate {
|
|||
struct Root;
|
||||
# #[derive(juniper::GraphQLObject)] struct User { name: String }
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::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::impl_object]
|
||||
#[juniper::object]
|
||||
impl Root {
|
||||
fn users_at_location(coordinate: WorldCoordinate, radius: f64) -> Vec<User> {
|
||||
// Send coordinate to database
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
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:
|
||||
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
|
||||
example from the last chapter, this is how you would define `Person` using the
|
||||
macro:
|
||||
|
@ -14,7 +14,7 @@ struct Person {
|
|||
age: i32,
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl Person {
|
||||
fn name(&self) -> &str {
|
||||
self.name.as_str()
|
||||
|
@ -43,7 +43,7 @@ struct House {
|
|||
inhabitants: Vec<Person>,
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::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 {
|
|||
website_url: String,
|
||||
}
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
// With this attribtue you can change the public GraphQL name of the type.
|
||||
name = "PersonObject",
|
||||
)]
|
||||
|
@ -96,4 +96,4 @@ GraphQL fields expose more features than Rust's standard method syntax gives us:
|
|||
* Per-argument descriptions
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl Example {
|
||||
fn contents() -> FieldResult<String> {
|
||||
let mut file = File::open(&self.filename)?;
|
||||
|
@ -143,7 +143,7 @@ struct Example {
|
|||
whatever: Option<bool>,
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl Example {
|
||||
fn whatever() -> Result<bool, CustomError> {
|
||||
if let Some(value) = self.whatever {
|
||||
|
|
|
@ -57,7 +57,7 @@ struct User {
|
|||
|
||||
|
||||
// Assign Database as the context type for User
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
Context = Database,
|
||||
)]
|
||||
impl User {
|
||||
|
|
|
@ -80,7 +80,7 @@ struct WithCustomContext {
|
|||
a: bool,
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl Query {
|
||||
fn obj() -> Obj {
|
||||
Obj {
|
||||
|
|
|
@ -151,7 +151,7 @@ juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue {
|
|||
|
||||
struct TestType;
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
Scalar = MyScalarValue
|
||||
)]
|
||||
impl TestType {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# master
|
||||
|
||||
### impl_object macro
|
||||
### object macro
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::value::{DefaultScalarValue, Object, Value};
|
|||
|
||||
struct TestType;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl TestType {
|
||||
fn a() -> &str {
|
||||
"a"
|
||||
|
|
|
@ -17,7 +17,7 @@ enum Color {
|
|||
}
|
||||
struct TestType;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl TestType {
|
||||
fn to_string(color: Color) -> String {
|
||||
format!("Color::{:?}", color)
|
||||
|
|
|
@ -7,7 +7,7 @@ mod field_execution {
|
|||
struct DataType;
|
||||
struct DeepDataType;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl DataType {
|
||||
fn a() -> &str {
|
||||
"Apple"
|
||||
|
@ -37,7 +37,7 @@ mod field_execution {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl DeepDataType {
|
||||
fn a() -> &str {
|
||||
"Already Been Done"
|
||||
|
@ -162,7 +162,7 @@ mod merge_parallel_fragments {
|
|||
|
||||
struct Type;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Type {
|
||||
fn a() -> &str {
|
||||
"Apple"
|
||||
|
@ -246,7 +246,7 @@ mod merge_parallel_inline_fragments {
|
|||
struct Type;
|
||||
struct Other;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Type {
|
||||
fn a() -> &str {
|
||||
"Apple"
|
||||
|
@ -265,7 +265,7 @@ mod merge_parallel_inline_fragments {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Other {
|
||||
fn a() -> &str {
|
||||
"Apple"
|
||||
|
@ -396,7 +396,7 @@ mod threads_context_correctly {
|
|||
|
||||
impl Context for TestContext {}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
Context = TestContext,
|
||||
)]
|
||||
impl Schema {
|
||||
|
@ -462,7 +462,7 @@ mod dynamic_context_switching {
|
|||
|
||||
struct ItemRef;
|
||||
|
||||
#[crate::impl_object_internal(Context = OuterContext)]
|
||||
#[crate::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))
|
||||
|
@ -492,7 +492,7 @@ mod dynamic_context_switching {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(Context = InnerContext)]
|
||||
#[crate::object_internal(Context = InnerContext)]
|
||||
impl ItemRef {
|
||||
fn value(context: &InnerContext) -> String {
|
||||
context.value.clone()
|
||||
|
@ -801,7 +801,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Schema {
|
||||
fn inner() -> Inner {
|
||||
Inner
|
||||
|
@ -814,7 +814,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Inner {
|
||||
fn nullable_field() -> Option<Inner> {
|
||||
Some(Inner)
|
||||
|
@ -1068,7 +1068,7 @@ mod named_operations {
|
|||
|
||||
struct Schema;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Schema {
|
||||
fn a() -> &str {
|
||||
"b"
|
||||
|
|
|
@ -37,7 +37,7 @@ mod interface {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
interfaces = [&Pet]
|
||||
)]
|
||||
impl Dog {
|
||||
|
@ -63,7 +63,7 @@ mod interface {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
interfaces = [&Pet]
|
||||
)]
|
||||
impl Cat {
|
||||
|
@ -79,7 +79,7 @@ mod interface {
|
|||
pets: Vec<Box<Pet>>,
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Schema {
|
||||
fn pets(&self) -> Vec<&Pet> {
|
||||
self.pets.iter().map(|p| p.as_ref()).collect()
|
||||
|
@ -188,7 +188,7 @@ mod union {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Dog {
|
||||
fn name(&self) -> &str {
|
||||
&self.name
|
||||
|
@ -209,7 +209,7 @@ mod union {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Cat {
|
||||
fn name(&self) -> &str {
|
||||
&self.name
|
||||
|
@ -223,7 +223,7 @@ mod union {
|
|||
pets: Vec<Box<Pet>>,
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Schema {
|
||||
fn pets(&self) -> Vec<&Pet> {
|
||||
self.pets.iter().map(|p| p.as_ref()).collect()
|
||||
|
|
|
@ -64,7 +64,7 @@ enum EnumDeprecation {
|
|||
|
||||
struct Root;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Root {
|
||||
fn default_name() -> DefaultName {
|
||||
DefaultName::Foo
|
||||
|
|
|
@ -79,7 +79,7 @@ struct FieldWithDefaults {
|
|||
field_two: i32,
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Root {
|
||||
fn test_field(
|
||||
a1: DefaultName,
|
||||
|
|
|
@ -52,7 +52,7 @@ graphql_interface!(Interface: () as "SampleInterface" |&self| {
|
|||
});
|
||||
|
||||
/// The root query object in the schema
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
interfaces = [&Interface]
|
||||
Scalar = crate::DefaultScalarValue,
|
||||
)]
|
||||
|
|
|
@ -62,7 +62,7 @@ struct InputWithDefaults {
|
|||
a: i32,
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl TestType {
|
||||
fn field_with_object_input(input: Option<TestInputObject>) -> String {
|
||||
format!("{:?}", input)
|
||||
|
|
|
@ -210,7 +210,7 @@ mod integration_test {
|
|||
fn test_serialization() {
|
||||
struct Root;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Root {
|
||||
fn exampleNaiveDate() -> NaiveDate {
|
||||
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
|
||||
// functionality automatically.
|
||||
pub use juniper_codegen::{
|
||||
impl_object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue,
|
||||
object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue,
|
||||
};
|
||||
// Internal macros are not exported,
|
||||
// but declared at the root to make them easier to use.
|
||||
#[allow(unused_imports)]
|
||||
use juniper_codegen::{
|
||||
impl_object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal,
|
||||
GraphQLScalarValueInternal,
|
||||
object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal, GraphQLScalarValueInternal,
|
||||
};
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -61,12 +61,12 @@ impl Character for Droid {
|
|||
fn id(&self) -> &str { &self.id }
|
||||
}
|
||||
|
||||
#[juniper::impl_object(Context = Database)]
|
||||
#[juniper::object(Context = Database)]
|
||||
impl Human {
|
||||
fn id(&self) -> &str { &self.id }
|
||||
}
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
name = "Droid",
|
||||
Context = Database,
|
||||
)]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
## DEPRECATION WARNING
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ struct Point {
|
|||
x: i32,
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Root {
|
||||
fn simple() -> i32 {
|
||||
0
|
||||
|
|
|
@ -20,7 +20,7 @@ Syntax to validate:
|
|||
|
||||
*/
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
interfaces = [&Interface],
|
||||
)]
|
||||
impl Root {
|
||||
|
|
|
@ -12,7 +12,7 @@ struct WithLifetime<'a> {
|
|||
value: &'a str,
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(Context=Context)]
|
||||
#[crate::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::impl_object_internal(Context=Context)]
|
||||
#[crate::object_internal(Context=Context)]
|
||||
impl WithContext {
|
||||
fn ctx(ctx: &Context) -> bool {
|
||||
ctx.flag1
|
||||
|
@ -33,7 +33,7 @@ struct Query {
|
|||
b: bool,
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
scalar = crate::DefaultScalarValue,
|
||||
name = "Query",
|
||||
context = Context,
|
||||
|
@ -106,7 +106,7 @@ impl<'a> Query {
|
|||
#[derive(Default)]
|
||||
struct Mutation;
|
||||
|
||||
#[crate::impl_object_internal(context = Context)]
|
||||
#[crate::object_internal(context = Context)]
|
||||
impl Mutation {
|
||||
fn empty() -> bool {
|
||||
true
|
||||
|
@ -114,7 +114,7 @@ impl Mutation {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn impl_object_introspect() {
|
||||
fn object_introspect() {
|
||||
let res = util::run_info_query::<Query, Mutation, Context>("Query");
|
||||
assert_eq!(
|
||||
res,
|
||||
|
@ -222,7 +222,7 @@ fn impl_object_introspect() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn impl_object_query() {
|
||||
fn object_query() {
|
||||
let doc = r#"
|
||||
query {
|
||||
withSelf
|
||||
|
|
|
@ -42,7 +42,7 @@ struct ResolversWithTrailingComma;
|
|||
|
||||
struct Root;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Concrete {
|
||||
fn simple() -> i32 {
|
||||
0
|
||||
|
@ -111,7 +111,7 @@ graphql_interface!(ResolversWithTrailingComma: () |&self| {
|
|||
field simple() -> i32 { 0 }
|
||||
});
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl<'a> Root {
|
||||
fn custom_name() -> CustomName {
|
||||
CustomName {}
|
||||
|
|
|
@ -78,7 +78,7 @@ graphql_scalar!(ScalarDescription {
|
|||
}
|
||||
});
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Root {
|
||||
fn default_name() -> DefaultName {
|
||||
DefaultName(0)
|
||||
|
|
|
@ -46,7 +46,7 @@ enum ResolversWithTrailingComma {
|
|||
|
||||
struct Root;
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl Concrete {
|
||||
fn simple() -> i32 {
|
||||
123
|
||||
|
@ -99,7 +99,7 @@ graphql_union!(ResolversWithTrailingComma: () |&self| {
|
|||
description: "A description"
|
||||
});
|
||||
|
||||
#[crate::impl_object_internal]
|
||||
#[crate::object_internal]
|
||||
impl<'a> Root {
|
||||
fn custom_name() -> CustomName {
|
||||
CustomName::Concrete(Concrete)
|
||||
|
|
|
@ -31,7 +31,7 @@ struct Foo {
|
|||
|
||||
struct Query;
|
||||
|
||||
#[crate::impl_object_internal(Scalar = S)]
|
||||
#[crate::object_internal(Scalar = S)]
|
||||
impl<'a, S> Query
|
||||
where
|
||||
S: crate::ScalarValue + 'a,
|
||||
|
|
|
@ -73,7 +73,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
name = "__Schema"
|
||||
Context = SchemaType<'a, S>,
|
||||
Scalar = S,
|
||||
|
@ -111,7 +111,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
name = "__Type"
|
||||
Context = SchemaType<'a, S>,
|
||||
Scalar = S,
|
||||
|
@ -242,7 +242,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
name = "__Field",
|
||||
Context = SchemaType<'a, S>,
|
||||
Scalar = S,
|
||||
|
@ -279,7 +279,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
name = "__InputValue",
|
||||
Context = SchemaType<'a, S>,
|
||||
Scalar = S,
|
||||
|
@ -306,7 +306,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
name = "__EnumValue",
|
||||
Scalar = S,
|
||||
)]
|
||||
|
@ -331,7 +331,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
name = "__Directive",
|
||||
Context = SchemaType<'a, 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,
|
||||
Scalar = crate::DefaultScalarValue,
|
||||
interfaces = [&dyn Character],
|
||||
|
@ -62,7 +62,7 @@ impl<'a> &'a Human {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
Context = Database,
|
||||
Scalar = crate::DefaultScalarValue,
|
||||
interfaces = [&dyn Character],
|
||||
|
@ -95,7 +95,7 @@ impl<'a> &'a Droid {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::impl_object_internal(
|
||||
#[crate::object_internal(
|
||||
name = "Query",
|
||||
Context = Database,
|
||||
Scalar = crate::DefaultScalarValue,
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::util;
|
|||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
/// Generate code for the juniper::impl_object macro.
|
||||
pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool) -> TokenStream {
|
||||
/// Generate code for the juniper::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,
|
||||
Err(e) => {
|
||||
|
@ -62,11 +62,11 @@ pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool
|
|||
.ident
|
||||
.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.
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
### 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.
|
||||
|
||||
```
|
||||
|
@ -96,7 +96,7 @@ More advanced use cases are introduced step by step.
|
|||
struct Query;
|
||||
|
||||
// We prefix the impl Block with the procedural macro.
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl Query {
|
||||
|
||||
// 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
|
||||
// - GraphQL compatible wrappers like Option<_>, Vec<_>.
|
||||
// - types which use the `#derive[juniper::GraphQLObject]`
|
||||
// - `impl_object` structs.
|
||||
// - `object` structs.
|
||||
//
|
||||
// An important note regarding naming:
|
||||
// By default, field names will be converted to camel case.
|
||||
|
@ -147,7 +147,7 @@ impl Person {
|
|||
}
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl Person {
|
||||
fn first_name(&self) -> &str {
|
||||
&self.first_name
|
||||
|
@ -187,7 +187,7 @@ impl juniper::Context for Context {}
|
|||
|
||||
struct Query;
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
// Here we specify the context type for this object.
|
||||
Context = Context,
|
||||
)]
|
||||
|
@ -217,7 +217,7 @@ struct InternalQuery;
|
|||
// Doc comments can be used to specify graphql documentation.
|
||||
/// GRAPHQL DOCUMENTATION.
|
||||
/// More info for GraphQL users....
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
// You can rename the type for GraphQL by specifying the name here.
|
||||
name = "Query",
|
||||
// You can also specify a description here.
|
||||
|
@ -280,7 +280,7 @@ struct WithLifetime<'a> {
|
|||
value: &'a str,
|
||||
}
|
||||
|
||||
#[juniper::impl_object]
|
||||
#[juniper::object]
|
||||
impl<'a> WithLifetime<'a> {
|
||||
fn value(&self) -> &str {
|
||||
self.value
|
||||
|
@ -301,7 +301,7 @@ You can easily specify a custom scalar though.
|
|||
|
||||
struct Query;
|
||||
|
||||
#[juniper::impl_object(
|
||||
#[juniper::object(
|
||||
Scalar = MyCustomScalar,
|
||||
)]
|
||||
impl Query {
|
||||
|
@ -311,15 +311,15 @@ impl Query {
|
|||
|
||||
*/
|
||||
#[proc_macro_attribute]
|
||||
pub fn impl_object(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let gen = impl_object::build_impl_object(args, input, false);
|
||||
pub fn object(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let gen = impl_object::build_object(args, input, false);
|
||||
gen.into()
|
||||
}
|
||||
|
||||
/// A proc macro for defining a GraphQL object.
|
||||
#[doc(hidden)]
|
||||
#[proc_macro_attribute]
|
||||
pub fn impl_object_internal(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let gen = impl_object::build_impl_object(args, input, true);
|
||||
pub fn object_internal(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let gen = impl_object::build_object(args, input, true);
|
||||
gen.into()
|
||||
}
|
||||
|
|
|
@ -508,7 +508,7 @@ pub struct FieldAttributes {
|
|||
pub deprecation: Option<DeprecationAttr>,
|
||||
// Only relevant for GraphQLObject derive.
|
||||
pub skip: bool,
|
||||
/// Only relevant for impl_object macro.
|
||||
/// Only relevant for object macro.
|
||||
pub arguments: HashMap<String, FieldAttributeArgument>,
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ use juniper::{Context, EmptyMutation};
|
|||
# struct QueryRoot;
|
||||
# struct Database { users: HashMap<String, User> }
|
||||
#
|
||||
# #[juniper::impl_object( Context = Database )]
|
||||
# #[juniper::object( Context = Database )]
|
||||
# impl User {
|
||||
# fn id(&self) -> FieldResult<&String> {
|
||||
# Ok(&self.id)
|
||||
|
@ -54,7 +54,7 @@ use juniper::{Context, EmptyMutation};
|
|||
# }
|
||||
# }
|
||||
#
|
||||
# #[juniper::impl_object( Context = Database )]
|
||||
# #[juniper::object( Context = Database )]
|
||||
# impl QueryRoot {
|
||||
# fn user(context: &Database, id: String) -> FieldResult<Option<&User>> {
|
||||
# Ok(executor.context().users.get(&id))
|
||||
|
|
|
@ -134,7 +134,7 @@ where
|
|||
///
|
||||
/// struct QueryRoot;
|
||||
///
|
||||
/// #[juniper::impl_object(
|
||||
/// #[juniper::object(
|
||||
/// Context = ExampleContext
|
||||
/// )]
|
||||
/// impl QueryRoot {
|
||||
|
|
Loading…
Reference in a new issue