Upgrade juniper_codegen dependencies (#231)

* Upgrade `juniper_codegen` to `syn-0.14`/`quote-0.6`

* Upgrade `juniper_codegen` to `regex-1.0`

* Fix comment typos in enum derive code

* Stop testing rust-1.21.0, replace with rust-1.23.0. rust-1.21.0 breaks with the newer dependencies
This commit is contained in:
Dirkjan Ochtman 2018-08-27 23:51:12 +02:00 committed by Christian Legnitto
parent d496220e10
commit 62d015cf86
7 changed files with 63 additions and 54 deletions

View file

@ -8,8 +8,8 @@ rust:
- nightly
# Prevent accidentally breaking older Rust versions
- 1.23.0
- 1.22.0
- 1.21.0
env:
global:

View file

@ -44,3 +44,7 @@
**Note:** while this is a breaking change, it is a necessary one to better align with the latest [GraphQL June 2018](https://facebook.github.io/graphql/June2018/#sec-Errors) specification, which defines the reserved *extensions* field for error details.
[#219](https://github.com/graphql-rust/juniper/pull/219)
* Due to newer dependencies, the oldest Rust version supported is now 1.22.0
[#231](https://github.com/graphql-rust/juniper/pull/231)

View file

@ -14,9 +14,10 @@ repository = "https://github.com/graphql-rust/juniper"
proc-macro = true
[dependencies]
syn = { version = "0.13.*", features = ["full", "extra-traits"] }
quote = "0.5.*"
regex = "0.2.10"
proc-macro2 = "0.4"
syn = { version = "0.14", features = ["full", "extra-traits"] }
quote = "0.6"
regex = "1"
lazy_static = "1.0.0"
[badges]

View file

@ -1,4 +1,5 @@
use quote::Tokens;
use proc_macro2::{Span, TokenStream};
use syn;
use syn::{Data, DeriveInput, Fields, Ident, Meta, NestedMeta, Variant};
@ -106,7 +107,7 @@ impl EnumVariantAttrs {
}
}
pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
pub fn impl_enum(ast: &syn::DeriveInput) -> TokenStream {
let variants = match ast.data {
Data::Enum(ref enum_data) => enum_data.variants.iter().collect::<Vec<_>>(),
_ => {
@ -124,10 +125,10 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
None => quote!{ let meta = meta; },
};
let mut values = Vec::<Tokens>::new();
let mut resolves = Vec::<Tokens>::new();
let mut from_inputs = Vec::<Tokens>::new();
let mut to_inputs = Vec::<Tokens>::new();
let mut values = TokenStream::new();
let mut resolves = TokenStream::new();
let mut from_inputs = TokenStream::new();
let mut to_inputs = TokenStream::new();
for variant in variants {
match variant.fields {
@ -146,7 +147,7 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
// Build value.
let name = var_attrs
.name
.unwrap_or(::util::to_upper_snake_case(variant.ident.as_ref()));
.unwrap_or(::util::to_upper_snake_case(&variant.ident.to_string()));
let descr = match var_attrs.description {
Some(s) => quote!{ Some(#s.to_string()) },
None => quote!{ None },
@ -155,33 +156,29 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
Some(s) => quote!{ Some(#s.to_string()) },
None => quote!{ None },
};
let value = quote!{
values.extend(quote!{
_juniper::meta::EnumValue{
name: #name.to_string(),
description: #descr,
deprecation_reason: #depr,
},
};
values.push(value);
});
// Build resolve match clause.
let resolve = quote!{
resolves.extend(quote!{
&#ident::#var_ident => _juniper::Value::String(#name.to_string()),
};
resolves.push(resolve);
});
// Buil from_input clause.
let from_input = quote!{
// Build from_input clause.
from_inputs.extend(quote!{
Some(#name) => Some(#ident::#var_ident),
};
from_inputs.push(from_input);
});
// Buil to_input clause.
let to_input = quote!{
// Build to_input clause.
to_inputs.extend(quote!{
&#ident::#var_ident =>
_juniper::InputValue::string(#name.to_string()),
};
to_inputs.push(to_input);
});
}
let body = quote! {
@ -233,7 +230,10 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
}
};
let dummy_const = Ident::from(format!("_IMPL_GRAPHQLENUM_FOR_{}", ident).as_str());
let dummy_const = Ident::new(
&format!("_IMPL_GRAPHQLENUM_FOR_{}", ident),
Span::call_site(),
);
// This ugly hack makes it possible to use the derive inside juniper itself.
// FIXME: Figure out a better way to do this!

View file

@ -1,6 +1,7 @@
use std::str::FromStr;
use quote::{ToTokens, Tokens};
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use syn::{self, Data, DeriveInput, Field, Fields, Ident, Meta, NestedMeta};
use util::*;
@ -112,7 +113,7 @@ impl ObjFieldAttrs {
}
}
pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
pub fn impl_input_object(ast: &syn::DeriveInput) -> TokenStream {
let fields = match ast.data {
Data::Struct(ref data) => match data.fields {
Fields::Named(ref named) => named.named.iter().collect::<Vec<_>>(),
@ -137,9 +138,9 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
None => quote!{ let meta = meta; },
};
let mut meta_fields = Vec::<Tokens>::new();
let mut from_inputs = Vec::<Tokens>::new();
let mut to_inputs = Vec::<Tokens>::new();
let mut meta_fields = TokenStream::new();
let mut from_inputs = TokenStream::new();
let mut to_inputs = TokenStream::new();
for field in fields {
let field_ty = &field.ty;
@ -154,7 +155,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
}
None => {
// Note: auto camel casing when no custom name specified.
::util::to_camel_case(field_ident.as_ref())
::util::to_camel_case(&field_ident.to_string())
}
};
let field_description = match field_attrs.description {
@ -169,7 +170,11 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
match field_attrs.default_expr {
Some(ref def) => match ::proc_macro::TokenStream::from_str(def) {
Ok(t) => match syn::parse::<syn::Expr>(t) {
Ok(e) => Some(e.into_tokens()),
Ok(e) => {
let mut tokens = TokenStream::new();
e.to_tokens(&mut tokens);
Some(tokens)
}
Err(_) => {
panic!("#graphql(default = ?) must be a valid Rust expression inside a string");
}
@ -195,14 +200,13 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
}
}
};
let meta_field = quote!{
meta_fields.extend(quote!{
{
#create_meta_field
#field_description
field
},
};
meta_fields.push(meta_field);
});
// Build from_input clause.
@ -215,7 +219,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
None => quote!{},
};
let from_input = quote!{
from_inputs.extend(quote!{
#field_ident: {
// TODO: investigate the unwraps here, they seem dangerous!
match obj.get(#name) {
@ -227,14 +231,12 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
},
}
},
};
from_inputs.push(from_input);
});
// Build to_input clause.
let to_input = quote!{
to_inputs.extend(quote!{
(#name, self.#field_ident.to_input_value()),
};
to_inputs.push(to_input);
});
}
let body = quote! {
@ -282,7 +284,10 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
}
};
let dummy_const = Ident::from(format!("_IMPL_GRAPHQLINPUTOBJECT_FOR_{}", ident).as_str());
let dummy_const = Ident::new(
&format!("_IMPL_GRAPHQLINPUTOBJECT_FOR_{}", ident),
Span::call_site(),
);
// This ugly hack makes it possible to use the derive inside juniper itself.
// FIXME: Figure out a better way to do this!

View file

@ -1,4 +1,4 @@
use quote::Tokens;
use proc_macro2::TokenStream;
use syn;
use syn::{Data, DeriveInput, Field, Fields};
@ -91,7 +91,7 @@ impl ObjFieldAttrs {
}
}
pub fn impl_object(ast: &syn::DeriveInput) -> Tokens {
pub fn impl_object(ast: &syn::DeriveInput) -> TokenStream {
let fields = match ast.data {
Data::Struct(ref data) => match data.fields {
Fields::Named(ref fields) => fields.named.iter().collect::<Vec<_>>(),
@ -114,8 +114,8 @@ pub fn impl_object(ast: &syn::DeriveInput) -> Tokens {
None => quote!{ builder },
};
let mut meta_fields = Vec::<Tokens>::new();
let mut resolvers = Vec::<Tokens>::new();
let mut meta_fields = TokenStream::new();
let mut resolvers = TokenStream::new();
for field in fields {
let field_ty = &field.ty;
@ -130,7 +130,7 @@ pub fn impl_object(ast: &syn::DeriveInput) -> Tokens {
}
None => {
// Note: auto camel casing when no custom name specified.
::util::to_camel_case(field_ident.as_ref())
::util::to_camel_case(&field_ident.to_string())
}
};
let build_description = match field_attrs.description {
@ -143,22 +143,20 @@ pub fn impl_object(ast: &syn::DeriveInput) -> Tokens {
None => quote!{ field },
};
let meta_field = quote!{
meta_fields.extend(quote!{
{
let field = registry.field::<#field_ty>(#name, &());
let field = #build_description;
let field = #build_deprecation;
field
},
};
meta_fields.push(meta_field);
});
// Build from_input clause.
let resolver = quote!{
resolvers.extend(quote!{
#name => executor.resolve_with_ctx(&(), &self.#field_ident),
};
resolvers.push(resolver);
});
}
let toks = quote! {

View file

@ -7,6 +7,7 @@
#![recursion_limit = "1024"]
extern crate proc_macro;
extern crate proc_macro2;
#[macro_use]
extern crate quote;
extern crate syn;