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

refactor(gatsby): change bootstrap to use services #24816

Merged
merged 27 commits into from
Jun 19, 2020

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Jun 5, 2020

This splits the bootstrap command into smaller parts, which it imports from services. A lot of this is in the initialize service, which is mostly a direct TypeScript port from the relevant section of the old bootstrap file.

The services that this PR includes are:

  • initialize
  • customize-schema
  • source-nodes
  • build-schema
  • create-pages
  • create-pages-statefully
  • extract-queries
  • write-out-requires
  • write-out-redirects
  • post-bootstrap

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 5, 2020
@ascorbic ascorbic added topic: develop state machine and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jun 5, 2020
@ascorbic ascorbic marked this pull request as ready for review June 11, 2020 10:49
@ascorbic ascorbic requested a review from a team as a code owner June 11, 2020 10:49
@ascorbic ascorbic added the status: needs core review Currently awaiting review from Core team member label Jun 12, 2020
import { Runner } from "./create-graphql-runner"
import { writeOutRedirects } from "../services/write-out-redirects"
import { postBootstrap } from "../services/post-bootstrap"
import { rebuildWithSitePage } from "../schema"
Copy link
Contributor

Choose a reason for hiding this comment

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

This one feels werid to actually not be service given that everything else is (other than types and one "startListener").

What qualifies something to be a service really?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In short: it being used in state machine. I'm not 100% sure whether I'll need to use this one there, but you're right I should probably make it one anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this one will be used in any other place (schema-hot-reloader uses rebuild from src/schema/index), but I do like "entry points" for each ... "service" to be in same place (src/services/) vs some in services and some elsewhere.

Also another NIT - this change as is lost the update schema activity wrapping the execution of rebuildWithSitePage

activity = reporter.activityTimer(`update schema`, {	
    parentSpan: bootstrapSpan,	
  })

So if this is moved to service - that would be natural place to re-add it

@ascorbic ascorbic changed the title refactor(gatsby): change boostrap to use services refactor(gatsby): change bootstrap to use services Jun 16, 2020
@sidharthachatterjee sidharthachatterjee self-assigned this Jun 17, 2020
@wardpeet
Copy link
Contributor

I'll run this locally but looks good to me. Good job!

@@ -70,8 +70,8 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
const buildSpan = buildActivity.span
buildSpan.setTag(`directory`, program.directory)

const { graphqlRunner: bootstrapGraphQLRunner } = await bootstrap({
...program,
const { gatsbyNodeGraphQLFunction } = await bootstrap({
Copy link
Contributor

@pvdz pvdz Jun 18, 2020

Choose a reason for hiding this comment

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

@ascorbic btw when I mean reducing irrelevant changes out, this is the kind. This file has 5 changed lines. Three of them concern a var rename. I bet we can find many of these that are not really relevant to the core of this PR.

You can probably separate out the bootstrap api changes as well. (Export default to export binding, program no longer being spread, returned keys, etc).

In other words; I don't think any of the changes in this file are really relevant to the kind of change this PR intends to introduce.

Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

I did a thorough review.

It seems to me like there's a lot of duplicate code going on in the service files. Every service is basically the pattern

const activity = reporter.activityTimer(desc, {
    parentSpan,
  })
  activity.start()
  await <action>
  activity.end()

Can't we abstract and dedupe that code? Do we prefer to be explicit in this case?

Beyond that I have some non-blocking comments, a question, and two minor changes I'd like to see (moving the type stuff and removing debug comments). This is almost ready to go :)

packages/gatsby/src/services/build-schema.ts Show resolved Hide resolved
packages/gatsby/src/services/create-pages.ts Show resolved Hide resolved
packages/gatsby/src/services/initialize.ts Show resolved Hide resolved
packages/gatsby/src/services/initialize.ts Show resolved Hide resolved
packages/gatsby/src/services/initialize.ts Outdated Show resolved Hide resolved
}

module.exports = async (args: BootstrapArgs) => {
const spanArgs = args.parentSpan ? { childOf: args.parentSpan } : {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I presume this childOf stuff is not relevant anymore?

packages/gatsby/src/services/initialize.ts Show resolved Hide resolved
packages/gatsby/src/services/initialize.ts Outdated Show resolved Hide resolved
packages/gatsby/src/services/initialize.ts Show resolved Hide resolved
packages/gatsby/src/services/post-bootstrap.ts Outdated Show resolved Hide resolved
@ascorbic
Copy link
Contributor Author

@pvdz Thanks for the detailed review! Regarding that activity stuff, yes it is annoying to have all that boilerplate, though I'm not sure how much shorter it would be if I abstracted it: I'd only really be able to remove the explicit start() call, as everything else would still need passing in, and it would still need stopping. Any ideas for a cleaner way?

@wardpeet
Copy link
Contributor

@pdvz Let's not refactor activities. I like the verbosity of it + we might need to think about another way in the future for this. In state machine land these could be side effects

wardpeet
wardpeet previously approved these changes Jun 19, 2020
pvdz
pvdz previously approved these changes Jun 19, 2020
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

🚀

@ascorbic ascorbic added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Jun 19, 2020
@gatsbybot gatsbybot merged commit a78c7b0 into master Jun 19, 2020
@ascorbic ascorbic deleted the chore/bootstrap-refactor branch June 19, 2020 13:17
@@ -15,14 +16,15 @@ export interface IProgram {
port: number
proxyPort: number
host: string
report: typeof reporter
report: Reporter
Copy link
Contributor

Choose a reason for hiding this comment

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

somehow this reverts this PR:

-  report: Reporter
+  report: typeof reporter

was this intended?

//cc @tgallacher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes status: needs core review Currently awaiting review from Core team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants