ChilliCream / ChilliCream/graphql-platform

"Cannot convert error" in generated StrawberryShake code for implemented result types

Open
#6,292 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ strawberry shake
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.
image

The generated error:
cannot convert from 'ConsoleApp1.State.IParentTypeData' to 'ConsoleApp1.State.ParentVariantData'

Steps to reproduce
  1. mutations.graphql:
mutation mutationOneTest {
  testMutation {
    parent {
      someValue
    }
  }
}

mutation mutationOne {
  testMutation {
    ... on MutationResultVariantB {
      parent {
        ... on ParentVariant {
          someValue
        }
      }
    }
  }
}
  1. 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!
}
  1. .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"
                }
            ]
        }
    }
}

  1. Run the generator
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.