cynic icon indicating copy to clipboard operation
cynic copied to clipboard

Support oneOf input objects

Open obmarg opened this issue 1 year ago • 3 comments

There's an RFC for these, and some servers support it already.

Cynics InputObject derive is quite awkward to use with oneOf objects currently:

  1. You can only serialize one of the fields of the InputObject, so you need to manually sprinkle skip_serializing_if everywhere.
  2. 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:

  1. Automatically provide skip_serializing_if: Option::is_none on fields of a struct associated with a oneOf input.
  2. Allow users to use an enum for oneOf inputs
  3. Update the generator to generate an enum for oneOf inputs.

obmarg avatar Jun 07 '23 16:06 obmarg

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.

obmarg avatar Jun 22 '23 22:06 obmarg

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

obmarg avatar Jun 22 '23 23:06 obmarg

This is super useful. We can take inspiration from async-graphql and it's OneofObject

carlocorradini avatar May 31 '24 08:05 carlocorradini