-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Conversation
import { Runner } from "./create-graphql-runner" | ||
import { writeOutRedirects } from "../services/write-out-redirects" | ||
import { postBootstrap } from "../services/post-bootstrap" | ||
import { rebuildWithSitePage } from "../schema" |
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 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?
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.
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.
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.
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
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({ |
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.
@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.
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.
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 :)
} | ||
|
||
module.exports = async (args: BootstrapArgs) => { | ||
const spanArgs = args.parentSpan ? { childOf: args.parentSpan } : {} |
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.
I presume this childOf
stuff is not relevant anymore?
Co-authored-by: Peter van der Zee <209817+pvdz@users.noreply.github.com>
@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 |
@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 |
… into chore/bootstrap-refactor
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.
🚀
@@ -15,14 +16,15 @@ export interface IProgram { | |||
port: number | |||
proxyPort: number | |||
host: string | |||
report: typeof reporter | |||
report: Reporter |
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.
somehow this reverts this PR:
- refactor(gatsby): convert program reducer to typescript #24941
refactor(gatsby): convert program reducer to typescript
- report: Reporter
+ report: typeof reporter
was this intended?
//cc @tgallacher
This splits the
bootstrap
command into smaller parts, which it imports from services. A lot of this is in theinitialize
service, which is mostly a direct TypeScript port from the relevant section of the old bootstrap file.The services that this PR includes are: