ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
4.96k stars 722 forks source link

Allow query conventions for non-object return types #7085

Closed cmeeren closed 1 week ago

cmeeren commented 2 weeks ago

Product

Hot Chocolate

Is your feature request related to a problem?

I need to use query conventions (e.g., [Error]) with fields that return non-object types such as List or primitives such as String.

The solution you'd like

I realize that unions do not support lists or primitives as one of their cases. When a field using query conventions returns a non-object type, I would like HotChocolate to automatically wrap the OK result for me, similar (though not identical) to mutation conventions.

For example, the list/primitive could be wrapped in a type called ...ResultValue which has a single member Value that is the returned list/primitive. The ...ResultValue type will then be the success case of the of the ...Result union.

DatStorm commented 1 week ago

There is a related issue for mutation but would be really nice if it worked for both: #6795

michaelstaib commented 1 week ago

We wont support that as unions do not work with scalars. I also do not want to introduce some wrapping here as this would result in a bad schema design. I am closing.

There is a related issue for mutation but would be really nice if it worked for both: https://github.com/ChilliCream/graphql-platform/issues/6795

For mutations this should work fine. I will have a look at the other issue.

cmeeren commented 1 week ago

@michaelstaib Would you mind elaborating on the bad schema design you mention? I'm currently wrapping my types manually. I have fields that return a list of objects, and this field has error conditions I want to return as part of the schema, too.