Skip to content

Commit a6bbe78

Browse files
committed
Merge branch 'master' into object-safe-graphqltype
# Conflicts: # juniper/CHANGELOG.md
2 parents af26c5e + ed6b257 commit a6bbe78

File tree

3 files changed

+96
-70
lines changed

3 files changed

+96
-70
lines changed

juniper/CHANGELOG.md

+80-66
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,118 @@
22

33
## Features
44

5-
- Added support for outputting the Rust schema in the [GraphQL Schema Language](https://graphql.org/learn/schema/#type-language). ([#676](https://github.com/graphql-rust/juniper/pull/676))
6-
- This is controlled by the `schema-language` feature and is on by default. It may be turned off if you do not need this functionality to reduce dependencies and speed up compile times.
5+
- Added async support. ([#2](https://github.com/graphql-rust/juniper/issues/2))
6+
- `execute()` is now async. Synchronous execution can still be used via `execute_sync()`.
7+
- Field resolvers may optionally be declared as `async` and return a future.
78

8-
- Normalization for the subscriptions_endpoint_url in the `graphiql_source`.
9-
(See [#628](https://github.com/graphql-rust/juniper/pull/628) for more details)
10-
11-
- Support raw identifiers in field and argument names. (`#[object]` macro)
9+
- Added *experimental* support for GraphQL subscriptions. ([#433](https://github.com/graphql-rust/juniper/pull/433))
1210

13-
- Most error types now implement `std::error::Error`:
11+
- Added support for generating the [GraphQL Schema Language](https://graphql.org/learn/schema/#type-language) representation of a schema using `RootNode::as_schema_language()`. ([#676](https://github.com/graphql-rust/juniper/pull/676))
12+
- This is controlled by the `schema-language` feature and is on by default. It may be turned off if you do not need this functionality to reduce dependencies and speed up compile times.
13+
- Note that this is for generating the GraphQL Schema Language representation from the Rust schema. For the opposite--generating a Rust schema from a GraphQL Schema Language file--see the [`juniper_from_schema`](https://github.com/davidpdrsn/juniper-from-schema) project.
14+
15+
- Most GraphQL spec violations are now caught at compile-time. ([#631](https://github.com/graphql-rust/juniper/pull/631))
16+
- The enhanced error messages now include the reason and a link to the spec.
17+
For example, if you try to declare a GraphQL object with no fields:
18+
```rust
19+
error: GraphQL object expects at least one field
20+
--> $DIR/impl_no_fields.rs:4:1
21+
|
22+
4 | impl Object {}
23+
| ^^^^^^^^^^^^^^
24+
|
25+
= note: https://spec.graphql.org/June2018/#sec-Objects
26+
```
27+
28+
- [Raw identifiers](https://doc.rust-lang.org/edition-guide/rust-2018/module-system/raw-identifiers.html) are now supported in field and argument names.
29+
30+
- Most error types now implement `std::error::Error`. ([#419](https://github.com/graphql-rust/juniper/pull/419))
1431
- `GraphQLError`
1532
- `LexerError`
1633
- `ParseError`
1734
- `RuleError`
1835

19-
- Support subscriptions (see
20-
[#433](https://github.com/graphql-rust/juniper/pull/433) for more details)
21-
22-
See [#419](https://github.com/graphql-rust/juniper/pull/419).
23-
24-
- `SchemaType` is now public
25-
- This is helpful when using `context.getSchema()` inside of your field resolvers
26-
27-
- Support subscriptions in GraphiQL
28-
29-
See [#569](https://github.com/graphql-rust/juniper/pull/569).
36+
## Fixes
3037

31-
- GraphQLUnion derive support ("#[derive(GraphqQLUnion)]")
32-
- implements GraphQLAsyncType
33-
34-
See [#618](https://github.com/graphql-rust/juniper/pull/618).
35-
36-
- Derive macro `GraphQLEnum` supports custom context (see [#621](https://github.com/graphql-rust/juniper/pull/621))
37-
38-
- Reworked `#[derive(GraphQLUnion)]` macro ([#666]):
39-
- Applicable to enums and structs.
40-
- Supports custom resolvers.
41-
- Supports generics.
42-
- Supports multiple `#[graphql]` attributes.
43-
- New `#[graphql_union]` macro ([#666]):
38+
- Massively improved the `#[graphql_union]` proc macro. ([#666](https://github.com/graphql-rust/juniper/pull/666)):
4439
- Applicable to traits.
4540
- Supports custom resolvers.
4641
- Supports generics.
4742
- Supports multiple `#[graphql_union]` attributes.
4843

49-
- Better error messages for all proc macros (see
50-
[#631](https://github.com/graphql-rust/juniper/pull/631)
44+
- Massively improved the `#[derive(GraphQLUnion)]` macro. ([#666](https://github.com/graphql-rust/juniper/pull/666)):
45+
- Applicable to enums and structs.
46+
- Supports custom resolvers.
47+
- Supports generics.
48+
- Supports multiple `#[graphql]` attributes.
49+
50+
- The `GraphQLEnum` derive now supports specifying a custom context. ([#621](https://github.com/graphql-rust/juniper/pull/621))
51+
- Example:
52+
```rust
53+
#[derive(juniper::GraphQLEnum)]
54+
#[graphql(context = CustomContext)]
55+
enum TestEnum {
56+
A,
57+
}
58+
```
59+
60+
- Added support for renaming arguments within a GraphQL object. ([#631](https://github.com/graphql-rust/juniper/pull/631))
61+
- Example:
62+
```rust
63+
#[graphql(arguments(argA(name = "test")))]
64+
```
65+
66+
- `SchemaType` is now public.
67+
- This is helpful when using `context.getSchema()` inside of your field resolvers.
5168

52-
- Improved lookahead visibility for aliased fields (see [#662](https://github.com/graphql-rust/juniper/pull/662))
69+
- Improved lookahead visibility for aliased fields. ([#662](https://github.com/graphql-rust/juniper/pull/662))
5370

54-
- Bumped bson crate's version to 1.0.0 (see [#678](https://github.com/graphql-rust/juniper/pull/678))
71+
- When enabled, the optional `bson` integration now requires `bson-1.0.0`. ([#678](https://github.com/graphql-rust/juniper/pull/678))
5572

5673
## Breaking Changes
5774

58-
- `GraphQLType` trait was split into 2 traits: ([#685])
59-
- object safe `GraphQLValue` trait containing resolving logic;
60-
- static `GraphQLType` trait containing GraphQL type information.
75+
- `GraphQLType` trait was split into 2 traits: ([#685](https://github.com/graphql-rust/juniper/pull/685))
76+
- object safe `GraphQLValue` trait containing resolving logic;
77+
- static `GraphQLType` trait containing GraphQL type information.
78+
79+
- `juniper::graphiql` has moved to `juniper::http::graphiql`.
80+
- `juniper::http::graphiql::graphiql_source()` now requires a second parameter for subscriptions.
81+
82+
- Renamed the `object` proc macro to `graphql_object`.
83+
- Removed the `graphql_object!` macro. Use the `#[graphql_object]` proc macro instead.
6184

62-
- `juniper::graphiql` has moved to `juniper::http::graphiql`
63-
- `juniper::http::graphiql::graphiql_source` now requies a second parameter for subscriptions
85+
- Renamed the `scalar` proc macro to `graphql_scalar`.
86+
- Removed the `graphql_scalar!` macro. Use the `#[graphql_scalar]` proc macro instead.
6487

65-
- remove old `graphql_object!` macro, rename `object` proc macro to `graphql_object`
88+
- Removed the deprecated `ScalarValue` custom derive. Use `GraphQLScalarValue` instead.
6689

67-
- remove old `graphql_scalar!` macro, rename `scalar` proc macro to `graphql_scalar`
90+
- Removed the `graphql_union!` macro. Use the `#[graphql_union]` proc macro or custom resolvers for the `#[derive(GraphQLUnion)]` instead.
6891

69-
- Remove deprecated `ScalarValue` custom derive (renamed to GraphQLScalarValue)
92+
- The `#[derive(GraphQLUnion)]` macro no longer generates `From` impls for enum variants. ([#666](https://github.com/graphql-rust/juniper/pull/666))
93+
- Consider using the [`derive_more`](https//docs.rs/derive_more) crate directly.
7094

71-
- `graphql_union!` macro removed, replaced by `#[graphql_union]` proc macro and custom resolvers for the `#[derive(GraphQLUnion)]` macro.
72-
- The `#[derive(GraphQLUnion)]` macro doesn't generate `From` impls for enum variants anymore. Consider using the [`derive_more`](https//docs.rs/derive_more) crate directly ([#666]).
95+
- The `ScalarRefValue` trait has been removed as it was not required.
7396

74-
- `ScalarRefValue` trait removed. Trait was not required.
97+
- Prefixing variables or fields with an underscore now matches Rust's behavior. ([#684](https://github.com/graphql-rust/juniper/pull/684))
7598

76-
- Changed return type of GraphQLType::resolve to `ExecutionResult`
77-
This was done to unify the return type of all resolver methods
78-
The previous `Value` return type was just an internal artifact of
99+
- The return type of `GraphQLType::resolve()` has been changed to `ExecutionResult`.
100+
- This was done to unify the return type of all resolver methods. The previous `Value` return type was just an internal artifact of
79101
error handling.
80102

81103
- Subscription-related:
82-
add subscription type to `RootNode`,
83-
add subscription endpoint to `playground_source()`
84-
85-
- Putting a scalar type into a string is not allowed anymore, e.g.
86-
`#[graphql(scalar = "DefaultScalarValue")]`. Only
87-
`#[derive(GraphQLInputObject)]` supported this syntax. The
88-
refactoring of GraphQLInputObject allowed to drop the support
89-
(see [#631](https://github.com/graphql-rust/juniper/pull/631)).
104+
- Add subscription type to `RootNode`.
105+
- Add subscription endpoint to `playground_source()`.
106+
- Add subscription endpoint to `graphiql_source()`.
90107

91-
- Support for renaming arguments within an GraphQL object
92-
`#[graphql(arguments(argA(name = "test")))]`
93-
(see [#631](https://github.com/graphql-rust/juniper/pull/631))
108+
- Specifying a scalar type via a string is no longer supported. ([#631](https://github.com/graphql-rust/juniper/pull/631))
109+
- For example, instead of `#[graphql(scalar = "DefaultScalarValue")]` use `#[graphql(scalar = DefaultScalarValue)]`. *Note the lack of quotes*.
94110

95111
- Integration tests:
96-
Rename `http::tests::HTTPIntegration` as `http::tests::HttpIntegration`
97-
and add support for `application/graphql` POST request.
98-
99-
- When using LookAheadMethods to access child selections, children are always found using their alias if it exists rather than their name (see [#662](https://github.com/graphql-rust/juniper/pull/662)). These methods are also deprecated in favour of the new `children` method.
112+
- Renamed `http::tests::HTTPIntegration` as `http::tests::HttpIntegration`.
113+
- Added support for `application/graphql` POST request.
100114

101-
[#666]: https://github.com/graphql-rust/juniper/pull/666
102-
[#685]: https://github.com/graphql-rust/juniper/pull/685
115+
- When using `LookAheadMethods` to access child selections, children are always found using their alias if it exists rather than their name. ([#662](https://github.com/graphql-rust/juniper/pull/662))
116+
- These methods are also deprecated in favor of the new `LookAheadMethods::children()` method.
103117

104118
# [[0.14.2] 2019-12-16](https://github.com/graphql-rust/juniper/releases/tag/juniper-0.14.2)
105119

juniper/src/util.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ use std::borrow::Cow;
77
pub fn to_camel_case(s: &'_ str) -> Cow<'_, str> {
88
let mut dest = Cow::Borrowed(s);
99

10-
for (i, part) in s.split('_').enumerate() {
10+
// handle '_' to be more friendly with the
11+
// _var convention for unused variables
12+
let s_iter = if s.starts_with('_') { &s[1..] } else { s }
13+
.split('_')
14+
.enumerate();
15+
16+
for (i, part) in s_iter {
1117
if i > 0 && part.len() == 1 {
1218
dest += Cow::Owned(part.to_uppercase());
1319
} else if i > 0 && part.len() > 1 {
@@ -32,7 +38,7 @@ pub fn to_camel_case(s: &'_ str) -> Cow<'_, str> {
3238
#[test]
3339
fn test_to_camel_case() {
3440
assert_eq!(&to_camel_case("test")[..], "test");
35-
assert_eq!(&to_camel_case("_test")[..], "Test");
41+
assert_eq!(&to_camel_case("_test")[..], "test");
3642
assert_eq!(&to_camel_case("first_second")[..], "firstSecond");
3743
assert_eq!(&to_camel_case("first_")[..], "first");
3844
assert_eq!(&to_camel_case("a_b_c")[..], "aBC");

juniper_codegen/src/util/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,13 @@ fn get_doc_attr(attrs: &[Attribute]) -> Option<Vec<MetaNameValue>> {
233233
pub fn to_camel_case(s: &str) -> String {
234234
let mut dest = String::new();
235235

236-
for (i, part) in s.split('_').enumerate() {
236+
// handle '_' to be more friendly with the
237+
// _var convention for unused variables
238+
let s_iter = if s.starts_with('_') { &s[1..] } else { s }
239+
.split('_')
240+
.enumerate();
241+
242+
for (i, part) in s_iter {
237243
if i > 0 && part.len() == 1 {
238244
dest.push_str(&part.to_uppercase());
239245
} else if i > 0 && part.len() > 1 {
@@ -1906,7 +1912,7 @@ mod test {
19061912
#[test]
19071913
fn test_to_camel_case() {
19081914
assert_eq!(&to_camel_case("test")[..], "test");
1909-
assert_eq!(&to_camel_case("_test")[..], "Test");
1915+
assert_eq!(&to_camel_case("_test")[..], "test");
19101916
assert_eq!(&to_camel_case("first_second")[..], "firstSecond");
19111917
assert_eq!(&to_camel_case("first_")[..], "first");
19121918
assert_eq!(&to_camel_case("a_b_c")[..], "aBC");

0 commit comments

Comments
 (0)