Skip to content

Commit

Permalink
Merge pull request #917 from bvanneerven/master
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed May 7, 2022
2 parents 336451f + 92ed523 commit e87a8d2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 31 deletions.
63 changes: 32 additions & 31 deletions docs/en/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,40 @@
- [Introduction](introduction.md)
- [Quickstart](quickstart.md)
- [Type System](typesystem.md)
- [SimpleObject](define_simple_object.md)
- [Object](define_complex_object.md)
- [Context](context.md)
- [Error handling](error_handling.md)
- [Merging Objects / Subscriptions](merging_objects.md)
- [Derived fields](derived_fields.md)
- [Enum](define_enum.md)
- [Interface](define_interface.md)
- [Union](define_union.md)
- [InputObject](define_input_object.md)
- [Default value](default_value.md)
- [SimpleObject](define_simple_object.md)
- [Object](define_complex_object.md)
- [Context](context.md)
- [Error handling](error_handling.md)
- [Merging Objects / Subscriptions](merging_objects.md)
- [Derived fields](derived_fields.md)
- [Enum](define_enum.md)
- [Interface](define_interface.md)
- [Union](define_union.md)
- [InputObject](define_input_object.md)
- [OneofObject](define_one_of_object.md)
- [Default value](default_value.md)
- [Schema](define_schema.md)
- [Query and Mutation](query_and_mutation.md)
- [Subscription](subscription.md)
- [SDL Export](sdl_export.md)
- [Query and Mutation](query_and_mutation.md)
- [Subscription](subscription.md)
- [SDL Export](sdl_export.md)
- [Utilities](utilities.md)
- [Field guard](field_guard.md)
- [Input value validators](input_value_validators.md)
- [Cache control](cache_control.md)
- [Cursor connections](cursor_connections.md)
- [Error extensions](error_extensions.md)
- [Apollo Tracing](apollo_tracing.md)
- [Query complexity and depth](depth_and_complexity.md)
- [Hide content in introspection](visibility.md)
- [Field guard](field_guard.md)
- [Input value validators](input_value_validators.md)
- [Cache control](cache_control.md)
- [Cursor connections](cursor_connections.md)
- [Error extensions](error_extensions.md)
- [Apollo Tracing](apollo_tracing.md)
- [Query complexity and depth](depth_and_complexity.md)
- [Hide content in introspection](visibility.md)
- [Extensions](extensions.md)
- [How extensions are working](extensions_inner_working.md)
- [Available extensions](extensions_available.md)
- [How extensions are working](extensions_inner_working.md)
- [Available extensions](extensions_available.md)
- [Integrations](integrations.md)
- [Poem](integrations_to_poem.md)
- [Warp](integrations_to_warp.md)
- [Actix-web](integrations_to_actix_web.md)
- [Poem](integrations_to_poem.md)
- [Warp](integrations_to_warp.md)
- [Actix-web](integrations_to_actix_web.md)
- [Advanced topics](advanced_topics.md)
- [Custom scalars](custom_scalars.md)
- [Optimizing N+1 queries](dataloader.md)
- [Custom directive](custom_directive.md)
- [Apollo Federation](apollo_federation.md)
- [Custom scalars](custom_scalars.md)
- [Optimizing N+1 queries](dataloader.md)
- [Custom directive](custom_directive.md)
- [Apollo Federation](apollo_federation.md)
36 changes: 36 additions & 0 deletions docs/en/src/define_one_of_object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# OneofObject

A `OneofObject` is a special type of `InputObject`, in which only one of its fields must be set and is not-null.
It is especially useful when you want a user to be able to choose between several potential input types.

This feature is still an [RFC](https://github.com/graphql/graphql-spec/pull/825) and therefore not yet officially part of the GraphQL spec, but `Async-graphql` already supports it!

```rust
use async_graphql::*;

#[derive(OneofObject)]
enum UserBy {
Email(String),
RegistrationNumber(i64),
Address(Address)
}

#[derive(InputObject)]
struct Address {
street: String,
house_number: String,
city: String,
zip: String,
}

struct Query {}

#[Object]
impl Query {
async fn search_users(&self, by: Vec<UserBy>) -> Vec<User> {
// ... Searches and returns a list of users ...
}
}
```

As you can see, a `OneofObject` is represented by an `enum` in which each variant contains another `InputType`. This means that you can use [`InputObject`](define_input_object.md) as variant too.

0 comments on commit e87a8d2

Please sign in to comment.