ChilliCream / ChilliCream/graphql-platform

Generation fails for interface types which has an id field

Open
#6,539 0 comments 0 reactions 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

I discovered that when I try to create a client for a schema where a field returns a list of an interface type and an implementing type as an id field, the generation breaks.

As soon as the interface has the field defined too it works. But if one of the implementing types implements two interfaces and only one has the id field defined it breaks again.

Steps to reproduce

Unittest for Strawberryshake CodeGeneration CSharp

    [Fact]
    public void Generate_CarsClient()
    {
        AssertResult(
            FileResource.Open("CarsQuery.graphql"),
            FileResource.Open("Schema.extensions.graphql"),
            FileResource.Open("Cars.Schema.graphql"));
    }

Cars.Schema.graphql

schema {
  query: Query
}

type Query {
  cars: [Car]
}

type Ferrari implements Car & Node{
  id: ID!
  price: Int!
}

type Bugatti implements Car & Node {
  id: ID!
  price: Int!
}

interface Car {
  price: Int!
}

interface Node {
  id: ID!
}

CarsQuery.graphql

query GetFerrariPrices {
  cars {
    ...on Ferrari {
      id
      price
    }
  }
}

Relevant log output
at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at StrawberryShake.CodeGeneration.CSharp.Generators.TypeMapperGenerator.GenerateIfForEachImplementedBy(MethodBuilder method, ComplexTypeDescriptor complexTypeDescriptor, Func`2 generator)
Additional Context?

In my use case i have an interface type and the implementing types generally also implement the Node interface. So they all have an id field. But the field which returns them is a list field of the other interface.

I already tried to enhance the IsData extension to use Entity and EntityData kind too but that breaks all other tests :D

Version

13.5.1

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

Start with the Generate_CarsClient unittest in the Strawberryshake CodeGeneration CSharp tests and its CarsQuery.graphql, Schema.extensions.graphql, and Cars.Schema.graphql resources. Trace the failure at TypeMapperGenerator.GenerateIfForEachImplementedBy, then add regression coverage showing generation succeeds for the interface and implementing types described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, graphql
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.