Skip to content

Commit

Permalink
fix: rename GraphQLExecutor to AbstractGraphQLExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Dwairi committed Dec 24, 2024
1 parent 858df2d commit 31b6a58
Show file tree
Hide file tree
Showing 33 changed files with 325 additions and 325 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.expediagroup.sdk.graphql.common

import com.apollographql.apollo.api.Mutation
import com.apollographql.apollo.api.Query
import com.apollographql.java.client.ApolloClient
import com.expediagroup.sdk.core.client.Disposable
import com.expediagroup.sdk.core.client.AbstractRequestExecutor
import com.expediagroup.sdk.core.model.exception.service.ExpediaGroupServiceException
import com.expediagroup.sdk.graphql.model.exception.NoDataException
import com.expediagroup.sdk.graphql.model.response.RawResponse
import java.util.concurrent.CompletableFuture

/**
* Abstract base class for executing GraphQL operations, providing a structure for executing queries and mutations
* and returning the full response data along with any errors.
*
* This class is designed to handle the execution of GraphQL operations and return a [RawResponse] containing
* the complete, unprocessed data and error details. Subclasses should implement specific behaviors for how
* requests are sent and processed.
*/
abstract class AbstractGraphQLExecutor(
private val requestExecutor: AbstractRequestExecutor
) : Disposable {

/**
* The Apollo Client instance used to perform GraphQL requests.
* Subclasses must initialize this property with a configured [ApolloClient] instance.
*/
protected abstract val apolloClient: ApolloClient

/**
* Executes a GraphQL query and returns the complete raw response.
*
* @param query The GraphQL query to be executed.
* @return A [RawResponse] containing the full data and any errors from the query response.
* @throws [ExpediaGroupServiceException] If an exception occurs during the execution of the query.
* @throws [NoDataException] If the query completes without data but includes errors.
*/
abstract fun <T : Query.Data> execute(query: Query<T>): RawResponse<T>

/**
* Executes a GraphQL mutation and returns the complete raw response.
*
* @param mutation The GraphQL mutation to be executed.
* @return A [RawResponse] containing the full data and any errors from the mutation response.
* @throws [ExpediaGroupServiceException] If an exception occurs during the execution of the mutation.
* @throws [NoDataException] If the mutation completes without data but includes errors.
*/
abstract fun <T : Mutation.Data> execute(mutation: Mutation<T>): RawResponse<T>

/**
* Asynchronously executes a GraphQL query and returns the complete raw response in a [CompletableFuture].
*
* @param query The GraphQL query to be executed.
* @return A [CompletableFuture] containing the full data and any errors from the query response wrapped in [RawResponse].
* @throws [ExpediaGroupServiceException] If an exception occurs during the execution of the query.
* @throws [NoDataException] If the query completes without data but includes errors.
*/
abstract fun <T : Query.Data> executeAsync(query: Query<T>): CompletableFuture<RawResponse<T>>

/**
* Asynchronously executes a GraphQL mutation and returns the complete raw response in a [CompletableFuture].
*
* @param mutation The GraphQL mutation to be executed.
* @return A [CompletableFuture] containing the full data and any errors from the mutation response wrapped in [RawResponse].
* @throws [ExpediaGroupServiceException] If an exception occurs during the execution of the mutation.
* @throws [NoDataException] If the mutation completes without data but includes errors.
*/
abstract fun <T : Mutation.Data> executeAsync(mutation: Mutation<T>): CompletableFuture<RawResponse<T>>

/**
* Closes the underlying [AbstractRequestExecutor] and [ApolloClient]
*/
override fun dispose() {
requestExecutor.dispose()
apolloClient.close()
}
}

This file was deleted.

Loading

0 comments on commit 31b6a58

Please sign in to comment.