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

[WIP] feat(gatsby): worker-pool for custom GraphQL field resolvers #10938

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f5c4334
first shot at parallel workers
Moocar Dec 18, 2018
f4d816c
stuff
Moocar Dec 18, 2018
7b3fca9
async getNode
Moocar Dec 18, 2018
25a524d
asyncPlugin
Moocar Dec 18, 2018
e6beb71
fix pluginFields
Moocar Dec 18, 2018
aef1e43
use jest-worker for IPC
Moocar Dec 19, 2018
8596eda
remove console.logs
Moocar Dec 19, 2018
e7cbeac
jest workers work!
Moocar Dec 19, 2018
6863ca8
Merge branch 'master' into parallel-sketch
Moocar Jan 8, 2019
242420c
store resolvers against their type, not just fieldName
Moocar Jan 8, 2019
a7559d5
fixed up rpc api
Moocar Jan 8, 2019
fa5ec9f
replace isAsync with workerPlugin
Moocar Jan 8, 2019
3cf872e
document jest-worker IPC code 3 in async/worker code
Moocar Jan 8, 2019
1508298
change async-resolvers -> worker-resolvers
Moocar Jan 8, 2019
a889664
error checking
Moocar Jan 8, 2019
38e0370
resolver-worker docs and error checking
Moocar Jan 8, 2019
70e7aaa
docs
Moocar Jan 9, 2019
c5655ec
use @moocar/jest-worker
Moocar Jan 9, 2019
a77c1d4
yarn.lock for @moocar/jest-worker
Moocar Jan 9, 2019
7a86ee1
end worker pool after bootstrap
Moocar Jan 9, 2019
f629eaa
Merge branch 'master' into parallel-sketch
Moocar Jan 9, 2019
6767039
introduce getCache mocker
Moocar Jan 9, 2019
d50efb2
fix unsupported properties, and general cleanup
Moocar Jan 9, 2019
21d5aba
use plugin.name for cache in resolver-worker
Moocar Jan 11, 2019
98fbec2
Merge branch 'master' into parallel-sketch
Moocar Jan 21, 2019
15099d3
Merge branch 'master' into parallel-sketch
Moocar Jan 30, 2019
61b0168
Merge branch 'master' into parallel-sketch
Moocar Feb 4, 2019
0aca069
step.toString() in markdown benchmark
Moocar Feb 5, 2019
21bfc69
Merge branch 'master' into parallel-sketch
Moocar Feb 12, 2019
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
Prev Previous commit
Next Next commit
store resolvers against their type, not just fieldName
  • Loading branch information
Moocar committed Jan 8, 2019
commit 242420ce384b431ea452dd45619bbb87652d35cf
4 changes: 2 additions & 2 deletions packages/gatsby/src/schema/async-resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ function add(field) {
fields.push(field)
}

function workerResolver({ fieldName }) {
function workerResolver({ typeName, fieldName }) {
return async (node, args) => {
try {
return await pool.execResolver(fieldName, node, args)
return await pool.execResolver(typeName, fieldName, node, args)
} catch (e) {
console.log(e)
return null
Expand Down
22 changes: 17 additions & 5 deletions packages/gatsby/src/schema/resolver-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const uuidv4 = require(`uuid/v4`)
const Cache = require(`../utils/cache`)
const _ = require(`lodash`)

const resolvers = {}
const types = {}
const rpcs = new Map()

function handleRpcResponse(rpc) {
Expand Down Expand Up @@ -94,6 +94,10 @@ function makeRpcs() {
}
}

function storeResolver(typeName, fieldName, fieldConfig) {
_.set(types, [typeName, `fields`, fieldName], fieldConfig)
}

async function initModule({
fieldName,
resolverFile,
Expand All @@ -107,8 +111,8 @@ async function initModule({
const cache = new Cache({ name: `some cache` }).init()
const api = { type, pathPrefix, cache, ...makeRpcs() }
const newFields = await module.setFieldsOnGraphQLNodeType(api, pluginOptions)
_.forEach(newFields, (v, k) => {
resolvers[k] = v.resolve
_.forEach(newFields, (fieldConfig, fieldName) => {
storeResolver(type.name, fieldName, fieldConfig)
})
}

Expand All @@ -120,9 +124,17 @@ async function setup(args) {
}
}

async function execResolver(resolver, node, args) {
async function execResolver(typeName, fieldName, node, args) {
try {
return await resolvers[resolver](node, args)
invariant(typeName, `execResolver typeName`)
invariant(fieldName, `execResolver fieldName`)
const type = types[typeName]
invariant(type, `execResolver type`)
const field = type.fields[fieldName]
invariant(field, `execResolver field`)
const resolver = field.resolve
invariant(resolver, `execResolver resolver`)
return await resolver(node, args)
} catch (e) {
console.log(e)
return null
Expand Down