-
Notifications
You must be signed in to change notification settings - Fork 2k
Logging support #402
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
Logging support #402
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
*/ | ||
|
||
export { execute } from './execute'; | ||
export { TAG } from './logging'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* @flow */ | ||
/** | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
export const TAG = { | ||
SUBTREE_START: 'SUBTREE_START', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't a |
||
SUBTREE_END: 'SUBTREE_END', | ||
SUBTREE_ERROR: 'SUBTREE_ERROR', | ||
RESOLVER_START: 'RESOLVER_START', | ||
RESOLVER_END: 'RESOLVER_END', | ||
RESOLVER_ERROR: 'RESOLVER_ERROR', | ||
}; | ||
|
||
export type GraphQLLoggingTagType = $Keys<typeof TAG>; // eslint-disable-line | ||
|
||
export function passThroughResultAndLog( | ||
logFn: any, | ||
tag: GraphQLLoggingTagType, | ||
payload: any, | ||
info: any | ||
): any { | ||
return function (result) { | ||
logFn(tag, payload, info); | ||
return result; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,14 +39,19 @@ import type { GraphQLSchema } from './type/schema'; | |
* The name of the operation to use if requestString contains multiple | ||
* possible operations. Can be omitted if requestString contains only | ||
* one operation. | ||
* logFn: | ||
* The function that is called with a tag of an event, an event payload | ||
* and other execution information. | ||
* The examples include: errors thrown, before and after the resolver call. | ||
*/ | ||
export function graphql( | ||
schema: GraphQLSchema, | ||
requestString: string, | ||
rootValue?: mixed, | ||
contextValue?: mixed, | ||
variableValues?: ?{[key: string]: mixed}, | ||
operationName?: ?string | ||
operationName?: ?string, | ||
logFn?: (tag: string, payload: mixed, info: mixed) => void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like there are two main cases that this PR will need to account for:
Timings Inspection |
||
): Promise<GraphQLResult> { | ||
return new Promise(resolve => { | ||
const source = new Source(requestString || '', 'GraphQL request'); | ||
|
@@ -62,7 +67,8 @@ export function graphql( | |
rootValue, | ||
contextValue, | ||
variableValues, | ||
operationName | ||
operationName, | ||
logFn | ||
) | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,7 @@ export { | |
// Execute GraphQL queries. | ||
export { | ||
execute, | ||
TAG | ||
} from './execution'; | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of logging
RESOLVER_ERROR
orSUBTREE_ERROR
if you've already got theexeContext.errors
Array?