ChilliCream / ChilliCream/graphql-platform
"Cannot convert error" in generated StrawberryShake code for implemented result types
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Is there an existing issue for this?
- I have searched the existing issues
Product
Strawberry Shake
Describe the bug
In a recent project encountered "cannot convert from" error in the StrawberryShake generated code. I simplified the data structure which is handled with errors in the StrawberryShake generator.
There is a base type (ParentType), that is used in one mutation result (MutationResultVariantA) and the there is a extended type (ParentVariant), which is used in the second mutation result (MutationResultVariantB).
Additional data that is inside these types were stripped for simplicity.
The generated error:
cannot convert from 'ConsoleApp1.State.IParentTypeData' to 'ConsoleApp1.State.ParentVariantData'
Steps to reproduce
- mutations.graphql:
mutation mutationOneTest {
testMutation {
parent {
someValue
}
}
}
mutation mutationOne {
testMutation {
... on MutationResultVariantB {
parent {
... on ParentVariant {
someValue
}
}
}
}
}
- schema.graphql:
schema {
query: Query
mutation: Mutation
}
type Query {
testQuery(): MutationResult!
}
type Mutation {
testMutation(): MutationResult!
}
interface MutationResult {
parent: ParentType!
}
interface ParentType {
someValue: Int!
}
type MutationResultVariantA implements MutationResult {
parent: ParentType!
}
type MutationResultVariantB implements MutationResult {
parent: ParentVariant!
}
type ParentVariant implements ParentType {
someValue: Int!
}
- .graphqlrc,json
{
"schema": "schema.graphql",
"documents": "**/*.graphql",
"extensions": {
"strawberryShake": {
"name": "GraphQLClient",
"dependencyInjection": true,
"strictSchemaValidation": true,
"hashAlgorithm": "md5",
"useSingleFile": true,
"requestStrategy": "Default",
"outputDirectoryName": "Generated",
"noStore": false,
"emitGeneratedCode": true,
"razorComponents": false,
"records": {
"inputs": false,
"entities": false
},
"transportProfiles": [
{
"default": "Http",
"subscription": "WebSocket"
}
]
}
}
}
- Run the generator
- There is a repo with the bug present: https://github.com/maris-jurgenbergs/SBSGQLBug
Relevant log output
No response
Additional Context?
No response
Version
12.18.0
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
Reproduce the failure with the linked SBSGQLBug repository using mutations.graphql, schema.graphql, and .graphqlrc.json, then run the StrawberryShake generator. Inspect the generated code for the two mutation results and the ParentType/ParentVariant selection. Done means generation succeeds without the reported cannot-convert error for both mutations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100