Skip to content

Commit 7cc8561

Browse files
committed
Move resover information resolution to plugin.
1 parent d9e6ce3 commit 7cc8561

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

packages/datadog-instrumentations/src/graphql.js

+2-34
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,11 @@ function assertField (context, info, args) {
275275
accesses the parent span from the storage unit in its own scope */
276276
const childResource = new AsyncResource('bound-anonymous-fn')
277277

278-
addResolver(context, info, args)
279-
280278
childResource.runInAsyncScope(() => {
281279
startResolveCh.publish({
282280
info,
283-
context
281+
context,
282+
args
284283
})
285284
})
286285

@@ -344,37 +343,6 @@ function wrapFieldType (field) {
344343
wrapFields(unwrappedType)
345344
}
346345

347-
function addResolver (context, info, args) {
348-
context.resolver = null
349-
350-
const resolverInfo = {}
351-
352-
if (args && Object.keys(args).length) {
353-
Object.assign(resolverInfo, args)
354-
}
355-
356-
const directives = info.fieldNodes[0].directives
357-
for (const directive of directives) {
358-
const argList = {}
359-
for (const argument of directive['arguments']) {
360-
const arg = {}
361-
arg[argument.name.value] = argument.value.value
362-
Object.assign(argList, arg)
363-
}
364-
365-
if (Object.keys(argList).length) {
366-
const directiveInfo = {}
367-
directiveInfo[directive.name.value] = argList
368-
Object.assign(resolverInfo, directiveInfo)
369-
}
370-
}
371-
372-
if (Object.keys(resolverInfo).length) {
373-
context.resolver = {}
374-
context.resolver[info.fieldName] = resolverInfo
375-
}
376-
}
377-
378346
function finishResolvers ({ fields }) {
379347
Object.keys(fields).reverse().forEach(key => {
380348
const field = fields[key]

packages/datadog-plugin-graphql/src/resolve.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ class GraphQLResolvePlugin extends TracingPlugin {
88
static get id () { return 'graphql' }
99
static get operation () { return 'resolve' }
1010

11-
start ({ info, context }) {
11+
start ({ info, context, args }) {
1212
const path = getPath(info, this.config)
1313

1414
if (!shouldInstrument(this.config, path)) return
1515
const computedPathString = path.join('.')
1616

17+
addResolver(context, info, args)
18+
1719
if (this.config.collapse) {
1820
if (!context[collapsedPathSym]) {
1921
context[collapsedPathSym] = {}
@@ -107,4 +109,36 @@ function withCollapse (responsePathAsArray) {
107109
}
108110
}
109111

112+
function addResolver (context, info, args) {
113+
context.resolver = null
114+
115+
const resolverInfo = {}
116+
117+
if (args && Object.keys(args).length) {
118+
Object.assign(resolverInfo, args)
119+
}
120+
121+
const directives = info.fieldNodes[0].directives
122+
for (const directive of directives) {
123+
const argList = {}
124+
for (const argument of directive['arguments']) {
125+
const arg = {}
126+
arg[argument.name.value] = argument.value.value
127+
Object.assign(argList, arg)
128+
}
129+
130+
if (Object.keys(argList).length) {
131+
const directiveInfo = {}
132+
directiveInfo[directive.name.value] = argList
133+
Object.assign(resolverInfo, directiveInfo)
134+
}
135+
}
136+
137+
if (Object.keys(resolverInfo).length) {
138+
context.resolver = {}
139+
context.resolver[info.fieldName] = resolverInfo
140+
}
141+
}
142+
143+
110144
module.exports = GraphQLResolvePlugin

0 commit comments

Comments
 (0)