cynic
cynic copied to clipboard
Support oneOf input objects
There's an RFC for these, and some servers support it already.
Cynics InputObject
derive is quite awkward to use with oneOf
objects currently:
- You can only serialize one of the fields of the
InputObject
, so you need to manually sprinkleskip_serializing_if
everywhere. - When constructing objects you need to provide a bunch of additional
field: None
I think it'd be good to have some rudimentary first class support for these:
- Automatically provide
skip_serializing_if: Option::is_none
on fields of a struct associated with aoneOf
input. - Allow users to use an
enum
foroneOf
inputs - Update the generator to generate an enum for
oneOf
inputs.
Using these with introspection queries might be complicated, since oneOf isn't actually "official" so not sure how we'd know whether to include it in an introspection query.
I suppose we could run an initial query without oneOf, look at the directives and see oneOf and then run another query? Not ideal though.
Actually, one way to achieve this might be to allow derive(InputObject) on an enum for any input object that has entirely optional fields.
Avoids needing to specifically detect it, and it should presumably work anyway? Interesting thought
This is super useful.
We can take inspiration from async-graphql
and it's OneofObject