diff --git a/docs/en/src/SUMMARY.md b/docs/en/src/SUMMARY.md index 9e4fdd3d..e49d9cfa 100644 --- a/docs/en/src/SUMMARY.md +++ b/docs/en/src/SUMMARY.md @@ -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) diff --git a/docs/en/src/define_one_of_object.md b/docs/en/src/define_one_of_object.md new file mode 100644 index 00000000..83d1f438 --- /dev/null +++ b/docs/en/src/define_one_of_object.md @@ -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) -> Vec { + // ... 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.