Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into validation-extensions
- Loading branch information
Showing
15 changed files
with
769 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/CustomGraphQLClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2021 Netflix, 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.netflix.graphql.dgs.client | ||
|
||
/** | ||
* Blocking implementation of a GraphQL client. | ||
* The user is responsible for doing the actual HTTP request, making this pluggable with any HTTP client. | ||
* For a more convenient option, use [WebClientGraphQLClient] instead. | ||
*/ | ||
class CustomGraphQLClient(private val url: String, private val requestExecutor: RequestExecutor) : GraphQLClient { | ||
override fun executeQuery(query: String): GraphQLResponse { | ||
return executeQuery(query, emptyMap(), null) | ||
} | ||
|
||
override fun executeQuery(query: String, variables: Map<String, Any>): GraphQLResponse { | ||
return executeQuery(query, variables, null) | ||
} | ||
|
||
override fun executeQuery(query: String, variables: Map<String, Any>, operationName: String?): GraphQLResponse { | ||
val serializedRequest = GraphQLClients.objectMapper.writeValueAsString( | ||
Request( | ||
query, | ||
variables, | ||
operationName | ||
) | ||
) | ||
|
||
val response = requestExecutor.execute(url, GraphQLClients.defaultHeaders, serializedRequest) | ||
return GraphQLClients.handleResponse(response, serializedRequest, url) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/CustomMonoGraphQLClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2021 Netflix, 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.netflix.graphql.dgs.client | ||
|
||
import reactor.core.publisher.Mono | ||
|
||
/** | ||
* Non-blocking implementation of a GraphQL client, based on the [Mono] type. | ||
* The user is responsible for doing the actual HTTP request, making this pluggable with any HTTP client. | ||
* For a more convenient option, use [WebClientGraphQLClient] instead. | ||
*/ | ||
class CustomMonoGraphQLClient(private val url: String, private val monoRequestExecutor: MonoRequestExecutor) : MonoGraphQLClient { | ||
override fun reactiveExecuteQuery(query: String): Mono<GraphQLResponse> { | ||
return reactiveExecuteQuery(query, emptyMap(), null) | ||
} | ||
|
||
override fun reactiveExecuteQuery(query: String, variables: Map<String, Any>): Mono<GraphQLResponse> { | ||
return reactiveExecuteQuery(query, variables, null) | ||
} | ||
|
||
override fun reactiveExecuteQuery( | ||
query: String, | ||
variables: Map<String, Any>, | ||
operationName: String? | ||
): Mono<GraphQLResponse> { | ||
val serializedRequest = GraphQLClients.objectMapper.writeValueAsString( | ||
Request( | ||
query, | ||
variables, | ||
operationName | ||
) | ||
) | ||
return monoRequestExecutor.execute(url, GraphQLClients.defaultHeaders, serializedRequest).map { response -> | ||
GraphQLClients.handleResponse(response, serializedRequest, url) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.