Remove macro_use + extern crate statements (2018 edition)

This commit is contained in:
Christoph Herzog 2019-04-23 02:19:06 +02:00
parent 54a1b64a79
commit 5a4230e0d0
No known key found for this signature in database
GPG key ID: DAFF71D48B493238
39 changed files with 134 additions and 171 deletions

View file

@ -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)]

View file

@ -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"
}),
),

View file

@ -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.

View file

@ -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,

View file

@ -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,

View file

@ -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
}

View file

@ -1,7 +1,5 @@
#[macro_use]
extern crate juniper;
#[cfg(test)]
#[macro_use]
extern crate serde_json;
#[cfg(test)]

View file

@ -157,9 +157,10 @@ impl<S> FieldError<S> {
/// 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<DefaultScalarValue> =

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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<String>,
@ -41,20 +43,20 @@ struct TestInputObject {
d: Option<TestComplexScalar>,
}
#[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<String>,
b: i32,
}
#[derive(GraphQLInputObjectInternal, Debug)]
#[derive(GraphQLInputObject, Debug)]
struct InputWithDefaults {
#[graphql(default = "123")]
a: i32,

View file

@ -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;

View file

@ -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<E>(self, value: i128) -> Result<InputValue<S>, 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<E>(self, value: u128) -> Result<InputValue<S>, E>
where
E: de::Error,

View file

@ -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::*;

View file

@ -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| {

View file

@ -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<String> }
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<String> }
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<T> { items: Vec<T> }
graphql_object!(<T> GenericType<T>: () as "GenericType" |&self| {
juniper::graphql_object!(<T> GenericType<T>: () as "GenericType" |&self| {
field count() -> i32 { self.items.len() as i32 }
});
@ -98,14 +98,14 @@ graphql_object!(<T> GenericType<T>: () 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<Implementor>;
}
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 = <S> |&self| {
juniper::graphql_object!(User: () where Scalar = <S> |&self| {
field id() -> &String {
&self.id
}

View file

@ -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 {

View file

@ -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,
}

View file

@ -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,

View file

@ -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<Argument<'a, S>>,
}
#[derive(Clone, PartialEq, Eq, Debug, GraphQLEnumInternal)]
#[derive(Clone, PartialEq, Eq, Debug, GraphQLEnum)]
#[graphql(name = "__DirectiveLocation")]
pub enum DirectiveLocation {
Query,

View file

@ -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,

View file

@ -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

View file

@ -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,

View file

@ -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<DefaultScalarValue>;
///
/// # fn main() {

View file

@ -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<S, ParseError<'a>>;
@ -18,7 +19,7 @@ pub trait ParseScalarValue<S = DefaultScalarValue> {
/// 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<S = DefaultScalarValue> {
/// 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),

View file

@ -1,5 +1,6 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::{self, Data, DeriveInput, Fields, Variant};
use crate::util::*;

View file

@ -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::<syn::Expr>(t) {
Ok(e) => {
let mut tokens = TokenStream::new();

View file

@ -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::*;

View file

@ -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 {

View file

@ -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;

View file

@ -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)

View file

@ -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<Body> {
resp
}
#[derive(Deserialize)]
#[derive(serde_derive::Deserialize)]
#[serde(untagged)]
#[serde(bound = "InputValue<S>: Deserialize<'de>")]
enum GraphQLRequest<S = DefaultScalarValue>
@ -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();

View file

@ -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<String, User> }
#
# 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<Option<&User>> {
# 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<S>: Deserialize<'de>")]
enum GraphQLBatchRequest<S = DefaultScalarValue>
@ -141,7 +135,7 @@ where
Batch(Vec<http::GraphQLRequest<S>>),
}
#[derive(Serialize)]
#[derive(serde_derive::Serialize)]
#[serde(untagged)]
enum GraphQLBatchResponse<'a, S = DefaultScalarValue>
where

View file

@ -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<Database>>;
#[get("/")]
#[rocket::get("/")]
fn graphiql() -> content::Html<String> {
juniper_rocket::graphiql_source("/graphql")
}
#[get("/graphql?<request>")]
#[rocket::get("/graphql?<request>")]
fn get_graphql_handler(
context: State<Database>,
request: juniper_rocket::GraphQLRequest,
@ -27,7 +22,7 @@ fn get_graphql_handler(
request.execute(&schema, &context)
}
#[post("/graphql", data = "<request>")]
#[rocket::post("/graphql", data = "<request>")]
fn post_graphql_handler(
context: State<Database>,
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();
}

View file

@ -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<S>: Deserialize<'de>")]
enum GraphQLBatchRequest<S = DefaultScalarValue>
@ -77,7 +71,7 @@ where
Batch(Vec<http::GraphQLRequest<S>>),
}
#[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<Database>>;
/// #
/// #[get("/graphql?<request..>")]
/// #[rocket::get("/graphql?<request..>")]
/// fn get_graphql_handler(
/// mut cookies: Cookies,
/// context: State<Database>,

View file

@ -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<Database>>;
@ -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());

View file

@ -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<S>: Deserialize<'de>")]
enum GraphQLBatchRequest<S = DefaultScalarValue>
@ -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,