-
Notifications
You must be signed in to change notification settings - Fork 89
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
[experiment] Attempt to upgrade stitching to latest #3375
Draft
damassi
wants to merge
6
commits into
main
Choose a base branch
from
damassi/upgrade-stitching-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/lib/stitching2/kaws/__tests__/__snapshots__/schema.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`creates an SDL 1`] = ` | ||
"type Collection { | ||
id: ID! | ||
slug: String! | ||
title: String! | ||
description: String | ||
descriptionMarkdown: String | ||
headerImage: String | ||
thumbnail: String | ||
keywords: String! | ||
credit: String | ||
category: String! | ||
query: CollectionQuery! | ||
createdAt: DateTime! | ||
updatedAt: DateTime! | ||
price_guidance: Float @deprecated(reason: \\"Prefer priceGuidance\\") | ||
priceGuidance: Float | ||
show_on_editorial: Boolean! @deprecated(reason: \\"Prefer showOnEditorial\\") | ||
showOnEditorial: Boolean! | ||
is_featured_artist_content: Boolean! @deprecated(reason: \\"Prefer isFeaturedArtistContent\\") | ||
isFeaturedArtistContent: Boolean! | ||
linkedCollections: [CollectionGroup!]! | ||
featuredArtistExclusionIds: [String!] | ||
relatedCollections(size: Int = 10): [Collection!]! | ||
isDepartment: Boolean! | ||
} | ||
|
||
type CollectionCategory { | ||
name: String! | ||
collections: [Collection!]! | ||
} | ||
|
||
type CollectionGroup { | ||
internalID: ID | ||
groupType: GroupTypes! | ||
name: String! | ||
members: [Collection!]! | ||
} | ||
|
||
type CollectionQuery { | ||
id: ID | ||
internalID: ID | ||
acquireable: Boolean | ||
aggregations: [String!] | ||
artist_ids: [String!] @deprecated(reason: \\"Prefer artistIDs\\") | ||
artistIDs: [String!] | ||
artist_id: String @deprecated(reason: \\"Prefer artistID\\") | ||
artistID: String | ||
at_auction: Boolean @deprecated(reason: \\"Prefer atAuction\\") | ||
atAuction: Boolean | ||
color: String | ||
dimension_range: String @deprecated(reason: \\"Prefer dimensionRange\\") | ||
dimensionRange: String | ||
extra_aggregation_gene_ids: [String!] @deprecated(reason: \\"prefer extraAggregationGeneIDs\\") | ||
extraAggregationGeneIDs: [String!] | ||
include_artworks_by_followed_artists: Boolean @deprecated(reason: \\"Prefer includeArtworksByFollowedArtists\\") | ||
includeArtworksByFollowedArtists: Boolean | ||
include_medium_filter_in_aggregation: Boolean @deprecated(reason: \\"Prefer includeMediumFilterInAggregation\\") | ||
includeMediumFilterInAggregation: Boolean | ||
inquireable_only: Boolean @deprecated(reason: \\"Prefer inquireableOnly\\") | ||
inquireableOnly: Boolean | ||
for_sale: Boolean @deprecated(reason: \\"Prefer forSale\\") | ||
forSale: Boolean | ||
gene_id: String @deprecated(reason: \\"Prefer geneID\\") | ||
geneID: String | ||
gene_ids: [String!] @deprecated(reason: \\"Prefer geneIDs\\") | ||
geneIDs: [String!] | ||
height: String | ||
width: String | ||
medium: String | ||
period: String | ||
periods: [String!] | ||
major_periods: [String!] @deprecated(reason: \\"Prefer majorPeriods\\") | ||
majorPeriods: [String!] | ||
partner_id: ID @deprecated(reason: \\"Prefer partnerID\\") | ||
partnerID: ID | ||
partner_cities: [String!] @deprecated(reason: \\"Prefer partnerCities\\") | ||
partnerCities: [String!] | ||
price_range: String @deprecated(reason: \\"Prefer priceRange\\") | ||
priceRange: String | ||
page: Int | ||
sale_id: ID @deprecated(reason: \\"Prefer saleID\\") | ||
saleID: ID | ||
size: Int | ||
sort: String | ||
tag_id: String @deprecated(reason: \\"Prefer tagID\\") | ||
tagID: String | ||
keyword: String | ||
} | ||
|
||
scalar DateTime | ||
|
||
enum GroupTypes { | ||
ArtistSeries | ||
FeaturedCollections | ||
OtherCollections | ||
} | ||
|
||
type Query { | ||
collections(slugs: [String!], category: String, randomizationSeed: String, size: Int, isFeaturedArtistContent: Boolean, showOnEditorial: Boolean, artistID: String): [Collection!]! | ||
categories: [CollectionCategory!]! | ||
collection(slug: String!): Collection | ||
hubCollections: [Collection!]! | ||
} | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { executableKawsSchema } from "../schema" | ||
import { | ||
getTypesFromSchema, | ||
getRootFieldsFromSchema, | ||
} from "lib/stitching/lib/getTypesFromSchema" | ||
import { printSchema } from "graphql" | ||
import { stitchSchemas } from "@graphql-tools/stitch" | ||
import { incrementalMergeSchemas2 } from "lib/stitching2/mergeSchemas" | ||
|
||
it("Does not include kaws core types", async () => { | ||
const stitchedSchema = incrementalMergeSchemas2({}) | ||
const kawsSchema = await executableKawsSchema() | ||
const schema = stitchSchemas({ | ||
subschemas: [kawsSchema], | ||
}) | ||
debugger | ||
const kawsTypes = await getTypesFromSchema(schema) | ||
|
||
expect(kawsTypes).not.toContain("Collection") | ||
expect(kawsTypes).not.toContain("CollectionCategory") | ||
expect(kawsTypes).not.toContain("CollectionQuery") | ||
|
||
expect(kawsTypes).toContain("MarketingCollection") | ||
}) | ||
|
||
it("Does not include the root query fields", async () => { | ||
const kawsSchema = await executableKawsSchema() | ||
const rootFields = await getRootFieldsFromSchema(kawsSchema.schema) | ||
|
||
expect(rootFields).not.toContain("categories") | ||
expect(rootFields).not.toContain("collection") | ||
expect(rootFields).not.toContain("collections") | ||
}) | ||
|
||
it("creates an SDL", async () => { | ||
const kawsSchema = await executableKawsSchema() | ||
expect( | ||
printSchema(kawsSchema.schema, { commentDescriptions: true }) | ||
).toMatchSnapshot() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { | ||
getKawsMergedSchema, | ||
getKawsStitchedSchema, | ||
} from "lib/stitching/kaws/__tests__/testingUtils" | ||
import { getFieldsForTypeFromSchema } from "lib/stitching/lib/getTypesFromSchema" | ||
|
||
describe("KAWS Stitching", () => { | ||
it("extends the Viewer object", async () => { | ||
const mergedSchema = await getKawsMergedSchema() | ||
const viewerFields = await getFieldsForTypeFromSchema( | ||
"Viewer", | ||
mergedSchema | ||
) | ||
expect(viewerFields).toContain("marketingCollections") | ||
}) | ||
|
||
describe("HomePageMarketingCollectionsModule", () => { | ||
it("extends the HomePageMarketingCollectionsModule object", async () => { | ||
const mergedSchema = await getKawsMergedSchema() | ||
const homePageMarketingCollectionsModuleFields = await getFieldsForTypeFromSchema( | ||
"HomePageMarketingCollectionsModule", | ||
mergedSchema | ||
) | ||
expect(homePageMarketingCollectionsModuleFields).toContain("results") | ||
}) | ||
|
||
it("returns an array even if the kaws request fails", async () => { | ||
const { resolvers } = await getKawsStitchedSchema() | ||
const resultsResolver = | ||
resolvers.HomePageMarketingCollectionsModule.results.resolve | ||
const delegateToSchemaMock = jest.fn() | ||
delegateToSchemaMock.mockRejectedValue( | ||
"simulating a kaws request failure" | ||
) | ||
const mergeInfo = { delegateToSchema: delegateToSchemaMock } | ||
const results = await resultsResolver({}, {}, {}, { mergeInfo }) | ||
expect(results).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe("MarketingCollection", () => { | ||
it("extends the HomePageMarketingCollectionsModule object", async () => { | ||
const mergedSchema = await getKawsMergedSchema() | ||
const fields = await getFieldsForTypeFromSchema( | ||
"MarketingCollection", | ||
mergedSchema | ||
) | ||
expect(fields).toContain("internalID") | ||
}) | ||
|
||
it("returns the id", async () => { | ||
const { resolvers } = await getKawsStitchedSchema() | ||
const resolver = resolvers.MarketingCollection.internalID.resolve | ||
const result = resolver({ id: "percy" }, {}, {}, {}) | ||
expect(result).toEqual("percy") | ||
}) | ||
}) | ||
|
||
describe("marketingCollections", () => { | ||
it("passes artist internalID to kaws' artistID arg when querying `... on Artist`", async () => { | ||
const { resolvers } = await getKawsStitchedSchema() | ||
const marketingCollectionsResolver = | ||
resolvers.Artist.marketingCollections.resolve | ||
const mergeInfo = { delegateToSchema: jest.fn() } | ||
|
||
await marketingCollectionsResolver( | ||
{ internalID: "artist-internal-id" }, | ||
{}, | ||
{}, | ||
{ mergeInfo } | ||
) | ||
|
||
expect(mergeInfo.delegateToSchema).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
args: { artistID: "artist-internal-id" }, | ||
fieldName: "marketingCollections", | ||
}) | ||
) | ||
}) | ||
|
||
it("passes through slugs when stitched under a fair", async () => { | ||
const { resolvers } = await getKawsStitchedSchema() | ||
const marketingCollectionsResolver = | ||
resolvers.Fair.marketingCollections.resolve | ||
const mergeInfo = { delegateToSchema: jest.fn() } | ||
|
||
await marketingCollectionsResolver( | ||
{ kawsCollectionSlugs: ["catty-collection"] }, | ||
{}, | ||
{}, | ||
{ mergeInfo } | ||
) | ||
|
||
expect(mergeInfo.delegateToSchema).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
args: { slugs: ["catty-collection"] }, | ||
fieldName: "marketingCollections", | ||
}) | ||
) | ||
}) | ||
|
||
it("returns an empty list when there are no kawsCollectionSlugs", async () => { | ||
const { resolvers } = await getKawsStitchedSchema() | ||
const marketingCollectionsResolver = | ||
resolvers.Fair.marketingCollections.resolve | ||
const mergeInfo = { delegateToSchema: jest.fn() } | ||
|
||
const result = await marketingCollectionsResolver( | ||
{ kawsCollectionSlugs: [] }, | ||
{}, | ||
{}, | ||
{ mergeInfo } | ||
) | ||
|
||
expect(result).toEqual([]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { mergeSchemas } from "graphql-tools" | ||
import { kawsStitchingEnvironmentV2 } from "../v2/stitching" | ||
import { GraphQLSchema } from "graphql" | ||
import { executableKawsSchema } from "../schema" | ||
import localSchema from "schema/v2/schema" | ||
|
||
let cachedSchema: GraphQLSchema & { transforms: any } | ||
let stitchedSchema: ReturnType<typeof kawsStitchingEnvironmentV2> | ||
let mergedSchema: GraphQLSchema & { transforms: any } | ||
|
||
/** Gets a cached copy of the transformed kaws schema */ | ||
export const getKawsTransformedSchema = async () => { | ||
if (!cachedSchema) { | ||
cachedSchema = await executableKawsSchema() | ||
} | ||
return cachedSchema | ||
} | ||
|
||
/** Gets a cached copy of the stitched schema, independent of being merged into the local schema */ | ||
export const getKawsStitchedSchema = async () => { | ||
if (!stitchedSchema) { | ||
const cachedSchema = await getKawsTransformedSchema() | ||
stitchedSchema = kawsStitchingEnvironmentV2(localSchema, cachedSchema) | ||
} | ||
return stitchedSchema | ||
} | ||
|
||
/** Gets a cached fully setup schema with kaws and the localSchema set up */ | ||
export const getKawsMergedSchema = async () => { | ||
if (!stitchedSchema) { | ||
const cachedSchema = await getKawsTransformedSchema() | ||
const { extensionSchema, resolvers } = await getKawsStitchedSchema() | ||
|
||
// The order should only matter in that extension schemas come after the | ||
// objects that they are expected to build upon | ||
mergedSchema = mergeSchemas({ | ||
schemas: [localSchema, cachedSchema, extensionSchema], | ||
resolvers: resolvers, | ||
}) as GraphQLSchema & { transforms: any } | ||
|
||
const anyMergedSchema = mergedSchema as any | ||
anyMergedSchema.__allowedLegacyNames = ["__id"] | ||
} | ||
return mergedSchema | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the double page refresh is required. Below we're returning
export default app
, which is mounted into the main express app but here we need to wait forgetSchemaV2
to return before the routes are actually mounted -- hence the hiccup.