ChilliCream / ChilliCream/graphql-platform

StrawberryShake modifies queries when generated

Open
#7,781 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

Product

Strawberry Shake

Version

14.x + 15.x + 16.x

Link to minimal reproduction

https://github.com/Cheesebaron/StrawberryShakeQueryMangling

Steps to reproduce

Build the linked example project and check the obj/berry output.

What is expected?

The generated code and query is different from the one I have in my .graphql file and additional types are added to the query. I would expect only the types I explicitly query would end up being queried in the end.

What is actually happening?

When you look at the generated files in ActivitlyListQuery.Client you will notice in the generated class the following GraphQL query. It is not just a comment, but also what StrawberryShake ends up requesting from the server.

query ActivityList($take: Int, $skip: Int, $activityKinds: [ActivityKind!], $includeHidden: Boolean) {
  me {
    __typename
    activities(take: $take, skip: $skip, kinds: $activityKinds, includeHidden: $includeHidden) {
      __typename
      items {
        __typename
        kind
        ... ActivityListCoursePlay
        ... ActivityListRangeBullsEye
        ... ActivityListRangeHitIt
        ... ActivityListRangeCaptureTheFlag
        ... ActivityListRangePractice
        ... ActivityListRangeFMD
        ... ActivityListCombine
        ... ActivityListTest
        ... ActivityListScreenCast
        ... ActivityListShotAnalysis
        ... ActivityListVirtualRange
        ... ActivityListSession
        ... ActivityListPerformanceCenter
        ... on SessionActivity {
          id
        }
        ... on VirtualRangeSessionActivity {
          id
        }
        ... on PerformancePuttingSessionActivity {
          id
        }
        ... on SimulatorSessionActivity {
          id
        }
        ... on ShotAnalysisSessionActivity {
          id
        }
        ... on TracySessionActivity {
          id
        }
        ... on DynamicReportActivity {
          id
        }
        ... on CombineTestActivity {
          id
        }
        ... on TestActivity {
          id
        }
        ... on ScreencastActivity {
          id
        }
        ... on VideoActivityType {
          id
        }
        ... on RangePracticeActivity {
          id
        }
        ... on CoursePlayActivity {
          id
        }
        ... on ClosestToThePinActivity {
          id
        }
        ... on RangeFindMyDistanceActivity {
          id
        }
        ... on RangeBullsEyeActivity {
          id
        }
        ... on RangeHitItActivity {
          id
        }
        ... on RangeCaptureTheFlagActivity {
          id
        }
        ... on RangeVirtualGolfPlayActivity {
          id
        }
        ... on RangeVirtualGolfPracticeActivity {
          id
        }
        ... on PdfReportActivity {
          id
        }
        ... on EventReportActivity {
          id
        }
        ... on NoteActivity {
          id
        }
        ... on PerformanceCenterActivity {
          id
        }
      }
      pageInfo {
        __typename
        hasNextPage
        hasPreviousPage
      }
      totalCount
    }
  }
}

When you compare that to the actual query in activity-list.graphql:

query ActivityList($take: Int, $skip: Int, $activityKinds: [ActivityKind!], $includeHidden : Boolean) {
  me {
    activities (take: $take, skip: $skip, kinds: $activityKinds, includeHidden: $includeHidden)
    {
      items {
        kind
        ... ActivityListCoursePlay
        ... ActivityListRangeBullsEye
        ... ActivityListRangeHitIt
        ... ActivityListRangeCaptureTheFlag
        ... ActivityListRangePractice
        ... ActivityListRangeFMD
        ... ActivityListCombine
        ... ActivityListTest
        ... ActivityListScreenCast
        ... ActivityListShotAnalysis
        ... ActivityListVirtualRange
        ... ActivityListSession
        ... ActivityListPerformanceCenter
      }
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
      totalCount
    }
  }
}

Then I don't explicitly add querying for id on all of these types:

... on SessionActivity {
          id
        }
        ... on VirtualRangeSessionActivity {
          id
        }
        ... on PerformancePuttingSessionActivity {
          id
        }
        ... on SimulatorSessionActivity {
          id
        }
        ... on ShotAnalysisSessionActivity {
          id
        }
        ... on TracySessionActivity {
          id
        }
        ... on DynamicReportActivity {
          id
        }
        ... on CombineTestActivity {
          id
        }
        ... on TestActivity {
          id
        }
        ... on ScreencastActivity {
          id
        }
        ... on VideoActivityType {
          id
        }
        ... on RangePracticeActivity {
          id
        }
        ... on CoursePlayActivity {
          id
        }
        ... on ClosestToThePinActivity {
          id
        }
        ... on RangeFindMyDistanceActivity {
          id
        }
        ... on RangeBullsEyeActivity {
          id
        }
        ... on RangeHitItActivity {
          id
        }
        ... on RangeCaptureTheFlagActivity {
          id
        }
        ... on RangeVirtualGolfPlayActivity {
          id
        }
        ... on RangeVirtualGolfPracticeActivity {
          id
        }
        ... on PdfReportActivity {
          id
        }
        ... on EventReportActivity {
          id
        }
        ... on NoteActivity {
          id
        }
        ... on PerformanceCenterActivity {
          id
        }

Having this added behind your back is problematic, especially when you have multiple environments where some types are not present because they have not been released yet.

Relevant log output

Additional context

No response

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

Build the linked StrawberryShakeQueryMangling example and compare Example/activity-list.graphql with the generated files in ActivitlyListQuery.Client. Trace the Strawberry Shake query-generation entry point responsible for the added fields and fragments. Done means generated requests contain only selections from the source query and remain valid across environments with differing types.

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.