Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename GraphQLExecutor to AbstractGraphQLExecutor #149

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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