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

feat: afterSourcesLoaded hook #1497

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions gridsome/lib/app/PluginAPI.js
Expand Up @@ -49,6 +49,10 @@ class PluginAPI {
this._on('loadSource', handler)
}

afterLoadSources (handler) {
this._on('afterLoadSources', handler)
}

createSchema (handler) {
this._on('createSchema', handler)
}
Expand Down
27 changes: 21 additions & 6 deletions gridsome/lib/app/Plugins.js
Expand Up @@ -26,8 +26,13 @@ class Plugins {
)

app.hooks.bootstrap.tapPromise(
{ name: 'createSchema', label: 'Create GraphQL schema', phase: BOOTSTRAP_GRAPHQL },
() => this.createSchema()
{name: 'afterLoadSources', label: 'After sources loaded', phase: BOOTSTRAP_SOURCES},
() => this.afterLoadSources()
)

app.hooks.bootstrap.tapPromise(
{name: 'createSchema', label: 'Create GraphQL schema', phase: BOOTSTRAP_GRAPHQL},
() => this.createSchema()
)

app.hooks.bootstrap.tapPromise(
Expand Down Expand Up @@ -81,10 +86,20 @@ class Plugins {
})
}

async createSchema() {
const results = await this.run('createSchema', api => {
return createSchemaActions(api, this._app)
})
/**
*
* @returns {Promise<[]|*[]>}
*/
async afterLoadSources() {
return this.run('afterSourcesLoaded', api => {
return createSchemaActions(api, this._app)
})
}

async createSchema() {
const results = await this.run('createSchema', api => {
return createSchemaActions(api, this._app)
})

// add custom schemas returned from the hook handlers
results.forEach(schema =>
Expand Down