Skip to content

Commit

Permalink
Formatting...
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed May 12, 2019
1 parent 873858e commit d7a45f6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 48 deletions.
13 changes: 3 additions & 10 deletions juniper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,14 @@ extern crate uuid;
// This allows users to just depend on juniper and get the derive
// functionality automatically.
pub use juniper_codegen::{
GraphQLEnum,
GraphQLInputObject,
GraphQLObject,
GraphQLScalarValue,
ScalarValue,
impl_object,
impl_object, GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, ScalarValue,
};
// Internal macros are not exported,
// Internal macros are not exported,
// but declared at the root to make them easier to use.
#[allow(unused_imports)]
use juniper_codegen::{
impl_object_internal, GraphQLEnumInternal, GraphQLInputObjectInternal,
GraphQLScalarValueInternal,
GraphQLEnumInternal,
GraphQLInputObjectInternal,
impl_object_internal,
};

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion juniper/src/macros/object.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
## DEPRECATION WARNING
The `graphql_object!` macro is deprecated and will be removed soon.
The `graphql_object!` macro is deprecated and will be removed soon.
Use the new[impl_object](https://docs.rs/juniper/latest/juniper/macro.impl_object.html) macro instead.
Expose GraphQL objects
Expand Down
30 changes: 13 additions & 17 deletions juniper/src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,13 @@ where
fn fields(&self, include_deprecated: bool) -> Option<Vec<&Field<S>>> {
match *self {
TypeType::Concrete(&MetaType::Interface(InterfaceMeta { ref fields, .. }))
| TypeType::Concrete(&MetaType::Object(ObjectMeta { ref fields, .. })) => {
Some(
fields
.iter()
.filter(|f| include_deprecated || !f.deprecation_status.is_deprecated())
.filter(|f| !f.name.starts_with("__"))
.collect(),
)
}
| TypeType::Concrete(&MetaType::Object(ObjectMeta { ref fields, .. })) => Some(
fields
.iter()
.filter(|f| include_deprecated || !f.deprecation_status.is_deprecated())
.filter(|f| !f.name.starts_with("__"))
.collect(),
),
_ => None,
}
}
Expand Down Expand Up @@ -233,14 +231,12 @@ where
#[graphql(arguments(include_deprecated(default = false)))]
fn enum_values(&self, include_deprecated: bool) -> Option<Vec<&EnumValue>> {
match *self {
TypeType::Concrete(&MetaType::Enum(EnumMeta { ref values, .. })) => {
Some(
values
.iter()
.filter(|f| include_deprecated || !f.deprecation_status.is_deprecated())
.collect(),
)
}
TypeType::Concrete(&MetaType::Enum(EnumMeta { ref values, .. })) => Some(
values
.iter()
.filter(|f| include_deprecated || !f.deprecation_status.is_deprecated())
.collect(),
),
_ => None,
}
}
Expand Down
13 changes: 8 additions & 5 deletions juniper_codegen/src/impl_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool
// Check for executor arguments.
if util::type_is_identifier_ref(&captured.ty, "Executor") {
resolve_parts.push(quote!(let #arg_ident = executor;));
}
}
// Make sure executor is specified as a reference.
else if util::type_is_identifier(&captured.ty, "Executor") {
panic!("Invalid executor argument: to access the Executor, you need to specify the type as a reference.\nDid you mean &Executor?");
Expand All @@ -160,16 +160,19 @@ pub fn build_impl_object(args: TokenStream, body: TokenStream, is_internal: bool
.unwrap_or(false)
{
resolve_parts.push(quote!( let #arg_ident = executor.context(); ));
}
}
// Make sure the user does not specify the Context
// without a reference. (&Context)
else if context_type.clone().map(|ctx| ctx == &captured.ty).unwrap_or(false) {
else if context_type
.clone()
.map(|ctx| ctx == &captured.ty)
.unwrap_or(false)
{
panic!(
"Invalid context argument: to access the context, you need to specify the type as a reference.\nDid you mean &{}?",
quote!(captured.ty),
);
}
else {
} else {
let ty = &captured.ty;
// TODO: respect graphql attribute overwrite.
let final_name = util::to_camel_case(&arg_name);
Expand Down
20 changes: 10 additions & 10 deletions juniper_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ pub fn derive_scalar_value_internal(input: TokenStream) -> TokenStream {
The `impl_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
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
`impl_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 `impl_object`.
More advanced use cases are introduced step by step.
```
Expand All @@ -105,17 +105,17 @@ impl Query {
// This defines a simple, static field which does not require any context.
// You can return any value that implements the `GraphQLType` trait.
// You can return any value that implements the `GraphQLType` trait.
// This trait is implemented for:
// - 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.
//
// An important note regarding naming:
//
// An important note regarding naming:
// By default, field names will be converted to camel case.
// For your GraphQL queries, the field will be available as `apiVersion`.
//
//
// You can also manually customize the field name if required. (See below)
fn api_version() -> &'static str {
"0.1"
Expand Down Expand Up @@ -169,7 +169,7 @@ You can specify a context that will be available across
all your resolvers during query execution.
The Context can be injected into your resolvers by just
specifying an argument with the same type as the context
specifying an argument with the same type as the context
(but as a reference).
```
Expand Down Expand Up @@ -198,11 +198,11 @@ impl Query {
context.db.user(id)
}
// You can also gain access to the executor, which
// You can also gain access to the executor, which
// allows you to do look aheads.
fn with_executor(executor: &Executor) -> bool {
let info = executor.look_ahead();
// ...
// ...
true
}
}
Expand Down
10 changes: 5 additions & 5 deletions juniper_codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub struct GraphQLTypeDefiniton {
// This flag signifies if the type generics need to be
// included manually.
pub include_type_generics: bool,
// This flag indicates if the generated code should always be
// This flag indicates if the generated code should always be
// generic over the ScalarValue.
// If false, the scalar is only generic if a generic parameter
// is specified manually.
Expand Down Expand Up @@ -744,7 +744,7 @@ impl GraphQLTypeDefiniton {
// A custom scalar type was specified.
// Therefore, we always insert a where clause that marks the scalar as
// compatible with ScalarValueRef.
// This is done to prevent the user from having to specify this
// This is done to prevent the user from having to specify this
// manually.
let where_clause = generics.where_clause.get_or_insert(parse_quote!(where));
where_clause.predicates.push(
Expand All @@ -764,9 +764,9 @@ impl GraphQLTypeDefiniton {
// Insert a where clause that marks the scalar as
// compatible with ScalarValueRef.
// Same as in branch above.
where_clause.predicates.push(
parse_quote!(for<'__b> &'__b __S: #juniper_crate_name::ScalarRefValue<'__b>),
);
where_clause
.predicates
.push(parse_quote!(for<'__b> &'__b __S: #juniper_crate_name::ScalarRefValue<'__b>));
}

let type_generics_tokens = if self.include_type_generics {
Expand Down

0 comments on commit d7a45f6

Please sign in to comment.