File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -52,10 +52,10 @@ function getOperationName (query) {
52
52
* @param {?Record<string, *> } variables - GraphQL query variables
53
53
* @returns {*|Promise<*> } GraphQL response
54
54
*/
55
- function getGraphQLQueryResponse ( operationName , variables ) {
55
+ async function getGraphQLQueryResponse ( operationName , variables ) {
56
56
const res = data [ operationName ] || { }
57
57
if ( typeof res === 'function' ) {
58
- return res ( variables )
58
+ return await res ( variables )
59
59
}
60
60
return res
61
61
}
@@ -67,12 +67,24 @@ function getGraphQLQueryResponse (operationName, variables) {
67
67
* @param {* } request - Express HTTP GraphQL request
68
68
* @returns {*|Promise<*> } GraphQL response
69
69
*/
70
- function handleGraphQLRequest ( request ) {
70
+ async function handleGraphQLRequest ( request ) {
71
71
const isSchemaQuery = request . body . query . includes ( '__schema' )
72
72
const operationName = isSchemaQuery
73
73
? 'IntrospectionQuery'
74
74
: getOperationName ( request . body . query )
75
- return getGraphQLQueryResponse ( operationName , request . body . variables )
75
+ try {
76
+ return await getGraphQLQueryResponse ( operationName , request . body . variables )
77
+ } catch ( err ) {
78
+ console . error ( err )
79
+ return {
80
+ errors : [ {
81
+ message : err . message ,
82
+ extensions : {
83
+ stacktrace : err . stack . split ? err . stack . split ( '\n' ) : err . stack ,
84
+ } ,
85
+ } ] ,
86
+ }
87
+ }
76
88
}
77
89
78
90
module . exports = {
You can’t perform that action at this time.
0 commit comments