Commit graph

242 commits

Author SHA1 Message Date
Chris
6dd6abbadc
Fix custom ScalarValue usage for unions (#681)
- make GraphQLUnion trait generic over ScalarValue
- generate generic over ScalarValue impls of GraphQLUnion trait
- add codegen tests with a custom ScalarValue for union macros
2020-06-14 14:12:53 +03:00
tyranron
5b7706e839
Fix codegen failure tests for the latest nightly Rust 2020-06-10 11:36:36 +03:00
Kai Ren
ddc1488195
Codegen reimplementation for GraphQL unions (#666)
- reimplement #[derive(GraphQLUnion)] macro to support:
    - both structs and enums
    - generics in type definition
    - multiple #[graphql] attributes
    - external resolver functions
- remove From trait impls generation for enum variants

- reimplement #[graphql_union] macro to support:
    - traits
    - generics in trait definition
    - multiple attributes
    - external resolver functions
    - GraphQLType implemetation for a raw trait object
    - GraphQLTypeAsync implemetation (#549)

- add marker::GraphQLUnion trait

- rewrite "2.5 Unions" section in Book (Juniper user documentation)

- rewrite `codegen` and `codegen_fail` integration tests for GraphQL unions

Additionally:
- re-export `futures` crate in `juniper` for convenient reuse in the generated code without requiring library user to provide `futures` crate by himself (#663)
- use unit type () as default context for EmptyMutation and EmptySubscriptions
- relax Sized trait bound on some GraphQLType and GraphQLTypeAsync definitions, implementations and usages
2020-06-04 11:19:01 +03:00
Jonas Meurer
558eae91df
Ensure Specification(June 2018) Compliance (#631)
* Implemented most test cases from the specification

* Unified error handling for all generators

- Removed proc-macro-error -> not required -> use syn::Error
- Everything below lib.rs uses proc_macro2::TokenStream
  instead of proc_macro::TokenStream
- Replaced error handling in attribute parsers

* WIP better error messages for *all* macros

* Refactored GraphQLInputObject and minor tweaks

- removed support for Scalar within a string ("DefaultScalarValue")
- removed unraw function and replaced it with the built-in one
- added error messages and return types for all functions within utils
- added more constraints to fulfill the GraphQL spec

* Fixed test-cases which are not compliant with the specification

* Removed unused function

* Added constrains, updated error messages, added marker

* Added argument rename within impl_graphql and fixed `__` tests

* Formatted and cleanup

* Added GraphQLTypeAsync for input object

* Moved codegen tests to separate module

Nightly and stable produce different outputs, thus only test nightly.

* Added IsInputType/IsOutputType traits for type checking

Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-05-01 16:24:01 -10:00
André Isaksson Kraft
2ba9f71b0c
Make graphql_scalar a proc macro (#610)
Fixes #571

Signed-off-by: andrisak <andrisak@gmail.com>

* Replaced the old macro with the new proc macro.
Updated documentation.

Signed-off-by: andrisak <andrisak@gmail.com>

Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-04-20 10:15:09 -10:00
Jonas Meurer
fe99e1cc70
Allow specifying scalar and context for GraphQLEnum (#621)
* Updated implementation of derive enum

- allows context specification
- allows scalar specification
- shares code with derive object

* Added this feature to CHANGELOG

* Added matrix with supported macro attributes for enums

* Added case which checks for custom context

* GraphQLUnion now can use a different context per variant

* Moved context switch test for union into right folder

* Sync resolve expression has the same form as the other impls

* Disabled custom scalar on GraphQLEnum

* Fixed CHANGELOG

* Fixed support matrix of GraphQLEnum in the book

- scalar not supported!
- skip not supported!

* Added test case for "noasync" derive attribute

* Disallowed generics and lifetimes on GraphQLEnum

* Added error message for duplicate naming

* Added error message for empty variant
2020-04-17 19:09:04 -10:00
Jonas Meurer
a05f4e55c4
Derive macro for tagged enums (GraphQLUnion) (#618)
* Implemented device macro for GraphQLUnion's

* Updated PR link in CHNAGELOG

* Disabled documentation on enumeration fields

* Disabled skip on fields

* Changed implementation for std::convert::Into since skip is not possible

* Added documentation for GraphQLUnion

* Added tests for GraphQLUnion

* Fixed typos in error messages (as suggested by review)

* Fixed failing documentation example

* Utilized `resolver_code` in `util::GraphQLTypeDefinitionField`.

Simplifies code and provides the idea of using
`util::GraphQLTypeDefinitionField` for different types than objects.

* Removed wrong statement about skip annotation in docs.

Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-04-14 21:58:45 -10:00
Christian Legnitto
adc8d7be2d
Fix some clippy warnings (#595) 2020-03-31 08:34:50 -07:00
Gero Posmyk-Leinemann
5f777e8a6d
Clippy cleanup (#579) 2020-03-20 09:11:06 -07:00
nWacky
eb941e509a
Add subscription support (#433)
Co-authored-by: tyranron <tyranron@gmail.com>
Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
2020-03-18 20:31:36 -07:00
Christian Legnitto
27e00419b0
More clippy and warnings. (#568)
Also, remove `dbg!()`
2020-03-14 08:55:06 -07:00
Christian Legnitto
2796d8df9a
More clippy fixes (#565) 2020-03-13 23:02:43 -07:00
Christian Legnitto
3b5cf4ad64
Fix some clippy lints (#564)
* Fix some clippy lints
2020-03-13 22:03:36 -07:00
Christian Legnitto
00b111a1ff
Remove async feature gate (#554)
This still has the async / non-async split. Future diffs will get
rid of `GraphQLTypeAsync` and move everything into `GraphQLType`.
2020-03-08 23:20:11 -07:00
Christian Legnitto
b63a44e0f8
Add futures dependency (#541)
Fixes https://github.com/graphql-rust/juniper/issues/534.

I am not sure if the best way is to have folks bring their own futures for the
derives / macros or to pull it in as a dep explicitly like I have done here.

Because people are filing issues, we will do it this way and see what other issues arise.
2020-02-20 21:53:39 -07:00
Christian Legnitto
7ee67ed6e8
Convert graphql_object to central util parsing (#526) 2020-02-12 23:46:59 -07:00
tyranron
c51c675306
Use caret requirement for specifying 'futures' crate version 2020-02-04 09:57:47 +01:00
Christian Legnitto
c42c71b02d Update to latest tokio 2020-01-22 07:56:03 -08:00
Christian Legnitto
80ef24fc12 Break dep cycle again 2020-01-21 07:53:36 -08:00
Christian Legnitto
98caeefbc0 Break dep cycle with features 2020-01-21 00:02:26 -08:00
Christian Legnitto
c6becfe234 Fix juniper_codegen tests under async 2020-01-20 23:38:44 -08:00
Christian Legnitto
7681f42933 Merge remote-tracking branch 'upstream/master' into async-await 2020-01-20 22:47:05 -08:00
Christian Legnitto
73dc5cd5b8 Release juniper 0.14.2 2020-01-18 17:14:35 -08:00
Christian Legnitto
a5ccf8c2a1 Release juniper_codegen 0.14.2 2020-01-18 17:14:35 -08:00
danieleades
6fa6c20fa7 address clippy::all lints (#486) 2019-12-17 20:37:46 -08:00
Christian Legnitto
eddf948dad Release juniper 0.14.2 2019-12-16 21:53:51 -08:00
Christian Legnitto
e4cfc4b09f Release juniper_codegen 0.14.2 2019-12-16 21:52:50 -08:00
Christoph Herzog
ce3cf45ca9 Rename object proc macro to graphql_object 2019-11-16 02:57:48 +01:00
Christoph Herzog
358071bfa4 Remove deprecated ScalarValue derive
This was renamed to GraphQLScalarValue and has been deprecated for a
while
2019-11-16 02:33:20 +01:00
Christoph Herzog
9ce3d04007 Improve union proc macro
* Rename to graphql_union
* Implement full-featured parsing and code generation
2019-11-16 02:33:18 +01:00
Christoph Herzog
5d270b7dea Formatting 2019-11-15 22:18:38 +01:00
Christoph Herzog
50605ee73e Duplicate juniper_rocket for async
This is required because rocket only supports futures on a git branch.
2019-11-15 21:52:22 +01:00
Christoph Herzog
f6c0bc7b02 Fix tests. 2019-11-15 21:44:08 +01:00
Christoph Herzog
b634ad39eb Various async feature fixes for the type system 2019-11-15 21:23:59 +01:00
Christoph Herzog
ad16093b88 Refactor GraphQLType::resolve to return Result<>
This unifies the output type of all resolvers.

Required for future step of making the output a associated type.
2019-11-14 09:51:32 +01:00
Christoph Herzog
36c71d7162 chore: Remove ScalarRefValue trait
The trait was introduced while introducing generic scalars, but is not
actually required or useful. It's functionality is fully covered by
methods on the `ScalarValue` trait.

It also forced a lof of for<'a> ScalarRefValue bounds all over the code,
complicating signatures a lot.

It is completely removed now.
2019-11-14 01:21:41 +01:00
nWacky
eb85fefc36 Get back panic in macro [skip ci] 2019-11-13 14:26:25 +00:00
nWacky
2144ad0d7d Remove async-trait [skip ci] 2019-11-13 14:26:25 +00:00
nWacky
cf99495368 Replace all futures::BoxFuture with juniper::BoxFuture 2019-11-12 12:04:09 +00:00
nWacky
237e69c036 Rebase async_await onto master (#454)
* feat: Raw identifier support in object macro

This commit implements raw identifier (`r#name`) support
for field names (methods) and arguments in the `object` proc macro.

Eg:

```rust
impl T {
  fn r#type(r#trait: String) -> bool {}
}
```

* Rebase onto master

* Fix merge [skip ci]
2019-11-08 09:46:48 +00:00
David Pedersen
1148c75a1d feat: Raw identifier support in object macro
This commit implements raw identifier (`r#name`) support
for field names (methods) and arguments in the `object` proc macro.

Eg:

```rust
impl T {
  fn r#type(r#trait: String) -> bool {}
}
```
2019-11-06 23:08:25 +00:00
nWacky
778606c050
Fix bad merge [skip ci] 2019-11-06 12:01:50 +03:00
nWacky
99c0d26887
Comment out attr_arg_descr and attr_arg_descr_collapse tests 2019-11-05 12:06:08 +03:00
nWacky
dbcaf30ec3
Rebase onto master 2019-11-05 11:20:06 +03:00
nWacky
e3c12e31fc
Format 2019-11-05 11:14:53 +03:00
nWacky
00dd1dc391
Resolve better error message with field/type name todo, update other panics with query name 2019-11-05 11:14:20 +03:00
nWacky
52c3e281f3
Refactor GraphQLTypeAsync to use async-trait 2019-11-05 11:14:20 +03:00
Christian Legnitto
191468bf04
Release juniper 0.14.1 2019-11-05 11:14:16 +03:00
Christian Legnitto
7b18bd245d
Release juniper_codegen 0.14.1 2019-11-05 11:14:15 +03:00
Christian Legnitto
0929bad163 Fix non-async resolvers with returns in the async case 2019-11-03 22:14:44 -08:00
Christian Legnitto
560a172587 Make resolvers with returns work again
Note that this only fixes the non-async case
2019-11-03 22:07:40 -08:00
nWacky
321c3af38d Use name_of_type in macro [skip ci] 2019-11-01 12:59:16 +00:00
nWacky
245c351a73 Revert juniper::object name detection back to master [skip ci] 2019-11-01 12:59:16 +00:00
Christoph Herzog
ee9a82a817 Refacto graphql_union! macro to proc macro 2019-10-28 21:51:29 +01:00
Christian Legnitto
c434bddc91 Release juniper 0.14.1 2019-10-24 15:57:16 -07:00
Christian Legnitto
252f7b4353 Release juniper_codegen 0.14.1 2019-10-24 15:56:44 -07:00
tyranron
e2903cf0f7
Fix type inferring for trivial resolver code
Additionally:
- fix inconsistencies after merge with master
2019-10-10 14:50:10 +02:00
tyranron
635bf1ff34
Merge branch 'async-await' into remove-async-closure-feature
# Conflicts:
#	examples/warp_async/src/main.rs
#	integration_tests/async_await/src/main.rs
#	juniper/src/lib.rs
#	juniper_benchmarks/src/lib.rs
#	juniper_rocket/src/lib.rs
#	juniper_warp/src/lib.rs
2019-10-10 13:20:00 +02:00
Christoph Herzog
56a4f2558a WIP async/await implementation 2019-10-09 22:22:13 -07:00
tyranron
5d3ed9ac72
Remove async_closure feature usage 2019-10-10 00:07:10 +02:00
Christian Legnitto
dbbceae643 Release juniper 0.14.0 2019-09-29 19:04:31 -07:00
Christian Legnitto
c4d7661b3b Release juniper_codegen 0.14.0 2019-09-29 19:03:54 -07:00
Blaž Hrastnik
dcbb74155d juniper_codegen: Drop regex & lazy_static dependencies (#424)
* Replace regex & lazy_static with a simple check.
2019-09-07 21:19:37 -07:00
Christoph Herzog
a14f0ddebd WIP async/await implementation 2019-08-21 15:48:31 +02:00
theduke
a3caf126b0 derive: Upgrade syn/quote/proc_macro dependencies to 1.0 (#413) 2019-08-18 09:12:25 -07:00
Christian Legnitto
48c26a26b3 Release juniper 0.13.1 2019-07-29 08:08:05 -07:00
Christian Legnitto
6b32e90899 Release juniper_codegen 0.13.2 2019-07-29 08:07:32 -07:00
Christian Legnitto
644d6042ae Release juniper_codegen 0.13.1 2019-07-29 08:06:22 -07:00
Christoph Herzog
049ba0c9dc (codegen) Respect mut modifier on arguments in object proc macro
This commit forwards `mut` declaration of arguments in a #[juniper::object] macro invocation
to the generated code.

Closes #399
2019-07-24 02:37:31 +02:00
Christian Legnitto
54f98f46db Release juniper 0.13.0 2019-07-19 14:01:21 -07:00
Christian Legnitto
efe22b7ffd Release juniper_codegen 0.13.0 2019-07-19 14:01:21 -07:00
Christian Legnitto
7bedea05ed
Clean up test warnings (#392) 2019-07-15 21:47:16 -07:00
Peter Majchrak
28ca8fe006 Cleanup after #385 (#386) 2019-06-27 15:32:36 -07:00
Peter Majchrak
3373935046 Add support for "dyn" trait object syntax (#385)
* Use "dyn" for TraitObjects

* Cleanup after adding "dyn" support

* Add entry to CHANGELOG.md
2019-06-27 08:44:30 -07:00
Christoph Herzog
97e1005178 Clean up ScalarValue transparent derive argument handling and documentation. 2019-06-25 18:55:45 +02:00
theduke
7e0e7beaa7 Allow scalars without #[repr(transparent)] 2019-06-25 18:55:45 +02:00
Christoph Herzog
3396074274 (codegen) Implement newtype derive for scalars.
This commit implements a newtype style custom derive
for scalars via `#[derive(GraphQLScalarValue)]`, which now
supports both deriving a base enum scalar type and newtypes.

For newtypes, the `#[graphql(transparent)]` attribute is
required.

This commit:
* implements the derive
* adds integration tests
* updates the book
2019-06-25 18:55:45 +02:00
Kai Ren
49f723a3dd Optimize .unwrap_or() and .expect() usages (#374) 2019-06-18 23:12:13 -04:00
Christian Legnitto
9c9e3da72d Release juniper 0.12.0 2019-05-16 19:03:21 -07:00
Christian Legnitto
8a047e8702 Release juniper_codegen 0.12.0 2019-05-16 19:01:52 -07:00
Christoph Herzog
166c6d00c5 (tooling) Update release config to bump doc_root. 2019-05-15 11:20:51 +02:00
Yusuke Sasaki
0ae2475bb8 add #[doc(html_root_url)] to all published crates 2019-05-15 11:20:51 +02:00
Christoph Herzog
29025e6cae
Rename impl_object to object. 2019-05-13 21:15:14 +02:00
Christoph Herzog
520cac29a0
(codegen) Allow #[deprecated] on field in impl_object 2019-05-13 12:37:22 +02:00
Christoph Herzog
552b4d01ac
(codegen) Fix test dependency version to be exact.
Needed for releasing automation.
2019-05-12 21:03:52 +02:00
Christoph Herzog
de12e0eba5
Formatting... 2019-05-12 10:49:46 +02:00
Christoph Herzog
67b28c5e89
(codegen) Remove (extern crate self) declaration 2019-05-12 10:36:30 +02:00
Christoph Herzog
758f3f7d40
(codegen) Implement impl_object macro + unify code with object derive
This commit implements a new proc macro `impl_object` that replaces
the old graphql_object! macro.

The code shares a lot of similarities with the GraphQLObject
custom derive, so the code was unified to handle both
more generically.

Also, doc comment processing was standardized and improved.
2019-05-12 10:35:03 +02:00
Christian Legnitto
794568e463
Add release automation (#346)
See `RELEASING.md` for directions
2019-05-11 23:51:28 -07:00
Christoph Herzog
2e011014ea
Formatting... 2019-05-02 18:44:56 +02:00
Christoph Herzog
5a4230e0d0
Remove macro_use + extern crate statements (2018 edition) 2019-05-02 18:44:56 +02:00
Christoph Herzog
54a1b64a79
Refactor code to 2018 edition with 'cargo fix --edition' 2019-05-02 18:44:56 +02:00
Christoph Herzog
4f72a61346 Formatting... 2019-03-23 14:44:48 +01:00
Christoph Herzog
8c5b86e1c6 Allow specifying the Context type in #[derive(GraphQLObject)]
This commit extends the GraphQLObject derive to allow specifying a
custom context type.
2019-03-08 11:47:13 +01:00
Christian Legnitto
52fb87aaf4 Run cargo fmt on latest stable 2019-01-28 20:28:03 +01:00
Christian Legnitto
9b021b2fe7 Keep ScalarValue but mark it as deprecated 2018-12-19 20:17:17 +01:00
Christian Legnitto
88c17db8c3 Rename ScalarValue derive
Fixes https://github.com/graphql-rust/juniper/issues/299.
2018-12-19 20:17:17 +01:00
theduke
d015a3ca66 (ci) Check formatting with cargo fmt (#302)
This adds a new extra CI job for checking the formatting
with cargo fmt --check.
2018-12-19 10:27:49 -08:00
Christoph Herzog
2f5e3ab29b 0.11.1 Release
* Changelog
* Cargo.toml version bumps
2018-12-19 03:53:33 +01:00
Christoph Herzog
8dd2eafef8 Add *Internal custom derive variants for juniper crate
Currently, custom derives inside the main juniper crate are supported by
an ugly hack using the __juniper_use_everything macro.

This commit adds new custom derive variants that are for
main juniper crate internal use only (GraphQL{Enum,InputObject}Internal.

All custom derives inside the juniper crate are refactored to use the
new '*Internal' derives.

This allows us to
* remove the use_everything macro,
* simplify the generated code for custom derives
* support the Rust 2018 edition
2018-12-19 03:53:33 +01:00
Christian Legnitto
56954b15dc Fix publishing juniper atfter juniper_codegen 2018-12-17 14:49:27 -08:00
Christian Legnitto
8b2ec00a92 Bump juniper_codegen version to 0.11.1-pre 2018-12-17 14:43:57 -08:00
Christian Legnitto
2502c1b6da Set up some release automation.
Partially fixes https://github.com/graphql-rust/juniper/issues/248.

* Install `cargo-release`. (currently need a patched one with https://github.com/sunng87/cargo-release/pull/74)
* Run `cargo make release-dry-run` to do a dry run of a release
* Run `cargo make release` to do a minor versioned release of every crate
* Run `cargo make release-patch` to do a patch release of every crate

To only release one crate:
* Change directories into the desired crate
* Point `cargo-make` to the workspace-level Makefile when running a command. For example, `cargo make --makefile ../Makefile.toml release-dry-run`.

From the workspace root, run `cargo
2018-12-17 13:45:56 -08:00
Christian Legnitto
73175d7a10 Bump version 2018-12-17 13:11:21 -08:00
Kevin Stenerson
0f2a654471 Infer graphql "deprecation" from #[deprecated(note = "...")] in derive (and macros) (#269)
* Update object/iface macro with doc/deprecated attrs for fields

* Use the note from `#[deprecated]` by default in derived GraphQLType

* Update to support multiline raw-docstring format

* Support bare deprecated attribute

* Update arguments to support #[doc] for parity with previous ` as ` syntax
2018-10-27 21:28:48 -06:00
Georg Semmler
2e5df9f8a4 Introduce an abstraction for scalar values (#251)
Introduce an abstraction for scalar values

Before this change,  possible scalar values were hard coded to be representable
by one of the following types: `i32`, `f64`, `String` or `bool`. This
restricts the types of custom scalar values that can be defined. For
example, it was not possible to define a scalar value that represents an
`i64` without mapping it to a string (which would be inefficient).

One solution to fix the example above would simply be to change the
internal representation to allow it to represent an `i64`, but this would
only fix the problem for one type (until someone wants to support
`i128` for example). Also this would make juniper not follow the
GraphQL standard closely.

This commit takes another approach, by making the exact "internal"
representation of scalar values swappable (in such a way that a downstream crate could provide its own representation tailored to their needs). This allows juniper to provide a default type that only
contains the types described in the standard whereas other crates could define custom scalars for their needs.

To accomplish this we need to change several things in the current implementation:

* Add some traits that abstract the behavior of such a scalar value representation
* Change `Value` and `InputValue` to have a scalar variant (with a
  generic type) instead of hard coded variants for the standard
  types. This implies adding a generic parameter to both enums that
  needs to be added in the whole crate.
* Change the parser to allow deciding between different types of
  scalar values. The problem is basically that the original parser
  implementation had no way to know whether a parsed integer number is
  a `i32` or a `i64` (for example). To fix this we added some knowledge
  of the existing schema to the parser.
* Fix some macros and derives to follow the new behavior.

This commit also contains an unrelated change about the way `juniper_codegen`
resolves items from `juniper`. The `_internal` flag is removed and
the resolution is replaced by a macro.

The scalar parsing strategy is as follows:

* Pass optional type information all the way down in the parser. If a
  field/type/… does note exist, just do not pass down the type
  information.
* The lexer now distinguishes between several fundamental scalar types (`String`, `Float`, `Int`). It does not try to actually parse those values, instead it just annotates them that this is a floating point number, an integer number, or a string value, etc.
* If type information exists while parsing a scalar value, try the following:
    1. Try parsing the value using that type information.
    2. If that fails try parsing the value using the inferred type information from the lexer.
* If no type information exists, try parsing the scalar value using the inferred type from the lexer,

All macros support the introduced scalar value abstraction. It is now possible to specify if a certain implementation should be based on a specific scalar value representation or be generic about the exact representation. All macros now default to the `DefaultScalarValue` type provided by
`juniper` if no scalar value representation is specified. This is done with usability and backwards compatibility in mind.

Finally, we allow specifying the scalar value representations via an attribute
(`#[graphql(scalar = "Type")]`). A default generic implementation
is provided.
2018-10-22 21:40:14 -06:00
Christian Legnitto
bd455c9130
Remove Appveyor (#264)
Now that we have azure pipelines set up, there is no need
to use appveyor.

Part of https://github.com/graphql-rust/juniper/issues/259
2018-10-08 21:15:09 -07:00
Christian Legnitto
9c1ce1fb7a
0.10.0 release (#236)
* Bump` juniper`, `juniper_codegen`, and `juniper_tests` versions.

* Bump integration crate requirements to include 0.10.0. `juniper_iron` gets a semver breaking version as it has a breaking change but `juniper_iron` does not.

* Move `juniper_rocket` changelog into one file. This aligns with `juniper_iron` and will be easier
to automate in the future.

* Let `juniper_warp` and `juniper_hyper` use `0.9.x` versions of Juniper. They don't rely on anything in 0.10.0 so don't require it.
2018-09-13 09:13:31 -07:00
Christian Legnitto
08c31357af
Add support for lifetime annotations when using derives (#226)
Fixes https://github.com/graphql-rust/juniper/issues/225
2018-08-27 15:25:15 -07:00
Christian Legnitto
22c955599a
Add support for skipping fields in GraphQL objects (#224)
Fields can now be skipped with the `#[graphql(skip)]` annotation. Note this
doesn't really make sense for GraphQLInputObjects so this isn't supported there.

Fixes https://github.com/graphql-rust/juniper/issues/220.
2018-08-27 15:09:42 -07:00
Dirkjan Ochtman
62d015cf86 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
2018-08-27 14:51:12 -07:00
Christoph Herzog
56f71e934b Format code 2018-07-19 16:18:49 +02:00
Christian Legnitto
4be687f73e Add more unit tests for doc comments as descriptions 2018-06-20 20:45:34 +02:00
Christian Legnitto
1fd5c10327 Add support for using doc comments as descriptions
Fixes https://github.com/graphql-rust/juniper/issues/194.
2018-06-20 20:45:34 +02:00
Christian Legnitto
f0cbc97dc7
Do not assign field to itself if no description specified when deriving input object (#187)
If a field has a description, we properly generate a meta field definition like:

```rust
{
  let field = registry.field::<String>("id", &());
  let field = field.description("Whatever");
  field
}
```

If a field does not have a description, we were generating something like:

```rust
{
  let field = registry.field::<String>("id", &());
  let field = field; // <--- Note not needed
  field
}
```

This of course works (and was likely optimized out by the compiler), but bloats
generated code for no benefit.

This change merely makes the second case generate:

```rust
{
  let field = registry.field::<String>("id", &());

  field
}
```

Fixes https://github.com/graphql-rust/juniper/issues/185.
2018-06-06 18:40:45 -07:00
Christian Legnitto
7933bf92a5
Rename variable to be more descriptive. 2018-05-23 00:49:23 -07:00
piperRyan
9080448da2 Add Compile Time Check For "Invalid" Names (#170) 2018-05-23 00:25:20 -07:00
Christoph Herzog
05c1011d83 (juniper_codegen) Upgrade syn + quote 2018-05-03 01:49:36 +02:00
Ivan Dubrov
bfe2ef511a Provide type info to the concrete_type_name 2018-01-20 10:53:18 +01:00
Christoph Herzog
d00e74bb4e Format entire codebase with rustfmt 2018-01-13 12:25:55 +01:00
Christoph Herzog
40c946c81c 0.9.2 release
* Changelogs
* Update versions and dependency versions
2018-01-13 10:34:30 +01:00
theduke
ca9d5c1c1a Bump to 0.9.1 and fix up Cargo.toml files 2017-12-03 18:48:38 +01:00
theduke
643875838d (codegen) improve derive for InputObject
* Implement hack to allow usage in juniper crate
* implement (default) attribute for Default::default()
* Improve tests
2017-12-02 15:43:41 +01:00
theduke
6ff3f1fba4 (codegen) Improve enum field name generation
Introduce a to_upper_snake_case() helper to properly convert enum names
to GraphQL compatible names.

Previously, "SomeEnum" would be converted to "SOMEENUM" and not
"SOME_ENUM".
2017-12-02 15:43:41 +01:00
theduke
f858f416b8 Remove graphql_enum! macro in favor of custom derive
* Extend derive for enums to allow deriving inside the juniper crate
  itself. Note: this is a rather ugly hack right now, FIXME is in the
  code
* Remove the graphql_enum! macro and replace all internal use with
  derive
* Refactor introspection tests to use derive
2017-12-02 15:43:22 +01:00
theduke
7b066ef1f9 (docs) Add short crate docs to codegen. 2017-12-02 02:35:08 +01:00
theduke
3750349e71 Bump version to 0.9.0 2017-12-02 02:31:56 +01:00
theduke
141292ad91 Export codegen from main juniper crate
Use a trick for re-exporting proc-macros to supply juniper_derive as a
dependency of juniper.

Users will now just have to depend on juniper directly.
2017-12-02 02:27:41 +01:00
theduke
0372de84d5 Rename ToInputValue::to to to_input_value() 2017-08-29 05:34:35 +02:00
theduke
164aa29fdc Rename FromInputValue::from() to from_input_value() 2017-08-29 05:34:35 +02:00
Sam Rijs
a0f2c3bbdd Implement support for dynamic schemas 2017-08-07 22:15:09 +02:00
theduke
a826b22ffb Update Readme and Cargo files for new repo url 2017-08-07 08:20:05 +02:00
theduke
0c7e39f14e Rust fmt the whole codebase 2017-08-06 21:15:08 +02:00
theduke
81ce7780fa Codegen: implement description for custom derives + improve tests
Description attribute was available, but not actually used for derive
Object, InputObject and enum and the fields on input object.

Description is now properly set in each of those cases.

Also, tests for all three derives now properly verify the meta
information (name and description) for the derived GraphQLType.
2017-08-06 19:30:26 +02:00
theduke
6c45fba9bd Fix some warnings in codegen + tests. 2017-08-06 19:30:26 +02:00
theduke
6c7dc0493d Rename custom derive modules for consistency.
codegen/enums -> codegen/derive_enum
codegen/input_objects -> codegen/derive_input_object
tests/enums -> tests/derive_enum
tests/input_objects -> tests/derive_input_object
2017-08-06 19:30:26 +02:00
theduke
e835a5e019 Codegen: Add custom derive for GraphQLObject
This adds a simple derive for objects that implements GraphQLType for
structs which do not require any manual resolvers.

This could be extended in the future to provide a custom resolver
function via an attribute.

Also adds an integration test.
2017-08-06 19:30:26 +02:00
theduke
c27d2c7a23 Make variant name for derived enums upper case by default 2017-07-12 21:51:24 +02:00
theduke
1312c6a026 Implement derive for input objects 2017-07-12 21:51:24 +02:00
theduke
e42228e2d5 Duplicating to_camel_case in codegen 2017-07-12 21:51:24 +02:00
theduke
2bcfc315ad Use more descriptive variant variable names for enum deriving 2017-07-12 21:51:24 +02:00
theduke
d33db983de Add juniper_codegen crate.
This crate will contain multiple custom_derive implementations.

For now, only enum is supported.
2017-07-12 21:51:24 +02:00