Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add featuredFairsConnection #6421

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

olerichter00
Copy link
Contributor

@olerichter00 olerichter00 commented Feb 10, 2025

Addresses ONYX-1508

Description

This PR creates the new root field featuredFairsConnection. The connection replaces the Fairs home module and is used as a root field (for the new "Featured Fairs" screen) and the "Featured Fairs" home view section. Both the new root connection and the section share the resolver and return the same list of fairs.


Query:

{
  me {
    email
    internalID
  }

  homeView {
    section(id: "home-view-section-featured-fairs") {
      __typename
      internalID

      ... on HomeViewSectionFairs {
        fairsConnection(first: 10) {
          totalCount
          edges {
            node {
              name
              startAt
            }
          }
        }
      }
    }
  }

  featuredFairsConnection(first: 30) {
    totalCount
    edges {
      cursor
      node {
        name
        startAt
        endAt
      }
    }
  }
}

@olerichter00 olerichter00 self-assigned this Feb 10, 2025
@artsy-peril
Copy link
Contributor

artsy-peril bot commented Feb 12, 2025

Warnings
⚠️

The V2 schema in this PR has breaking changes with Force. Remember to update the Force schema if necessary.

Type 'ArtworkImportRowError' was removed
Type 'AssignArtworkImportArtistInput' was removed
Type 'AssignArtworkImportArtistPayload' was removed
Type 'AssignArtworkImportArtistResponseOrError' was removed
Type 'AssignArtworkImportArtistFailure' was removed
Type 'AssignArtworkImportArtistSuccess' was removed
Type 'CreateArtworkImportArtworksInput' was removed
Type 'CreateArtworkImportArtworksPayload' was removed
Type 'CreateArtworkImportArtworksResponseOrError' was removed
Type 'CreateArtworkImportArtworksFailure' was removed
Type 'CreateArtworkImportArtworksSuccess' was removed
Type 'MatchArtworkImportArtistsInput' was removed
Type 'MatchArtworkImportArtistsPayload' was removed
Type 'MatchArtworkImportArtistsResponseOrError' was removed
Type 'MatchArtworkImportArtistsFailure' was removed
Type 'MatchArtworkImportArtistsSuccess' was removed
'ArtworkImport' object type no longer implements 'Node' interface
Field 'unmatchedArtistNames' was removed from object type 'ArtworkImport'
Argument 'errorTypes: [String!]' was removed from field 'ArtworkImport.rowsConnection'
Argument 'hasErrors: Boolean' was removed from field 'ArtworkImport.rowsConnection'
Field 'artists' was removed from object type 'ArtworkImportRow'
Field 'artwork' was removed from object type 'ArtworkImportRow'
Field 'errors' was removed from object type 'ArtworkImportRow'
Field 'assignArtworkImportArtist' was removed from object type 'Mutation'
Field 'createArtworkImportArtworks' was removed from object type 'Mutation'
Field 'matchArtworkImportArtists' was removed from object type 'Mutation'
Input field 'filePath' was added to input object type 'CreateArtworkImportInput'
Input field 's3Bucket' was removed from input object type 'CreateArtworkImportInput'
Input field 's3Key' was removed from input object type 'CreateArtworkImportInput'
Field 'badgeText' was removed from object type 'HomeViewCard'
Field 'icon' was removed from object type 'NavigationPill'

Generated by 🚫 dangerJS against 21f710d


const now = moment.utc()

const { body: unfilteredRunningFairs } = await fairsLoader(gravityOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will return a default of 10 records from the gravity endpoint (as no pagination arguments are specified).

allFairs = allFairs.concat(closedFairs)
}

const totalCount = allFairs.length
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really doing pagination as 'all fairs' data is being assembled here, and only then 'sliced' over by the incoming connection arguments.

In general connections are always better than lists (as they're future proof and can support some 'fake' pagination or real pagination) - but in this case, maybe the schema should just be the full list? (featuredFairs w/ no connection).

Just calling out b/c anytime we do something 'quirky' with pagination, or kind of fake it by filtering and doing pagination not on the backend server - my ears perk up!

@dariakoko dariakoko self-requested a review February 13, 2025 13:34
Copy link
Member

@dblandin dblandin left a comment

Choose a reason for hiding this comment

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

Looking good!

const runningFairs = filter(unfilteredRunningFairs, (fair) => {
const startAt = moment.utc(fair.start_at)
return now.isAfter(startAt)
})
Copy link
Member

Choose a reason for hiding this comment

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

suggestion / non-blocking: The /api/v1/fairs API endpoint supports a status filter of running. Should we use that instead of active: true and this inline filter?

Not sure if this is used right now, but this fairs query has similar arguments.

const now = moment.utc()
const { size, offset, page } = convertConnectionArgsToGravityArgs(args)

const numberOfFairsToFetch = size + offset
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I think offset (along with size) can be directly passed to our pagination-supported API endpoints (source).

If the initial fairsLoader response returned fewer running fairs than the client's requested size, that's when we can trigger the backfill.

Something like:

const backfillSize = size - runningFairs.length

if (backfillSize > 0 && backfillSize > 0) {
  // request and add backfill fairs
}

const closedFairs = filter(unfilteredClosedFairs, (fair) => {
const endAt = moment.utc(fair.end_at)
return now.isAfter(endAt)
})
Copy link
Member

Choose a reason for hiding this comment

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

question: Similar to the question about running above – do we not trust Gravity to only return "closed" fairs? I wonder why this inline filter is needed...

const totalCount =
allFairs.length < numberOfFairsToFetch
? allFairs.length
: MAX_NUMBER_OF_FAIRS
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it's possible to return the combined total counts from both Gravity requests to return an accurate number here.

Something like:

const { body: runningFairs, headers: runningFairsHeaders } = await fairsLoader({
  size,
  offset,
  status: "running",
  total_count: true,
})

const { body: closedFairs, headers: closedFairsHeaders } = await fairsLoader({
  size: backfillSize,
  status: "close",
  total_count: true,
})

const totalCount = parseInt(runningFairs["x-total-count"] || "0") + parseInt(closedFairs["x-total-count"] || "0")

@olerichter00 olerichter00 force-pushed the olerichter00/ONYX-1508/add-featuredfairsconnection branch from 44730a3 to 21f710d Compare February 13, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants