Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify scalar and context (GraphQLEnum) #621

Merged
merged 15 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/book/content/types/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@ enum StarWarsEpisode {

# fn main() {}
```

## Supported Macro Attributes (Derive)

| Name of Attribute | Container Support | Field Support |
|-------------------|:-----------------:|:----------------:|
| context | ✔ | ? |
| deprecated | ✔ | ✔ |
| description | ✔ | ✔ |
| interfaces | ? | ✘ |
| name | ✔ | ✔ |
| noasync | ✔ | ? |
| scalar | ✔ | ? |
| skip | ? | ✔ |
| ✔: supported | ✘: not supported | ?: not available |
23 changes: 23 additions & 0 deletions integration_tests/juniper_tests/src/codegen/derive_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use fnv::FnvHashMap;
#[cfg(test)]
use juniper::{self, DefaultScalarValue, FromInputValue, GraphQLType, InputValue, ToInputValue};

pub struct CustomContext {}

impl juniper::Context for CustomContext {}

#[derive(juniper::GraphQLEnum, Debug, PartialEq)]
#[graphql(name = "Some", description = "enum descr")]
enum SomeEnum {
Expand Down Expand Up @@ -39,6 +43,12 @@ enum OverrideDocEnum {
Foo,
}

#[derive(juniper::GraphQLEnum)]
#[graphql(context = CustomContext)]
enum ContextEnum {
A,
}

#[test]
fn test_derived_enum() {
// Ensure that rename works.
Expand Down Expand Up @@ -98,3 +108,16 @@ fn test_doc_comment_override() {
let meta = OverrideDocEnum::meta(&(), &mut registry);
assert_eq!(meta.description(), Some(&"enum override".to_string()));
}

fn test_context<T>(_t: T)
where
T: GraphQLType<DefaultScalarValue, Context = CustomContext>,
{
// empty
}

#[test]
fn test_doc_custom_context() {
test_context(ContextEnum::A);
// test_context(OverrideDocEnum::Foo); does not work
}
7 changes: 7 additions & 0 deletions integration_tests/juniper_tests/src/codegen/derive_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ impl DroidCompat {
}
}

#[derive(juniper::GraphQLUnion)]
#[graphql(Context = CustomContext)]
pub enum DifferentContext {
A(DroidContext),
B(Droid),
}

// NOTICE: this can not compile due to generic implementation of GraphQLType<__S>
// #[derive(juniper::GraphQLUnion)]
// pub enum CharacterCompatFail {
Expand Down
2 changes: 2 additions & 0 deletions juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ See [#569](https://github.com/graphql-rust/juniper/pull/569).

See [#618](https://github.com/graphql-rust/juniper/pull/618).

- Derive macro `GraphQLEnum` supports custom context and scalar (see [#621](https://github.com/graphql-rust/juniper/pull/621))

## Breaking Changes

- `juniper::graphiql` has moved to `juniper::http::graphiql`
Expand Down