Skip to content

CHECK-395: Consolidate project page fetch into a single GraphQL query#2910

Open
amy-at-kickstarter wants to merge 2 commits into
mainfrom
feat/adyer/check-395/squash-fetch-queries
Open

CHECK-395: Consolidate project page fetch into a single GraphQL query#2910
amy-at-kickstarter wants to merge 2 commits into
mainfrom
feat/adyer/check-395/squash-fetch-queries

Conversation

@amy-at-kickstarter

@amy-at-kickstarter amy-at-kickstarter commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

📲 What

Combine FetchProjectByIdQuery and FetchProjectBySlugQuery into one query, FetchProjectByParamQuery.

🤔 Why

A project page can be fetched in two ways: by slug, or by pid. This was originally defined as two separate GraphQL queries: FetchProjectBySlugQuery and FetchProjectByIdQuery, respectively.

Because Apollo makes separate types for each query, we had different parsing code to handle each of the two query types. This led to a bunch of duplication, and makes it difficult to update this query.

By combining these into a single query - in which both pid and slug are optional - we can delete all this duplicate code and make it easier to handle. We use the enum type Param to make sure you always create this query correctly.

slug: .someOrNil(projectParam.slug)
)

switch (projectParam.id, projectParam.slug) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra mocking existed because the return type, ProjectPamphletData, was a tuple and not decodable. I made it a struct and decodable which let me delete all of this.

return SignalProducer(value: envelope)
}

internal func fetchProject(project: Project) -> SignalProducer<Project, ErrorEnvelope> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is unused. Since it used the query I renamed, I just deleted it instead of fixing it. (I also deleted it from ServiceType and Service).

)

return SignalProducer(value: data)
public struct ProjectPamphletData: Decodable {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure we need this envelope at all. But for now, making it a struct so it's easier to handle.

@nativeksr

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ Big PR

Generated by 🚫 Danger


static func project(
from data: GraphAPI.FetchProjectBySlugQuery.Data,
internal static func project(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tagged this as internal because it's only called by the method above, projectProducer(from:configCurrency:)

@amy-at-kickstarter amy-at-kickstarter marked this pull request as ready for review July 9, 2026 17:12
@amy-at-kickstarter amy-at-kickstarter requested review from a team and scottkicks and removed request for a team July 9, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants