Skip to content
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
1 change: 1 addition & 0 deletions expediagroup-sdk-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

testImplementation 'io.mockk:mockk:1.14.5'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
Expand Down
3 changes: 2 additions & 1 deletion expediagroup-sdk-graphql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
testImplementation platform('org.junit:junit-bom:5.13.3')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'io.mockk:mockk:1.14.5'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
Expand Down Expand Up @@ -76,7 +77,7 @@ kover {
bound {
aggregationForGroup = AggregationType.COVERED_PERCENTAGE
coverageUnits = CoverageUnit.BRANCH
minValue = 92
minValue = 83
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import com.apollographql.apollo.api.ApolloResponse
import com.apollographql.apollo.api.Error
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.api.composeJsonRequest
import com.apollographql.apollo.api.http.HttpHeader
import com.apollographql.apollo.api.json.buildJsonString
import com.apollographql.apollo.api.json.jsonReader
import com.apollographql.apollo.api.parseResponse
import com.apollographql.apollo.exception.ApolloHttpException
import com.expediagroup.sdk.core.http.CommonMediaTypes
import com.expediagroup.sdk.core.http.Method
import com.expediagroup.sdk.core.http.Request
Expand Down Expand Up @@ -52,6 +54,18 @@ fun <D : Operation.Data> Operation<D>.toSDKRequest(url: String): Request {
}

fun <D : Operation.Data> Response.toApolloResponse(operation: Operation<D>): ApolloResponse<D> {
if (status.code != 200) {
return ApolloResponse.Builder(operation, request.id)
.exception(
ApolloHttpException(
statusCode = status.code,
headers = headers.entries().map { HttpHeader(it.key, it.value.toString()) },
message = "Received non 200 response from the GraphQL server",
body = this.body?.source()?.buffer
)
).build()
}

val apolloResponse =
this.body?.let {
val jsonReader = it.source().buffer.jsonReader()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.adapter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.adapter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.schema

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.selections

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.selections

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

import com.apollographql.apollo.api.BuilderFactory
import com.apollographql.apollo.api.BuilderScope
import com.apollographql.apollo.api.CustomScalarAdapters
import com.apollographql.apollo.api.DataBuilderDsl
import com.apollographql.apollo.api.ObjectBuilder
import com.apollographql.apollo.api.ObjectType
import kotlin.Any
Expand All @@ -23,6 +24,7 @@ public class Mutation {
}
}

@DataBuilderDsl
public class MutationBuilder(
customScalarAdapters: CustomScalarAdapters,
) : ObjectBuilder<MutationMap>(customScalarAdapters) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

import com.apollographql.apollo.api.BuilderFactory
import com.apollographql.apollo.api.BuilderScope
import com.apollographql.apollo.api.CustomScalarAdapters
import com.apollographql.apollo.api.DataBuilderDsl
import com.apollographql.apollo.api.ObjectBuilder
import com.apollographql.apollo.api.ObjectType
import kotlin.Any
Expand All @@ -23,6 +24,7 @@ public class Query {
}
}

@DataBuilderDsl
public class QueryBuilder(
customScalarAdapters: CustomScalarAdapters,
) : ObjectBuilder<QueryMap>(customScalarAdapters) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

import com.apollographql.apollo.api.BuilderFactory
import com.apollographql.apollo.api.BuilderScope
import com.apollographql.apollo.api.CustomScalarAdapters
import com.apollographql.apollo.api.DataBuilderDsl
import com.apollographql.apollo.api.ObjectBuilder
import com.apollographql.apollo.api.ObjectType
import kotlin.Any
Expand All @@ -23,6 +24,7 @@ public class TestData {
}
}

@DataBuilderDsl
public class TestDataBuilder(
customScalarAdapters: CustomScalarAdapters,
) : ObjectBuilder<TestDataMap>(customScalarAdapters) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL version '4.1.1'.
// This class was automatically generated by Apollo GraphQL version '4.3.1'.
//
package testservice.type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.expediagroup.sdk.graphql

import com.apollographql.apollo.api.toResponseJson
import com.apollographql.apollo.exception.ApolloHttpException
import com.expediagroup.sdk.core.http.CommonMediaTypes
import com.expediagroup.sdk.core.http.Method
import com.expediagroup.sdk.core.http.Protocol
Expand All @@ -13,6 +14,7 @@ import okio.Buffer
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertInstanceOf
import testservice.TestMutation
import testservice.TestQuery
import testservice.type.buildTestData
Expand Down Expand Up @@ -83,4 +85,23 @@ class ApolloOperationExtensionTest {
assertEquals("Failed to parse response with null body", apolloResponse.errors?.get(0)?.message)
assertNull(apolloResponse.data)
}

@Test
fun `toApolloResponse should populate exception when the response status is not 200`() {
// Given
val testSDKResponse =
Response.builder()
.status(Status.INTERNAL_SERVER_ERROR)
.protocol(Protocol.HTTP_1_1)
.request(mockk { every { id } returns UUID.randomUUID() })
.build()

// When
val apolloResponse = testSDKResponse.toApolloResponse(TestMutation())

// Expect
assertInstanceOf<ApolloHttpException>(apolloResponse.exception)
assertNull(apolloResponse.data)
assertNull(apolloResponse.errors)
}
}
1 change: 1 addition & 0 deletions expediagroup-sdk-rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

testImplementation 'io.mockk:mockk:1.14.5'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
Expand Down
1 change: 1 addition & 0 deletions expediagroup-sdk-transport-okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

testImplementation 'io.mockk:mockk:1.14.5'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
Expand Down