graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Generating predictable model classes in strawberry shake

Open jarlef opened this issue 1 year ago • 3 comments

Product

Strawberry Shake

Is your feature request related to a problem?

A recent issue ive encounter is that the generated client in Strawberry Shake is not consistent when using fragments

E.g the following graphl queries agains a schema.

fragment MySchool on School {
    id
    name
}

fragment MyStudent on Student {
    id
    name
    age
    school {
        ...MySchool
    }
}

query GetStudentById($id: Int!) {
    student(id: $id) {
        ...MyStudent
    }

}

query GetStudents {
    students {
        ...MyStudent
    }
}

In this case it will generate two models for student. GetStudentById_Student and GetStudents_Students_Student both inherting from their own dedicated interfaces that in turn inherits from IMyStudent. But deeply nested properties like the School property on GetStudents_Students_Student and GetStudentById_Student gets randomly assigned a type that is either IGetStudents_Students_Student_School or IGetStudentById_Student_School.

The solution you'd like

Since they are both implementing the fragment interface IMyStudent it clearly means the school property can only be of one type and IMO that should be IMySchool which is the fragments interface. One could also argu that student and students properties should also use the interface IMyStudent instead of their own interfaces since the fragment is an intent to express a named contract.


Link to minimal reproduction from #7194: https://github.com/pm7y/StrawberryShakeBugRepro

jarlef avatar Feb 09 '24 12:02 jarlef

This is causing us a huge headache anytime we need to update the schema. We have several queries and mutations that we call that share common fragments. Due to this, whenever we update the schema, there is a high likelihood that the randomly assigned type that Strawberry Shake uses to generate the classes which utilize fragments will change as well.

dillon-miller2-carvana avatar Mar 12 '24 04:03 dillon-miller2-carvana