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

Add #[graphql(optional)] for fields (provde less boilerplate and more correctness) #1457

Open
xoac opened this issue Jan 8, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@xoac
Copy link
Contributor

xoac commented Jan 8, 2024

Description of the feature

I found that in GQL I use Optional<_> fields that are actually required, because how GQL interact in Apollo Federation (for example when error is returned for some subgraph the supergraph can still return partial data if field is optional). Adding #[graphql(optioanl)] make Rust code easier to write and at the same time make GQL as expected.

Code example (if possible)

#[derive(Debug, SimpleObject)]
#[graphql(shareable)]
// maybe #[graphql(all_fileds_optional)] that can be useful for structures used in Union? 
struct Object {
  #[graphql(optional)] // this field should never be null in our service but can be in others
  name: String,
  /// this field is sometime null
  opt_filed: Option<String>,
}
@xoac xoac added the enhancement New feature or request label Jan 8, 2024
@Miaxos
Copy link
Member

Miaxos commented Jan 8, 2024

Sorry I am not sure to understand the feature, why an Option<String> would not work here?

@xoac
Copy link
Contributor Author

xoac commented Jan 8, 2024

@Miaxos of course it will work - but you need to do a lot of Some(_) and also you can accidentally set value to None. With above you can have rust type checking system on your side. This would be only for fields that can't be null but in GQL schema are marked as nullable.

If you want to know why mark required fields as nullable read this: https://www.apollographql.com/docs/technotes/TN0023-nullability/

EDIT: updated example code to make sure that it's intentional and feature request is just syntax sugar.

@xoac xoac changed the title Add #[graphql(optional)] for fields Add #[graphql(optional)] for fields (provde less boilerplate and more correctness) Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants