From 2418854730bb76c25e6f0fb5746fcadefbd15310 Mon Sep 17 00:00:00 2001 From: Bernardo Gomez Palacio Date: Fri, 15 Oct 2021 10:48:38 -0700 Subject: [PATCH] Introduce a CONFLICT error catered to mutations. Indicates the operation conflicts with the current state of the target resource. Conflicts are most likely to occur in the context of a mutation. For example, you may get a CONFLICT when writing a field with a reference value that is older than the one already on the server, resulting in a version control conflict. HTTP Mapping: 409 Conflict. Error Type: FAILED_PRECONDITION --- .../com/netflix/graphql/types/errors/ErrorDetail.java | 11 +++++++++++ .../graphql/types/errors/TypedGraphQLError.java | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/ErrorDetail.java b/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/ErrorDetail.java index 4d17ca62b..687690c66 100644 --- a/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/ErrorDetail.java +++ b/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/ErrorDetail.java @@ -121,6 +121,17 @@ enum Common implements ErrorDetail { */ MISSING_RESOURCE(FAILED_PRECONDITION), + /** + * Indicates the operation conflicts with the current state of the target resource. + * Conflicts are most likely to occur in the context of a mutation. + *

+ * For example, you may get a CONFLICT when writing a field with a reference value that is + * older than the one already on the server, resulting in a version control conflict. + *

+ * HTTP Mapping: 409 Conflict. + * Error Type: FAILED_PRECONDITION + */ + CONFLICT(FAILED_PRECONDITION), /** * Service Error. diff --git a/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/TypedGraphQLError.java b/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/TypedGraphQLError.java index 6981e639c..2355a8033 100644 --- a/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/TypedGraphQLError.java +++ b/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/TypedGraphQLError.java @@ -226,6 +226,13 @@ public static Builder newBadRequestBuilder() { return new Builder().errorType(ErrorType.BAD_REQUEST); } + /** + * Create new Builder instance to further customize an error that results in a {@link ErrorDetail.Common#CONFLICT conflict}. + * @return A new TypedGraphQLError.Builder instance to further customize the error. Pre-sets {@link ErrorDetail.Common#CONFLICT}. + */ + public static Builder newConflictBuilder() { + return new Builder().errorDetail(ErrorDetail.Common.CONFLICT); + } @Override public String toString() {