ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.27k stars 748 forks source link

Query build Order changes underlying types depending on platform #7711

Closed dasomx77 closed 2 weeks ago

dasomx77 commented 2 weeks ago

Product

Strawberry Shake

Version

13.8.0

Link to minimal reproduction

https://github.com/ChilliCream/graphql-platform/issues/new?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22%F0%9F%8C%B6%EF%B8%8F+strawberry+shake%22&template=bug_report.yml

Steps to reproduce

Create multiple queries that use the same fragments and build the generated code on multiple platforms.

Example: File 1:

query MyViewerWithBasicFields {
  viewer {
    basicInfo {
      ...ViewerBasicInfoFragment
    }
  }
}

File 2:

query MyViewerWithBasicAndAdvancedFields {
  viewer {
    basicInfo {
      ...ViewerBasicInfoFragment
    }

    advancedInfo {
      ...ViewerAdvancedInfoFragment
    }
  }
}

create the fragments themselves in their own files.

What is expected?

I would expect either a single type consistently generated for say MyViewerWithBasicFields: data.viewer.basicInfo to be of type IMyViewerWithBasicFields_Viewer_BasicInfo and MyViewerWithBasicAndAdvancedFields: data.viewer.basicInfo to be of type IMyViewerWithBasicAndAdvancedFields_Viewer_BasicInfo or better yet a single type since they are both retrieving the same fragment.

What is actually happening?

When the fragments are created, depending on which query is built first it could end up with from MyViewerWithBasicFields results, viewer.basicInfo can end up being of type IMyViewerWithBasicAndAdvancedFields_Viewer_BasicInfo if MyViewerWithBasicAndAdvancedFields query is built before MyViewerWithBasicFields query and there doesn't seem to be a way to enforce query build order and so it makes testing or mocking the underlying types very difficult as one platform may end up generating the type that your local/dev machine did not generate. What ends up happening is that in my unit tests, I build mock objects to viewer.basicInfo of type IMyViewerWithBasicAndAdvancedFields_Viewer_BasicInfo and it works locally but when in our CI, it fails because IMyViewerWithBasicAndAdvancedFields_Viewer_BasicInfo cannot be converted to IMyViewerWithBasicFields_Viewer_BasicInfo which coincidentally is what the CI saw as the first query to build. I am also assuming this is due to the build order, first query to use a type becomes the type which other queries will use. Tested from mac and sent to be tested on a different platform.

Relevant log output

Additional context

No response

glen-84 commented 2 weeks ago

Closing as a duplicate of #6873.