From 49d0ce42ff0b09d0a51549fa24fac14890d5656b Mon Sep 17 00:00:00 2001 From: Andreas Berger Date: Wed, 17 Nov 2021 12:14:13 +0100 Subject: [PATCH] Use error whitelist instead of blacklist to cover all yet unknown errors (#256) --- .../kotlin/org/neo4j/graphql/Translator.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/main/kotlin/org/neo4j/graphql/Translator.kt b/core/src/main/kotlin/org/neo4j/graphql/Translator.kt index fce47922..cf866cc0 100644 --- a/core/src/main/kotlin/org/neo4j/graphql/Translator.kt +++ b/core/src/main/kotlin/org/neo4j/graphql/Translator.kt @@ -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) { @@ -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) } }