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

@orta => Remove all legacy loader, remove couple rewire uses #954

Merged
merged 3 commits into from
Feb 28, 2018

Conversation

mzikherman
Copy link
Contributor

As I'm working thru remaining legacy data loaders (home page ones coming next!), I figured it's a good idea to PR early and often. Much like voting.

So this removes a legacy all helper, that was being used like: gravity.all("artworks"), which would continue paginating the API until exhausted. We have a allViaLoader helper which is used in a couple places instead (and an open issue to remove the client code in Force which requests that since it's a horrible pattern).

Also removes some rewire/stubbing via explicit DI of the loaders. Definitely doing a lot of this in these PRs, @alloy mentions we can't easily have both Rewire and Jest stubs in the same project, and so it'd be preferable to remove rewire entirely?

it("fans out all the requests", () => {
const loader = jest
.fn()
.mockReturnValueOnce(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first call is to retrieve the count, and then we fan out all required pages (for simplicity just resolving with an empty body as this helper doesn't care what is resolved).

@@ -110,8 +110,17 @@ const PartnerShowType = new GraphQLObjectType({
description: "The slug or ID of an artist in the show.",
},
},
resolve: ({ id, partner }, options) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed these 2 when I swept thru this file the other day.

total.onCall(0).returns(Promise.resolve(2))
rootValue.partnerShowArtworksLoader = sinon
.stub()
.returns(Promise.resolve({ headers: { "x-total-count": 2 } }))
Copy link
Contributor

Choose a reason for hiding this comment

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

I’d also suggest getting rid of sinon over builtin jest stubs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 can I tackle that in a separate issue/cleanup? There are...a lot of those :)

Copy link
Contributor

@orta orta Feb 28, 2018

Choose a reason for hiding this comment

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

I would recommend it, as a separate issue,there's a tool (jest-codemods) that might help here

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh absolutely, it was only an observation.

@@ -25,6 +24,7 @@ import {
GraphQLBoolean,
} from "graphql"
import { allViaLoader } from "../lib/all"
import { totalViaLoader } from "../lib/loaders/legacy/total"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yea I will eventually clean up the legacy total, and move the helper out of legacy/ directory (which won't exist anymore).

@orta
Copy link
Contributor

orta commented Feb 28, 2018

Yep, both babel-rewire and jest modules want to have control over the module system, and that introduces conflicts, so until babel-rewire is completely removed we can't use jest mocks

@orta
Copy link
Contributor

orta commented Feb 28, 2018

Yep, looks 👍 to me

@orta orta merged commit d214d30 into master Feb 28, 2018
@orta orta deleted the home_page_legac branch February 28, 2018 18:16
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.

3 participants