Skip to content

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

Description

@maris-jurgenbergs

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions