From 5a4230e0d0ffc8f95e153bf4a36b9030279b7f4c Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Tue, 23 Apr 2019 02:19:06 +0200 Subject: [PATCH] Remove macro_use + extern crate statements (2018 edition) --- docs/book/content/quickstart.md | 3 +- .../content/types/objects/error_handling.md | 2 +- .../juniper_tests/src/codegen/derive_enum.rs | 8 +++--- .../src/codegen/derive_input_object.rs | 6 ++-- .../src/codegen/derive_object.rs | 3 +- .../juniper_tests/src/custom_scalar.rs | 6 ++-- integration_tests/juniper_tests/src/lib.rs | 2 -- juniper/src/executor/mod.rs | 3 +- juniper/src/executor_tests/enums.rs | 4 ++- .../src/executor_tests/introspection/enums.rs | 14 ++++++---- .../introspection/input_object.rs | 24 ++++++++-------- .../src/executor_tests/introspection/mod.rs | 4 ++- juniper/src/executor_tests/variables.rs | 10 ++++--- juniper/src/http/mod.rs | 1 + juniper/src/integrations/serde.rs | 5 ++-- juniper/src/lib.rs | 10 ------- juniper/src/macros/interface.rs | 8 +++--- juniper/src/macros/object.rs | 28 +++++++++---------- juniper/src/macros/scalar.rs | 4 +-- juniper/src/macros/tests/args.rs | 4 ++- juniper/src/parser/tests/value.rs | 11 ++++++-- juniper/src/schema/model.rs | 4 ++- juniper/src/tests/model.rs | 3 +- juniper/src/types/base.rs | 4 ++- juniper/src/validation/test_harness.rs | 4 ++- juniper/src/value/mod.rs | 4 +-- juniper/src/value/scalar.rs | 8 +++--- juniper_codegen/src/derive_enum.rs | 1 + juniper_codegen/src/derive_input_object.rs | 6 ++-- juniper_codegen/src/derive_object.rs | 3 +- juniper_codegen/src/derive_scalar_value.rs | 1 + juniper_codegen/src/lib.rs | 8 ------ juniper_codegen/src/util.rs | 2 +- juniper_hyper/src/lib.rs | 16 ++--------- juniper_iron/src/lib.rs | 18 ++++-------- juniper_rocket/examples/rocket_server.rs | 13 +++------ juniper_rocket/src/lib.rs | 14 +++------- juniper_warp/examples/warp_server.rs | 13 +++------ juniper_warp/src/lib.rs | 23 +++------------ 39 files changed, 134 insertions(+), 171 deletions(-) diff --git a/docs/book/content/quickstart.md b/docs/book/content/quickstart.md index 16f0367d..20e438b4 100644 --- a/docs/book/content/quickstart.md +++ b/docs/book/content/quickstart.md @@ -127,8 +127,7 @@ You can invoke `juniper::execute` directly to run a GraphQL query: ```rust # // Only needed due to 2018 edition because the macro is not accessible. -# #[macro_use] -# extern crate juniper; +# #[macro_use] extern crate juniper; use juniper::{FieldResult, Variables, EmptyMutation}; #[derive(juniper::GraphQLEnum, Clone, Copy)] diff --git a/docs/book/content/types/objects/error_handling.md b/docs/book/content/types/objects/error_handling.md index 2cbcf052..a2921ec0 100644 --- a/docs/book/content/types/objects/error_handling.md +++ b/docs/book/content/types/objects/error_handling.md @@ -129,7 +129,7 @@ impl juniper::IntoFieldError for CustomError { match self { CustomError::WhateverNotSet => juniper::FieldError::new( "Whatever does not exist", - juniper::graphql_value!({ + graphql_value!({ "type": "NO_WHATEVER" }), ), diff --git a/integration_tests/juniper_tests/src/codegen/derive_enum.rs b/integration_tests/juniper_tests/src/codegen/derive_enum.rs index 42f3d2c0..fd5dbd3c 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_enum.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_enum.rs @@ -4,7 +4,7 @@ use fnv::FnvHashMap; #[cfg(test)] use juniper::{self, DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue}; -#[derive(GraphQLEnum, Debug, PartialEq)] +#[derive(juniper::GraphQLEnum, Debug, PartialEq)] #[graphql(name = "Some", description = "enum descr")] enum SomeEnum { Regular, @@ -13,7 +13,7 @@ enum SomeEnum { } /// Enum doc. -#[derive(GraphQLEnum)] +#[derive(juniper::GraphQLEnum)] enum DocEnum { /// Variant doc. Foo, @@ -23,7 +23,7 @@ enum DocEnum { /// Doc 2. /// /// Doc 4. -#[derive(GraphQLEnum, Debug, PartialEq)] +#[derive(juniper::GraphQLEnum, Debug, PartialEq)] enum MultiDocEnum { /// Variant 1. /// Variant 2. @@ -31,7 +31,7 @@ enum MultiDocEnum { } /// This is not used as the description. -#[derive(GraphQLEnum, Debug, PartialEq)] +#[derive(juniper::GraphQLEnum, Debug, PartialEq)] #[graphql(description = "enum override")] enum OverrideDocEnum { /// This is not used as the description. diff --git a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs index 0db48933..368704c0 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs @@ -2,7 +2,7 @@ use fnv::FnvHashMap; use juniper::{self, FromInputValue, GraphQLType, InputValue, ToInputValue}; - +use juniper::GraphQLInputObject; use juniper::DefaultScalarValue; #[derive(GraphQLInputObject, Debug, PartialEq)] @@ -103,7 +103,7 @@ fn test_derived_input_object() { // Test default value injection. - let input_no_defaults: InputValue = ::serde_json::from_value(json!({ + let input_no_defaults: InputValue = ::serde_json::from_value(serde_json::json!({ "regularField": "a", })) .unwrap(); @@ -120,7 +120,7 @@ fn test_derived_input_object() { // Test with all values supplied. - let input: InputValue = ::serde_json::from_value(json!({ + let input: InputValue = ::serde_json::from_value(serde_json::json!({ "regularField": "a", "haha": 55, "other": true, diff --git a/integration_tests/juniper_tests/src/codegen/derive_object.rs b/integration_tests/juniper_tests/src/codegen/derive_object.rs index 23686edf..552e855d 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_object.rs @@ -3,6 +3,7 @@ use fnv::FnvHashMap; use juniper::DefaultScalarValue; #[cfg(test)] use juniper::Object; +use juniper::GraphQLObject; #[cfg(test)] use juniper::{self, execute, EmptyMutation, GraphQLType, RootNode, Value, Variables}; @@ -79,7 +80,7 @@ struct WithCustomContext { a: bool, } -graphql_object!(Query: () |&self| { +juniper::graphql_object!(Query: () |&self| { field obj() -> Obj { Obj{ regular_field: true, diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index 561cef03..e3d3732f 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -9,7 +9,7 @@ use juniper::{execute, EmptyMutation, Object, RootNode, Variables}; use juniper::{InputValue, ParseScalarResult, ScalarValue, Value}; use std::fmt; -#[derive(Debug, Clone, PartialEq, GraphQLScalarValue)] +#[derive(Debug, Clone, PartialEq, juniper::GraphQLScalarValue)] enum MyScalarValue { Int(i32), Long(i64), @@ -126,7 +126,7 @@ impl<'de> de::Visitor<'de> for MyScalarValueVisitor { } } -graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue { +juniper::graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue { resolve(&self) -> Value { Value::scalar(*self) } @@ -151,7 +151,7 @@ graphql_scalar!(i64 as "Long" where Scalar = MyScalarValue { struct TestType; -graphql_object!(TestType: () where Scalar = MyScalarValue |&self| { +juniper::graphql_object!(TestType: () where Scalar = MyScalarValue |&self| { field long_field() -> i64 { (::std::i32::MAX as i64) + 1 } diff --git a/integration_tests/juniper_tests/src/lib.rs b/integration_tests/juniper_tests/src/lib.rs index dd47c596..fa3742a3 100644 --- a/integration_tests/juniper_tests/src/lib.rs +++ b/integration_tests/juniper_tests/src/lib.rs @@ -1,7 +1,5 @@ -#[macro_use] extern crate juniper; #[cfg(test)] -#[macro_use] extern crate serde_json; #[cfg(test)] diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index 89e2e345..2150d32b 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -157,9 +157,10 @@ impl FieldError { /// You can use the `graphql_value!` macro to construct an error: /// /// ```rust - /// # #[macro_use] extern crate juniper; + /// # extern crate juniper; /// use juniper::FieldError; /// # use juniper::DefaultScalarValue; + /// use juniper::graphql_value; /// /// # fn sample() { /// # let _: FieldError = diff --git a/juniper/src/executor_tests/enums.rs b/juniper/src/executor_tests/enums.rs index de548a42..590ddbdd 100644 --- a/juniper/src/executor_tests/enums.rs +++ b/juniper/src/executor_tests/enums.rs @@ -1,3 +1,5 @@ +use juniper_codegen::GraphQLEnumInternal as GraphQLEnum; + use crate::ast::InputValue; use crate::executor::Variables; use crate::parser::SourcePosition; @@ -7,7 +9,7 @@ use crate::validation::RuleError; use crate::value::{DefaultScalarValue, Object, Value}; use crate::GraphQLError::ValidationError; -#[derive(GraphQLEnumInternal, Debug)] +#[derive(GraphQLEnum, Debug)] enum Color { Red, Green, diff --git a/juniper/src/executor_tests/introspection/enums.rs b/juniper/src/executor_tests/introspection/enums.rs index e3373d47..c80967e5 100644 --- a/juniper/src/executor_tests/introspection/enums.rs +++ b/juniper/src/executor_tests/introspection/enums.rs @@ -1,3 +1,5 @@ +use juniper_codegen::GraphQLEnumInternal as GraphQLEnum; + use crate::executor::Variables; use crate::schema::model::RootNode; use crate::types::scalars::EmptyMutation; @@ -15,33 +17,33 @@ Syntax to validate: */ -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] enum DefaultName { Foo, Bar, } -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] #[graphql(name = "ANamedEnum")] enum Named { Foo, Bar, } -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] enum NoTrailingComma { Foo, Bar, } -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] #[graphql(description = "A description of the enum itself")] enum EnumDescription { Foo, Bar, } -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] enum EnumValueDescription { #[graphql(description = "The FOO value")] Foo, @@ -49,7 +51,7 @@ enum EnumValueDescription { Bar, } -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] enum EnumDeprecation { #[graphql(deprecated = "Please don't use FOO any more")] Foo, diff --git a/juniper/src/executor_tests/introspection/input_object.rs b/juniper/src/executor_tests/introspection/input_object.rs index 4d9f00f2..68bc2ce9 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -1,3 +1,5 @@ +use juniper_codegen::GraphQLInputObjectInternal as GraphQLInputObject; + use crate::ast::{FromInputValue, InputValue}; use crate::executor::Variables; use crate::schema::model::RootNode; @@ -6,47 +8,47 @@ use crate::value::{DefaultScalarValue, Object, Value}; struct Root; -#[derive(GraphQLInputObjectInternal)] +#[derive(GraphQLInputObject)] struct DefaultName { field_one: String, field_two: String, } -#[derive(GraphQLInputObjectInternal)] +#[derive(GraphQLInputObject)] struct NoTrailingComma { field_one: String, field_two: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] struct Derive { field_one: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] #[graphql(name = "ANamedInputObject")] struct Named { field_one: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] #[graphql(description = "Description for the input object")] struct Description { field_one: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] pub struct Public { field_one: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] #[graphql(description = "Description for the input object")] pub struct PublicWithDescription { field_one: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] #[graphql( name = "APublicNamedInputObjectWithDescription", description = "Description for the input object" @@ -55,13 +57,13 @@ pub struct NamedPublicWithDescription { field_one: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] #[graphql(name = "APublicNamedInputObject")] pub struct NamedPublic { field_one: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] struct FieldDescription { #[graphql(description = "The first field")] field_one: String, @@ -69,7 +71,7 @@ struct FieldDescription { field_two: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] struct FieldWithDefaults { #[graphql(default = "123")] field_one: i32, diff --git a/juniper/src/executor_tests/introspection/mod.rs b/juniper/src/executor_tests/introspection/mod.rs index 3616905a..3c2b3506 100644 --- a/juniper/src/executor_tests/introspection/mod.rs +++ b/juniper/src/executor_tests/introspection/mod.rs @@ -1,6 +1,8 @@ mod enums; mod input_object; +use juniper_codegen::GraphQLEnumInternal as GraphQLEnum; + // This asserts that the input objects defined public actually became public #[allow(unused_imports)] use self::input_object::{NamedPublic, NamedPublicWithDescription}; @@ -10,7 +12,7 @@ use crate::schema::model::RootNode; use crate::types::scalars::EmptyMutation; use crate::value::{ParseScalarResult, ParseScalarValue, Value}; -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] #[graphql(name = "SampleEnum")] enum Sample { One, diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index 4b058f0a..88e7c213 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -1,3 +1,5 @@ +use juniper_codegen::GraphQLInputObjectInternal as GraphQLInputObject; + use crate::ast::InputValue; use crate::executor::Variables; use crate::parser::SourcePosition; @@ -32,7 +34,7 @@ graphql_scalar!(TestComplexScalar { } }); -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] #[graphql(scalar = "DefaultScalarValue")] struct TestInputObject { a: Option, @@ -41,20 +43,20 @@ struct TestInputObject { d: Option, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] #[graphql(scalar = "DefaultScalarValue")] struct TestNestedInputObject { na: TestInputObject, nb: String, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] struct ExampleInputObject { a: Option, b: i32, } -#[derive(GraphQLInputObjectInternal, Debug)] +#[derive(GraphQLInputObject, Debug)] struct InputWithDefaults { #[graphql(default = "123")] a: i32, diff --git a/juniper/src/http/mod.rs b/juniper/src/http/mod.rs index aff4051e..d7976198 100644 --- a/juniper/src/http/mod.rs +++ b/juniper/src/http/mod.rs @@ -5,6 +5,7 @@ pub mod playground; use serde::de::Deserialize; use serde::ser::{self, Serialize, SerializeMap}; +use serde_derive::{Serialize, Deserialize}; use crate::ast::InputValue; use crate::executor::ExecutionError; diff --git a/juniper/src/integrations/serde.rs b/juniper/src/integrations/serde.rs index 8a53622e..1863f9d3 100644 --- a/juniper/src/integrations/serde.rs +++ b/juniper/src/integrations/serde.rs @@ -1,6 +1,7 @@ use indexmap::IndexMap; use serde::ser::SerializeMap; use serde::{de, ser}; +use serde_derive::Serialize; use std::fmt; @@ -130,7 +131,7 @@ where self.0.visit_i64(value).map(InputValue::Scalar) } - serde_if_integer128! { + serde::serde_if_integer128! { fn visit_i128(self, value: i128) -> Result, E> where E: de::Error, @@ -167,7 +168,7 @@ where self.0.visit_u64(value).map(InputValue::Scalar) } - serde_if_integer128! { + serde::serde_if_integer128! { fn visit_u128(self, value: u128) -> Result, E> where E: de::Error, diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index ad676772..65f8e9df 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -91,18 +91,11 @@ Juniper has not reached 1.0 yet, thus some API instability should be expected. #![warn(missing_docs)] #[doc(hidden)] -#[macro_use] pub extern crate serde; -#[macro_use] -extern crate serde_derive; #[cfg(any(test, feature = "expose-test-schema"))] extern crate serde_json; -extern crate fnv; - -extern crate indexmap; - #[cfg(any(test, feature = "chrono"))] extern crate chrono; @@ -115,9 +108,6 @@ extern crate uuid; // Depend on juniper_codegen and re-export everything in it. // This allows users to just depend on juniper and get the derive // functionality automatically. -#[allow(unused_imports)] -#[macro_use] -extern crate juniper_codegen; #[doc(hidden)] pub use juniper_codegen::*; diff --git a/juniper/src/macros/interface.rs b/juniper/src/macros/interface.rs index 898ab0cc..7de478fc 100644 --- a/juniper/src/macros/interface.rs +++ b/juniper/src/macros/interface.rs @@ -40,7 +40,7 @@ A simplified extract from the StarWars schema example shows how to use the shared context to implement downcasts. ```rust -# #[macro_use] extern crate juniper; +# extern crate juniper; # use std::collections::HashMap; struct Human { id: String } struct Droid { id: String } @@ -61,16 +61,16 @@ impl Character for Droid { fn id(&self) -> &str { &self.id } } -graphql_object!(Human: Database as "Human" |&self| { +juniper::graphql_object!(Human: Database as "Human" |&self| { field id() -> &str { &self.id } }); -graphql_object!(Droid: Database as "Droid" |&self| { +juniper::graphql_object!(Droid: Database as "Droid" |&self| { field id() -> &str { &self.id } }); // You can introduce lifetimes or generic parameters by < > before the name. -graphql_interface!(<'a> &'a Character: Database as "Character" |&self| { +juniper::graphql_interface!(<'a> &'a Character: Database as "Character" |&self| { field id() -> &str { self.id() } instance_resolvers: |&context| { diff --git a/juniper/src/macros/object.rs b/juniper/src/macros/object.rs index ee105420..72207c8a 100644 --- a/juniper/src/macros/object.rs +++ b/juniper/src/macros/object.rs @@ -10,10 +10,10 @@ safety and reduce repetitive declarations. The simplest case exposes fields on a struct: ```rust -# #[macro_use] extern crate juniper; +# extern crate juniper; struct User { id: String, name: String, group_ids: Vec } -graphql_object!(User: () |&self| { +juniper::graphql_object!(User: () |&self| { field id() -> &String { &self.id } @@ -42,10 +42,10 @@ attributes. Alternatively the same syntax as for the type could be used ```rust -# #[macro_use] extern crate juniper; +# extern crate juniper; struct User { id: String, name: String, group_ids: Vec } -graphql_object!(User: () |&self| { +juniper::graphql_object!(User: () |&self| { description: "A user in the database" @@ -77,16 +77,16 @@ You can expose generic or pointer types by prefixing the type with the necessary generic parameters: ```rust -# #[macro_use] extern crate juniper; +# extern crate juniper; trait SomeTrait { fn id(&self) -> &str; } -graphql_object!(<'a> &'a SomeTrait: () as "SomeTrait" |&self| { +juniper::graphql_object!(<'a> &'a SomeTrait: () as "SomeTrait" |&self| { field id() -> &str { self.id() } }); struct GenericType { items: Vec } -graphql_object!( GenericType: () as "GenericType" |&self| { +juniper::graphql_object!( GenericType: () as "GenericType" |&self| { field count() -> i32 { self.items.len() as i32 } }); @@ -98,14 +98,14 @@ graphql_object!( GenericType: () as "GenericType" |&self| { You can use the `interfaces` item to implement interfaces: ```rust -# #[macro_use] extern crate juniper; +# extern crate juniper; trait Interface { fn id(&self) -> &str; fn as_implementor(&self) -> Option; } struct Implementor { id: String } -graphql_interface!(<'a> &'a Interface: () as "Interface" |&self| { +juniper::graphql_interface!(<'a> &'a Interface: () as "Interface" |&self| { field id() -> &str { self.id() } instance_resolvers: |&context| { @@ -113,7 +113,7 @@ graphql_interface!(<'a> &'a Interface: () as "Interface" |&self| { } }); -graphql_object!(Implementor: () |&self| { +juniper::graphql_object!(Implementor: () |&self| { field id() -> &str { &self.id } interfaces: [&Interface] @@ -140,11 +140,11 @@ automatically via the `?` operator, or you can construct them yourself using `FieldError::new`. ``` -# #[macro_use] extern crate juniper; +# extern crate juniper; # use juniper::FieldResult; struct User { id: String } -graphql_object!(User: () |&self| { +juniper::graphql_object!(User: () |&self| { field id() -> FieldResult<&String> { Ok(&self.id) } @@ -172,10 +172,10 @@ be used as type parameter to the implementing type. Example for using a generic scalar value type ```rust -# #[macro_use] extern crate juniper; +# extern crate juniper; struct User { id: String } -graphql_object!(User: () where Scalar = |&self| { +juniper::graphql_object!(User: () where Scalar = |&self| { field id() -> &String { &self.id } diff --git a/juniper/src/macros/scalar.rs b/juniper/src/macros/scalar.rs index 93e2e324..56537072 100644 --- a/juniper/src/macros/scalar.rs +++ b/juniper/src/macros/scalar.rs @@ -17,11 +17,11 @@ possible to use the same syntax as on `graphql_object!` to specify a custom representation. ```rust -# #[macro_use] extern crate juniper; +# extern crate juniper; # use juniper::{Value, FieldResult, ParseScalarValue, ParseScalarResult}; struct UserID(String); -graphql_scalar!(UserID { +juniper::graphql_scalar!(UserID { description: "An opaque identifier, represented as a string" resolve(&self) -> Value { diff --git a/juniper/src/macros/tests/args.rs b/juniper/src/macros/tests/args.rs index 0f19142e..91818a35 100644 --- a/juniper/src/macros/tests/args.rs +++ b/juniper/src/macros/tests/args.rs @@ -1,3 +1,5 @@ +use juniper_codegen::GraphQLInputObjectInternal as GraphQLInputObject; + use crate::executor::Variables; use crate::schema::model::RootNode; use crate::types::scalars::EmptyMutation; @@ -19,7 +21,7 @@ Syntax to validate: */ -#[derive(GraphQLInputObjectInternal)] +#[derive(GraphQLInputObject)] struct Point { x: i32, } diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index fed1c316..21282a38 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -1,5 +1,10 @@ use indexmap::IndexMap; +use juniper_codegen::{ + GraphQLInputObjectInternal as GraphQLInputObject, + GraphQLEnumInternal as GraphQLEnum, +}; + use crate::ast::{FromInputValue, InputValue, Type}; use crate::parser::value::parse_value_literal; use crate::parser::{Lexer, Parser, SourcePosition, Spanning}; @@ -9,17 +14,17 @@ use crate::schema::meta::{Argument, EnumMeta, EnumValue, InputObjectMeta, MetaTy use crate::schema::model::SchemaType; use crate::types::scalars::EmptyMutation; -#[derive(GraphQLEnumInternal)] +#[derive(GraphQLEnum)] enum Enum { EnumValue, } -#[derive(GraphQLInputObjectInternal)] +#[derive(GraphQLInputObject)] struct Bar { foo: String, } -#[derive(GraphQLInputObjectInternal)] +#[derive(GraphQLInputObject)] struct Foo { key: i32, other: Bar, diff --git a/juniper/src/schema/model.rs b/juniper/src/schema/model.rs index d63bd9f7..c2bb8f56 100644 --- a/juniper/src/schema/model.rs +++ b/juniper/src/schema/model.rs @@ -2,6 +2,8 @@ use std::fmt; use fnv::FnvHashMap; +use juniper_codegen::GraphQLEnumInternal as GraphQLEnum; + use crate::ast::Type; use crate::executor::{Context, Registry}; use crate::schema::meta::{Argument, InterfaceMeta, MetaType, ObjectMeta, PlaceholderMeta, UnionMeta}; @@ -57,7 +59,7 @@ pub struct DirectiveType<'a, S> { pub arguments: Vec>, } -#[derive(Clone, PartialEq, Eq, Debug, GraphQLEnumInternal)] +#[derive(Clone, PartialEq, Eq, Debug, GraphQLEnum)] #[graphql(name = "__DirectiveLocation")] pub enum DirectiveLocation { Query, diff --git a/juniper/src/tests/model.rs b/juniper/src/tests/model.rs index 27681a01..37743a3e 100644 --- a/juniper/src/tests/model.rs +++ b/juniper/src/tests/model.rs @@ -1,8 +1,9 @@ #![allow(missing_docs)] use std::collections::HashMap; +use juniper_codegen::GraphQLEnumInternal as GraphQLEnum; -#[derive(GraphQLEnumInternal, Copy, Clone, Eq, PartialEq, Debug)] +#[derive(GraphQLEnum, Copy, Clone, Eq, PartialEq, Debug)] pub enum Episode { #[graphql(name = "NEW_HOPE")] NewHope, diff --git a/juniper/src/types/base.rs b/juniper/src/types/base.rs index 84e97069..53b8424e 100644 --- a/juniper/src/types/base.rs +++ b/juniper/src/types/base.rs @@ -1,5 +1,7 @@ use indexmap::IndexMap; +use juniper_codegen::GraphQLEnumInternal as GraphQLEnum; + use crate::ast::{Directive, FromInputValue, InputValue, Selection}; use crate::executor::Variables; use crate::value::{DefaultScalarValue, Object, ScalarRefValue, ScalarValue, Value}; @@ -12,7 +14,7 @@ use crate::schema::meta::{Argument, MetaType}; /// /// The GraphQL specification defines a number of type kinds - the meta type /// of a type. -#[derive(Clone, Eq, PartialEq, Debug, GraphQLEnumInternal)] +#[derive(Clone, Eq, PartialEq, Debug, GraphQLEnum)] #[graphql(name = "__TypeKind")] pub enum TypeKind { /// ## Scalar types diff --git a/juniper/src/validation/test_harness.rs b/juniper/src/validation/test_harness.rs index ec79f85d..7c3a2684 100644 --- a/juniper/src/validation/test_harness.rs +++ b/juniper/src/validation/test_harness.rs @@ -1,3 +1,5 @@ +use juniper_codegen::GraphQLInputObjectInternal as GraphQLInputObject; + use crate::ast::{FromInputValue, InputValue}; use crate::executor::Registry; use crate::parser::parse_document_source; @@ -27,7 +29,7 @@ struct ComplicatedArgs; pub(crate) struct QueryRoot; -#[derive(Debug, GraphQLInputObjectInternal)] +#[derive(Debug, GraphQLInputObject)] struct TestInput { id: i32, name: String, diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index 9050920a..b4bf33cc 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -242,8 +242,8 @@ where /// Here are some examples; the resulting JSON will look just like what you /// passed in. /// ```rust -/// #[macro_use] extern crate juniper; -/// # use juniper::{Value, DefaultScalarValue}; +/// extern crate juniper; +/// # use juniper::{Value, DefaultScalarValue, graphql_value}; /// # type V = Value; /// /// # fn main() { diff --git a/juniper/src/value/scalar.rs b/juniper/src/value/scalar.rs index 7f0b6f13..0ceae6d8 100644 --- a/juniper/src/value/scalar.rs +++ b/juniper/src/value/scalar.rs @@ -2,6 +2,7 @@ use crate::parser::{ParseError, ScalarToken}; use serde::de; use serde::ser::Serialize; use std::fmt::{self, Debug, Display}; +use juniper_codegen::GraphQLScalarValueInternal as GraphQLScalarValue; /// The result of converting a string into a scalar value pub type ParseScalarResult<'a, S = DefaultScalarValue> = Result>; @@ -18,7 +19,7 @@ pub trait ParseScalarValue { /// The main objective of this abstraction is to allow other libraries to /// replace the default representation with something that better fits thei /// needs. -/// There is a custom derive (`#[derive(GraphQLScalarValue)]`) available that implements +/// There is a custom derive (`#[derive(juniper::GraphQLScalarValue)]`) available that implements /// most of the required traits automatically for a enum representing a scalar value. /// This derives needs a additional annotation of the form /// `#[juniper(visitor = "VisitorType")]` to specify a type that implements @@ -31,14 +32,13 @@ pub trait ParseScalarValue { /// The following example introduces an new variant that is able to store 64 bit integers. /// /// ``` -/// # #[macro_use] /// # extern crate juniper; /// # extern crate serde; /// # use serde::{de, Deserialize, Deserializer}; /// # use juniper::ScalarValue; /// # use std::fmt; /// # -/// #[derive(Debug, Clone, PartialEq, GraphQLScalarValue)] +/// #[derive(Debug, Clone, PartialEq, juniper::GraphQLScalarValue)] /// enum MyScalarValue { /// Int(i32), /// Long(i64), @@ -252,7 +252,7 @@ where /// The default scalar value representation in juniper /// /// This types closely follows the graphql specification. -#[derive(Debug, PartialEq, Clone, GraphQLScalarValueInternal)] +#[derive(Debug, PartialEq, Clone, GraphQLScalarValue)] #[allow(missing_docs)] pub enum DefaultScalarValue { Int(i32), diff --git a/juniper_codegen/src/derive_enum.rs b/juniper_codegen/src/derive_enum.rs index 2153984f..6c7bec2d 100644 --- a/juniper_codegen/src/derive_enum.rs +++ b/juniper_codegen/src/derive_enum.rs @@ -1,5 +1,6 @@ use proc_macro2::TokenStream; +use quote::quote; use syn::{self, Data, DeriveInput, Fields, Variant}; use crate::util::*; diff --git a/juniper_codegen/src/derive_input_object.rs b/juniper_codegen/src/derive_input_object.rs index 7e029f05..111cd366 100644 --- a/juniper_codegen/src/derive_input_object.rs +++ b/juniper_codegen/src/derive_input_object.rs @@ -1,8 +1,8 @@ use std::str::FromStr; use proc_macro2::{Span, TokenStream}; -use quote::ToTokens; -use syn::{self, Data, DeriveInput, Field, Fields, Ident, Meta, NestedMeta}; +use quote::{quote, ToTokens}; +use syn::{self, Data, DeriveInput, Field, Fields, Ident, Meta, NestedMeta, parse_quote}; use crate::util::*; @@ -183,7 +183,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre Some(quote! { Default::default() }) } else { match field_attrs.default_expr { - Some(ref def) => match ::proc_macro::TokenStream::from_str(def) { + Some(ref def) => match proc_macro::TokenStream::from_str(def) { Ok(t) => match syn::parse::(t) { Ok(e) => { let mut tokens = TokenStream::new(); diff --git a/juniper_codegen/src/derive_object.rs b/juniper_codegen/src/derive_object.rs index e6a5ffe4..f85cffc5 100644 --- a/juniper_codegen/src/derive_object.rs +++ b/juniper_codegen/src/derive_object.rs @@ -1,5 +1,6 @@ use proc_macro2::{Span, TokenStream}; -use syn::{self, Data, DeriveInput, Field, Fields, Ident}; +use syn::{self, Data, DeriveInput, Field, Fields, Ident, parse_quote}; +use quote::quote; use crate::util::*; diff --git a/juniper_codegen/src/derive_scalar_value.rs b/juniper_codegen/src/derive_scalar_value.rs index 5a5ae662..f969fb3f 100644 --- a/juniper_codegen/src/derive_scalar_value.rs +++ b/juniper_codegen/src/derive_scalar_value.rs @@ -1,5 +1,6 @@ use proc_macro2::TokenStream; +use quote::quote; use syn::{self, Data, Fields, Ident, Variant}; pub fn impl_scalar_value(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream { diff --git a/juniper_codegen/src/lib.rs b/juniper_codegen/src/lib.rs index 81d4dd44..7717d1e1 100644 --- a/juniper_codegen/src/lib.rs +++ b/juniper_codegen/src/lib.rs @@ -7,14 +7,6 @@ #![recursion_limit = "1024"] extern crate proc_macro; -extern crate proc_macro2; -#[macro_use] -extern crate quote; -#[macro_use] -extern crate syn; -#[macro_use] -extern crate lazy_static; -extern crate regex; mod derive_enum; mod derive_input_object; diff --git a/juniper_codegen/src/util.rs b/juniper_codegen/src/util.rs index 12e9175d..808bdc27 100644 --- a/juniper_codegen/src/util.rs +++ b/juniper_codegen/src/util.rs @@ -206,7 +206,7 @@ pub(crate) fn to_upper_snake_case(s: &str) -> String { #[doc(hidden)] pub fn is_valid_name(field_name: &str) -> bool { - lazy_static! { + lazy_static::lazy_static! { static ref GRAPHQL_NAME_SPEC: Regex = Regex::new("^[_A-Za-z][_0-9A-Za-z]*$").unwrap(); } GRAPHQL_NAME_SPEC.is_match(field_name) diff --git a/juniper_hyper/src/lib.rs b/juniper_hyper/src/lib.rs index eaa23dc0..2c217a37 100644 --- a/juniper_hyper/src/lib.rs +++ b/juniper_hyper/src/lib.rs @@ -1,15 +1,5 @@ -#[macro_use] -extern crate futures; -extern crate hyper; -extern crate juniper; -#[macro_use] -extern crate serde_derive; #[cfg(test)] extern crate reqwest; -extern crate serde_json; -extern crate tokio; -extern crate tokio_threadpool; -extern crate url; use futures::future::Either; use hyper::header::HeaderValue; @@ -204,7 +194,7 @@ fn new_html_response(code: StatusCode) -> Response { resp } -#[derive(Deserialize)] +#[derive(serde_derive::Deserialize)] #[serde(untagged)] #[serde(bound = "InputValue: Deserialize<'de>")] enum GraphQLRequest @@ -232,7 +222,7 @@ where { match self { GraphQLRequest::Single(request) => Either::A(future::poll_fn(move || { - let res = try_ready!(tokio_threadpool::blocking( + let res = futures::try_ready!(tokio_threadpool::blocking( || request.execute(&root_node, &context) )); let is_ok = res.is_ok(); @@ -246,7 +236,7 @@ where let root_node = root_node.clone(); let context = context.clone(); future::poll_fn(move || { - let res = try_ready!(tokio_threadpool::blocking( + let res = futures::try_ready!(tokio_threadpool::blocking( || request.execute(&root_node, &context) )); let is_ok = res.is_ok(); diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index bff305fa..4aa3cd73 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -23,7 +23,7 @@ the schema on an HTTP endpoint supporting both GET and POST requests: ```rust,no_run extern crate iron; -# #[macro_use] extern crate juniper; +# extern crate juniper; # extern crate juniper_iron; # use std::collections::HashMap; @@ -37,7 +37,7 @@ use juniper::{Context, EmptyMutation}; # struct QueryRoot; # struct Database { users: HashMap } # -# graphql_object!(User: Database |&self| { +# juniper::graphql_object!(User: Database |&self| { # field id() -> FieldResult<&String> { # Ok(&self.id) # } @@ -53,7 +53,7 @@ use juniper::{Context, EmptyMutation}; # } # }); # -# graphql_object!(QueryRoot: Database |&self| { +# juniper::graphql_object!(QueryRoot: Database |&self| { # field user(&executor, id: String) -> FieldResult> { # Ok(executor.context().users.get(&id)) # } @@ -101,18 +101,12 @@ supported. */ -#[macro_use] -extern crate iron; #[cfg(test)] extern crate iron_test; -extern crate juniper; -extern crate serde_json; -#[macro_use] -extern crate serde_derive; #[cfg(test)] extern crate url; -extern crate urlencoded; +use iron::itry; use iron::method; use iron::middleware::Handler; use iron::mime::Mime; @@ -130,7 +124,7 @@ use juniper::http; use juniper::serde::Deserialize; use juniper::{DefaultScalarValue, GraphQLType, InputValue, RootNode, ScalarRefValue, ScalarValue}; -#[derive(Deserialize)] +#[derive(serde_derive::Deserialize)] #[serde(untagged)] #[serde(bound = "InputValue: Deserialize<'de>")] enum GraphQLBatchRequest @@ -141,7 +135,7 @@ where Batch(Vec>), } -#[derive(Serialize)] +#[derive(serde_derive::Serialize)] #[serde(untagged)] enum GraphQLBatchResponse<'a, S = DefaultScalarValue> where diff --git a/juniper_rocket/examples/rocket_server.rs b/juniper_rocket/examples/rocket_server.rs index 05e88287..8417ce7e 100644 --- a/juniper_rocket/examples/rocket_server.rs +++ b/juniper_rocket/examples/rocket_server.rs @@ -1,10 +1,5 @@ #![feature(decl_macro, proc_macro_hygiene)] -extern crate juniper; -extern crate juniper_rocket; -#[macro_use] -extern crate rocket; - use rocket::response::content; use rocket::State; @@ -13,12 +8,12 @@ use juniper::{EmptyMutation, RootNode}; type Schema = RootNode<'static, Database, EmptyMutation>; -#[get("/")] +#[rocket::get("/")] fn graphiql() -> content::Html { juniper_rocket::graphiql_source("/graphql") } -#[get("/graphql?")] +#[rocket::get("/graphql?")] fn get_graphql_handler( context: State, request: juniper_rocket::GraphQLRequest, @@ -27,7 +22,7 @@ fn get_graphql_handler( request.execute(&schema, &context) } -#[post("/graphql", data = "")] +#[rocket::post("/graphql", data = "")] fn post_graphql_handler( context: State, request: juniper_rocket::GraphQLRequest, @@ -45,7 +40,7 @@ fn main() { )) .mount( "/", - routes![graphiql, get_graphql_handler, post_graphql_handler], + rocket::routes![graphiql, get_graphql_handler, post_graphql_handler], ) .launch(); } diff --git a/juniper_rocket/src/lib.rs b/juniper_rocket/src/lib.rs index b69cb983..8f746155 100644 --- a/juniper_rocket/src/lib.rs +++ b/juniper_rocket/src/lib.rs @@ -38,12 +38,6 @@ Check the LICENSE file for details. #![feature(decl_macro, proc_macro_hygiene)] -extern crate juniper; -extern crate rocket; -extern crate serde_json; -#[macro_use] -extern crate serde_derive; - use std::error::Error; use std::io::{Cursor, Read}; @@ -66,7 +60,7 @@ use juniper::RootNode; use juniper::ScalarRefValue; use juniper::ScalarValue; -#[derive(Debug, Deserialize, PartialEq)] +#[derive(Debug, serde_derive::Deserialize, PartialEq)] #[serde(untagged)] #[serde(bound = "InputValue: Deserialize<'de>")] enum GraphQLBatchRequest @@ -77,7 +71,7 @@ where Batch(Vec>), } -#[derive(Serialize)] +#[derive(serde_derive::Serialize)] #[serde(untagged)] enum GraphQLBatchResponse<'a, S = DefaultScalarValue> where @@ -191,7 +185,7 @@ impl GraphQLResponse { /// # /// # extern crate juniper; /// # extern crate juniper_rocket; - /// # #[macro_use] extern crate rocket; + /// # extern crate rocket; /// # /// # use rocket::http::Cookies; /// # use rocket::request::Form; @@ -203,7 +197,7 @@ impl GraphQLResponse { /// # /// # type Schema = RootNode<'static, Database, EmptyMutation>; /// # - /// #[get("/graphql?")] + /// #[rocket::get("/graphql?")] /// fn get_graphql_handler( /// mut cookies: Cookies, /// context: State, diff --git a/juniper_warp/examples/warp_server.rs b/juniper_warp/examples/warp_server.rs index f997be7a..d158f769 100644 --- a/juniper_warp/examples/warp_server.rs +++ b/juniper_warp/examples/warp_server.rs @@ -1,15 +1,10 @@ #![deny(warnings)] -extern crate env_logger; -#[macro_use] -extern crate log as irrelevant_log; -extern crate juniper; -extern crate juniper_warp; -extern crate warp; +extern crate log; use juniper::tests::model::Database; use juniper::{EmptyMutation, RootNode}; -use warp::{http::Response, log, Filter}; +use warp::{http::Response, Filter}; type Schema = RootNode<'static, Database, EmptyMutation>; @@ -21,7 +16,7 @@ fn main() { ::std::env::set_var("RUST_LOG", "warp_server"); env_logger::init(); - let log = log("warp_server"); + let log = warp::log("warp_server"); let homepage = warp::path::end().map(|| { Response::builder() @@ -31,7 +26,7 @@ fn main() { )) }); - info!("Listening on 127.0.0.1:8080"); + log::info!("Listening on 127.0.0.1:8080"); let state = warp::any().map(move || Database::new()); let graphql_filter = juniper_warp::make_graphql_filter(schema(), state.boxed()); diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index 0a24054a..458fb42e 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -39,27 +39,13 @@ Check the LICENSE file for details. #![deny(missing_docs)] #![deny(warnings)] -#[macro_use] -extern crate failure; -extern crate futures; -extern crate juniper; -#[macro_use] -extern crate serde_derive; -extern crate serde; -extern crate serde_json; -extern crate tokio_threadpool; -extern crate warp; - -#[cfg(test)] -extern crate percent_encoding; - use futures::{future::poll_fn, Future}; use juniper::{DefaultScalarValue, InputValue, ScalarRefValue, ScalarValue}; use serde::Deserialize; use std::sync::Arc; use warp::{filters::BoxedFilter, Filter}; -#[derive(Debug, Deserialize, PartialEq)] +#[derive(Debug, serde_derive::Deserialize, PartialEq)] #[serde(untagged)] #[serde(bound = "InputValue: Deserialize<'de>")] enum GraphQLBatchRequest @@ -98,7 +84,7 @@ where } } -#[derive(Serialize)] +#[derive(serde_derive::Serialize)] #[serde(untagged)] enum GraphQLBatchResponse<'a, S = DefaultScalarValue> where @@ -132,7 +118,6 @@ where /// /// ``` /// # extern crate juniper_warp; -/// # #[macro_use] /// # extern crate juniper; /// # extern crate warp; /// # @@ -149,7 +134,7 @@ where /// /// struct QueryRoot; /// -/// graphql_object! (QueryRoot: ExampleContext |&self| { +/// juniper::graphql_object! (QueryRoot: ExampleContext |&self| { /// field say_hello(&executor) -> String { /// let context = executor.context(); /// @@ -226,7 +211,7 @@ where let graphql_request = juniper::http::GraphQLRequest::new( request.remove("query").ok_or_else(|| { - format_err!("Missing GraphQL query string in query parameters") + failure::format_err!("Missing GraphQL query string in query parameters") })?, request.get("operation_name").map(|s| s.to_owned()), variables,