Skip to content

Commit 04723de

Browse files
committed
Improve error handling for the graphql function. This only returns the
formatted errors for GraphQLError, which are effectively pseudo-control-flow and part of expected execution. If it is another error, we assume it is *programmer error* and rethrow so we get a reasonable error message
1 parent 40e7806 commit 04723de

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/graphql.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { execute } from './executor/executor';
1515
import { formatError } from './error';
1616
import type { GraphQLFormattedError } from './error/formatError';
1717
import type { GraphQLSchema } from './type/schema';
18-
18+
import { GraphQLError } from './error/GraphQLError';
1919

2020
/**
2121
* This is the primary entry point function for fulfilling GraphQL operations
@@ -61,6 +61,9 @@ export function graphql(
6161
);
6262
}
6363
}).catch(error => {
64+
if (!(error instanceof GraphQLError)) {
65+
throw error;
66+
}
6467
return { errors: [ formatError(error) ] };
6568
});
6669
}

0 commit comments

Comments
 (0)