ChilliCream / ChilliCream/graphql-platform
InputParsing with Strawberry Shake runtime types
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Product
Hot Chocolate
Version
15.0.0
Link to minimal reproduction
https://github.com/jarlef/InputParsingUnsetOptionalFields
Steps to reproduce
We are trying to connect 2 graphql apis together using strawberry shake to fetch data from other. The api that is being called is exposing data with the ability to specify HC filtering and sorting. The consuming api invokes this api with forwarding / proxying the filters and sorting inputs from the user using Strawberry shake generated types. The issue is that the InputParser is setting all the properties on the Strawberry shake runtime type even though its not specified by the incoming payload, resulting in all the hidden set fields for the Strawberry shake is set to true
E.g incoming request
{
myItems(order: [ { Id: ASC } ]) {
id
title
}
}
The issue with the strawberry shake runtime type
public global::MyAPI.Generated.SortEnumType? Id
{
get => _value_id;
set
{
_set_id = true;
_value_id = value;
}
}
public global::MyAPI.Generated.SortEnumType? Title
{
get => _value_title;
set
{
_set_title = true; // <= this get set to true
_value_title = value;
}
}
Afterwards both the id and title is forwarded to the second api with titles sort value = null
What is expected?
Only the fields specified in the incoming payload to be marked as set. The InputParser seems overly eager in setting properties, even tough the value are null
What is actually happening?
The filter and sort inputs objects are not valid since they register every property as set in Strawberry Shake.
Relevant log output
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked InputParsingUnsetOptionalFields minimal reproduction and trace how InputParser handles omitted fields when populating Strawberry Shake generated runtime types. Compare the incoming selection with the generated setters' tracking flags; done means only fields present in the payload are marked set and forwarding no longer includes omitted fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, graphql
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100