Last active
April 12, 2016 04:21
-
-
Save clayallsopp/b7114aee0d31357433f50d876473316d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resolveWithInstrumentation = (resolve) => { | |
return (source, args, context, info) => { | |
const directives = info.fieldASTs[0].directives; | |
const instrumentDirective = directives.filter(d => d.name.value === InstrumentDirective.name)[0]; | |
if (!instrumentDirective) { | |
return resolve(source, args, context, info); | |
} | |
const start = new Date(); | |
return Promise.resolve(resolve(source, args, context, info)).then((result) => { | |
const diff = (new Date() - start); | |
const tag = instrumentDirective.arguments[0].value.value; | |
console.log(`Instrumented ${tag} @ ${diff}ms`) | |
return result; | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment