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

Move buildTime into new node type #21827

Merged
merged 4 commits into from
Mar 2, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
})

// Add site node.
const buildTime = moment()
.subtract(process.uptime(), `seconds`)
.toJSON()

const createGatsbyConfigNode = (config = {}) => {
// Delete plugins from the config as we add plugins above.
Expand All @@ -93,7 +90,6 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
port: state.program.port,
host: state.program.host,
...configCopy,
buildTime,
}
createNode({
...node,
Expand All @@ -109,6 +105,22 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {

createGatsbyConfigNode(state.config)

const buildTime = moment()
.subtract(process.uptime(), `seconds`)
.startOf(`second`)
.toJSON()

createNode({
id: `SiteBuildTime`,
parent: null,
children: [],
buildTime,
internal: {
contentDigest: createContentDigest(buildTime),
type: `SiteBuildTime`,
ascorbic marked this conversation as resolved.
Show resolved Hide resolved
},
})

const pathToGatsbyConfig = systemPath.join(
program.directory,
`gatsby-config.js`
Expand All @@ -129,6 +141,24 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
})
}

exports.createResolvers = ({ createResolvers }) => {
const resolvers = {
Site: {
buildTime: {
vladar marked this conversation as resolved.
Show resolved Hide resolved
type: `Date`,
resolve(source, args, context, info) {
ascorbic marked this conversation as resolved.
Show resolved Hide resolved
const buildNode = context.nodeModel.getNodeById({
id: `SiteBuildTime`,
type: `SiteBuildTime`,
})
return buildNode.buildTime
},
},
},
}
createResolvers(resolvers)
}

exports.onCreatePage = ({ createContentDigest, page, actions }) => {
const { createNode } = actions
// eslint-disable-next-line
Expand Down