Skip to content

Commit

Permalink
Use error whitelist instead of blacklist to cover all yet unknown err…
Browse files Browse the repository at this point in the history
…ors (#256)
  • Loading branch information
Andy2003 authored Nov 17, 2021
1 parent e783d04 commit 49d0ce4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/src/main/kotlin/org/neo4j/graphql/Translator.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.neo4j.graphql

import graphql.ExceptionWhileDataFetching
import graphql.ExecutionInput
import graphql.GraphQL
import graphql.InvalidSyntaxError
import graphql.*
import graphql.execution.NonNullableFieldWasNullError
import graphql.schema.GraphQLSchema
import graphql.validation.ValidationError

class Translator(val schema: GraphQLSchema) {

Expand All @@ -27,8 +24,15 @@ class Translator(val schema: GraphQLSchema) {
result.errors?.forEach {
when (it) {
is ExceptionWhileDataFetching -> throw it.exception
is ValidationError -> throw InvalidQueryException(it)
is InvalidSyntaxError -> throw InvalidQueryException(it)

is TypeMismatchError, // expected since we return cypher here instead of the correct json
is NonNullableFieldWasNullError, // expected since the returned cypher does not match the shape of the graphql type
is SerializationError // expected since the returned cypher does not match the shape of the graphql type
-> {
// ignore
}
// generic error handling
is GraphQLError -> throw InvalidQueryException(it)
}
}

Expand Down

0 comments on commit 49d0ce4

Please sign in to comment.