Skip to content

Instantly share code, notes, and snippets.

@clayallsopp
Last active April 12, 2016 04:21
Show Gist options
  • Save clayallsopp/b7114aee0d31357433f50d876473316d to your computer and use it in GitHub Desktop.
Save clayallsopp/b7114aee0d31357433f50d876473316d to your computer and use it in GitHub Desktop.
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