ChilliCream / ChilliCream/graphql-platform
Too high cost emitted for @OneOf-InputTypes
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
16.0.0.rc.1.30
Link to minimal reproduction
See sample below
Steps to reproduce
Currently cost calculation does not take @oneOf semantics into account.
Consider the following schema:
type Mutation {
setField(input: OneOfSampleInput): String!
}
input OneOfSampleInput @oneOf {
fieldOne: String! @cost(weight: "900")
fieldTwo: String! @cost(weight: "400")
}
For the mutation:
mutation ($input: OneOfSampleInput) {
setField(input: $input)
}
The result is:
{
"errors": [
{
"message": "The maximum allowed field cost was exceeded.",
"extensions": {
"code": "HC0047",
"fieldCost": 1301,
"maxFieldCost": 1000
}
}
]
}
This result is incorrect / way too high.
Since OneOfSampleInput is annotated with @oneOf, exactly one field must be provided. Therefore, the cost must not be computed as the sum of all fields. Instead, it must be the maximum cost of all fields, since only one field may have a value.
Background: I am having kind of a "God"-muation, with one huge OneOf-Input. Each field of that OneOf-type is fine regarding cost on its own, but when they a summed up, cost validation is violated by a huge amout.
mutation {
createObject(input: ObjectInput)
}
input ObjectInput @oneOf {
typeA: TypeAInput
typeB: TypeBInput
typeC: TypeCInput
...
# maaaany more types
typeZ: TypeZInput
}
This forces me to disable cost validation, even though this shouldn't be required.
What is expected?
cost(oneOf { f1, f2, ..., fn }) = max(cost(f1), cost(f2), ..., cost(fn))
What is actually happening?
cost(oneOf { f1, f2, ..., fn }) = cost(f1) + cost(f2) + ... + cost(fn))
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 by reproducing the reported schema and mutation with the @oneOf input and weighted fields, then trace the cost calculation for OneOf input types. Done means the calculated cost uses the maximum field cost rather than summing all fields, while preserving the reported limit validation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100