index int64 0 0 | repo_id stringlengths 26 205 | file_path stringlengths 51 246 | content stringlengths 8 433k | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/dgs-framework/graphql-dgs-reactive/src/main/java/com/netflix/graphql/dgs | Create_ds/dgs-framework/graphql-dgs-reactive/src/main/java/com/netflix/graphql/dgs/reactive/DgsReactiveQueryExecutor.java | /*
* 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.reactive;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.TypeRef;
import graphql.ExecutionResult;
import org.intellij.lang.annotations.Language;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.server.ServerRequest;
import reactor.core.publisher.Mono;
import java.util.Collections;
import java.util.Map;
/**
* Represents the core query executing capability of the framework.
* This is the reactive version of the interface, using {@link Mono} for its results.
* See {@link com.netflix.graphql.dgs.DgsQueryExecutor} for the blocking version of this interface.
* Use this interface to easily execute GraphQL queries, without using the HTTP endpoint.
* This is meant to be used in tests, and is also used internally in the framework.
* <p>
* The executeAnd* methods use the <a href="https://github.com/json-path/JsonPath">JsonPath library</a> library to easily get specific fields out of a nested Json structure.
* The {@link #executeAndGetDocumentContext(String)} method sets up a DocumentContext, which can then be reused to get multiple fields.
*
* @see <a href="https://netflix.github.io/dgs/query-execution-testing/">Query Execution Testing docs</a>
*/
public interface DgsReactiveQueryExecutor {
/**
* @param query The query string
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
*/
default Mono<ExecutionResult> execute(@Language("GraphQL") String query) {
return execute(query, null, null, null, null, null);
}
/**
* @param query The query string
* @param variables A map of variables
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
default Mono<ExecutionResult> execute(@Language("GraphQL") String query,
Map<String, Object> variables) {
return execute(query, variables, null, null, null, null);
}
/**
* @param query The query string
* @param variables A map of variables
* @param operationName The operation name
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://graphql.org/learn/queries/#operation-name">Operation name</a>
*/
default Mono<ExecutionResult> execute(@Language("GraphQL") String query,
Map<String, Object> variables,
String operationName) {
return execute(query, variables, null, null, operationName, null);
}
/**
* @param query The query string
* @param variables A map of variables
* @param extensions A map representing GraphQL extensions. This is made available in the
* {@link com.netflix.graphql.dgs.internal.DgsRequestData} object on
* {@link com.netflix.graphql.dgs.context.DgsContext}.
* @param headers Request headers represented as a Spring Framework {@link HttpHeaders}
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
default Mono<ExecutionResult> execute(@Language("GraphQL") String query,
Map<String, Object> variables,
Map<String, Object> extensions,
HttpHeaders headers) {
return execute(query, variables, extensions, headers, null, null);
}
/**
* Executes a GraphQL query. This method is used internally by all other methods in this interface.
*
* @param query The query string
* @param variables A map of variables
* @param extensions A map representing GraphQL extensions. This is made available in the {@link com.netflix.graphql.dgs.internal.DgsRequestData}
* object on {@link com.netflix.graphql.dgs.context.DgsContext}.
* @param headers Request headers represented as a Spring Framework {@link HttpHeaders}
* @param operationName Operation name
* @param serverRequest A Spring {@link ServerRequest} giving access to request details.
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://graphql.org/learn/queries/#operation-name">Operation name</a>
*/
Mono<ExecutionResult> execute(@Language("GraphQL") String query,
Map<String, Object> variables,
Map<String, Object> extensions,
HttpHeaders headers,
String operationName,
ServerRequest serverRequest);
/**
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify.
* This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)} instead.
* <p>
* This only works for primitive types and map representations.
* Use {@link #executeAndExtractJsonPathAsObject(String, String, Class)} for complex types and lists.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param <T> The type of primitive or map representation that should be returned.
* @return A Mono that might contain the resolved type.
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
default <T> Mono<T> executeAndExtractJsonPath(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath) {
return executeAndExtractJsonPath(query, jsonPath, Collections.emptyMap(), null);
}
/**
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify.
* This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)}instead.
* <p>
* This only works for primitive types and map representations.
* Use {@link #executeAndExtractJsonPathAsObject(String, String, Class)} for complex types and lists.*
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param serverRequest A Spring {@link ServerRequest} giving access to request details. *
* @param <T> The type of primitive or map representation that should be returned.
* @return A Mono that might contain the resolved type.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
<T> Mono<T> executeAndExtractJsonPath(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath,
Map<String, Object> variables,
ServerRequest serverRequest);
/**
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify.
* This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)}instead.
* <p>
* This only works for primitive types and map representations.
* Use {@link #executeAndExtractJsonPathAsObject(String, String, Class)} for complex types and lists.*
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param <T> The type of primitive or map representation that should be returned.
* @return A Mono that might contain the resolved type.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
default <T> Mono<T> executeAndExtractJsonPath(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath,
Map<String, Object> variables) {
return executeAndExtractJsonPath(query, jsonPath, variables, null);
}
/**
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify.
* This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)}instead.
* <p>
* This only works for primitive types and map representations.
* Use {@link #executeAndExtractJsonPathAsObject(String, String, Class)} for complex types and lists.*
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param serverRequest A Spring {@link ServerRequest} giving access to request details.
* @param <T> The type of primitive or map representation that should be returned.
* @return A Mono that might contain the resolved type.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
default <T> Mono<T> executeAndExtractJsonPath(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath,
ServerRequest serverRequest) {
return executeAndExtractJsonPath(query, jsonPath, null, serverRequest );
}
/**
* Executes a GraphQL query, parses the returned data, and return a {@link DocumentContext}.
* A {@link DocumentContext} can be used to extract multiple values using JsonPath, without re-executing the query.
*
* @param query GraphQL query string
* @return {@link DocumentContext} is a JsonPath type used to extract values from.
*/
default Mono<DocumentContext> executeAndGetDocumentContext(@Language("GraphQL") String query) {
return executeAndGetDocumentContext(query, Collections.emptyMap());
}
/**
* Executes a GraphQL query, parses the returned data, and return a {@link DocumentContext}.
* A {@link DocumentContext} can be used to extract multiple values using JsonPath, without re-executing the query.
*
* @param query GraphQL query string
* @param variables A Map of variables
* @return {@link DocumentContext} is a JsonPath type used to extract values from.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
Mono<DocumentContext> executeAndGetDocumentContext(@Language("GraphQL") String query,
Map<String, Object> variables);
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Be aware that this method can't guarantee type safety.
*
* @param query GraphQL query string
* @param jsonPath JsonPath expression.
* @param clazz The type to convert the extracted value to.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
default <T> Mono<T> executeAndExtractJsonPathAsObject(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath,
Class<T> clazz) {
return executeAndExtractJsonPathAsObject(query, jsonPath, Collections.emptyMap(), clazz);
}
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Be aware that this method can't guarantee type safety.
*
* @param query GraphQL query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param clazz The type to convert the extracted value to.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
<T> Mono<T> executeAndExtractJsonPathAsObject(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath,
Map<String, Object> variables,
Class<T> clazz);
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Uses a {@link TypeRef} to specify the expected type, which is useful for Lists and Maps.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param typeRef A JsonPath [TypeRef] representing the expected result type.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://github.com/json-path/JsonPath#what-is-returned-when">Using TypeRef</a>
*/
default <T> Mono<T> executeAndExtractJsonPathAsObject(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath,
TypeRef<T> typeRef) {
return executeAndExtractJsonPathAsObject(query, jsonPath, Collections.emptyMap(), typeRef);
}
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Uses a {@link TypeRef} to specify the expected type, which is useful for Lists and Maps.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param typeRef A JsonPath {@link TypeRef} representing the expected result type.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://github.com/json-path/JsonPath#what-is-returned-when">Using TypeRef</a>
*/
<T> Mono<T> executeAndExtractJsonPathAsObject(@Language("GraphQL") String query,
@Language("JSONPath") String jsonPath,
Map<String, Object> variables,
TypeRef<T> typeRef);
}
| 4,000 |
0 | Create_ds/dgs-framework/graphql-error-types/src/test/java/com/netflix/graphql/types | Create_ds/dgs-framework/graphql-error-types/src/test/java/com/netflix/graphql/types/errors/TypedGraphQLErrorTest.java | /*
* 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.types.errors;
import graphql.execution.ResultPath;
import graphql.language.SourceLocation;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.HashMap;
import java.util.stream.Stream;
public class TypedGraphQLErrorTest {
@Test
void equalsTest() {
TypedGraphQLError baseError = TypedGraphQLError.newPermissionDeniedBuilder()
.message("org.springframework.security.access.AccessDeniedException: Access is denied")
.path(ResultPath.parse("/graphqlEndpoint"))
.build();
TypedGraphQLError sameError = TypedGraphQLError.newPermissionDeniedBuilder()
.message("org.springframework.security.access.AccessDeniedException: Access is denied")
.path(ResultPath.parse("/graphqlEndpoint"))
.build();
Assertions.assertEquals(baseError, sameError);
}
@Test
void notEqualsTest() {
TypedGraphQLError baseError = TypedGraphQLError.newPermissionDeniedBuilder()
.message("org.springframework.security.access.AccessDeniedException: Access is denied")
.path(ResultPath.parse("/graphqlEndpoint"))
.build();
TypedGraphQLError differentMessageError = TypedGraphQLError.newPermissionDeniedBuilder()
.message("Different Error Message")
.path(ResultPath.parse("/graphqlEndpoint"))
.build();
Assertions.assertNotEquals(baseError, differentMessageError);
TypedGraphQLError differentLocationsError = TypedGraphQLError.newPermissionDeniedBuilder()
.message("Different Error Message")
.location(new SourceLocation(0, 0))
.path(ResultPath.parse("/graphqlEndpoint"))
.build();
Assertions.assertNotEquals(baseError, differentLocationsError);
TypedGraphQLError differentPathError = TypedGraphQLError.newPermissionDeniedBuilder()
.message("org.springframework.security.access.AccessDeniedException: Access is denied")
.path(ResultPath.parse("/differentGraphQlEndpoint"))
.build();
Assertions.assertNotEquals(baseError, differentPathError);
TypedGraphQLError differentExtensionsError = TypedGraphQLError.newPermissionDeniedBuilder()
.message("org.springframework.security.access.AccessDeniedException: Access is denied")
.path(ResultPath.parse("/differentGraphQlEndpoint"))
.extensions(new HashMap<String, Object>() {{
put("key", "value");
}})
.build();
Assertions.assertNotEquals(baseError, differentExtensionsError);
}
@ParameterizedTest
@MethodSource("reflexiveEqualitySource")
void reflexiveEqualityWithNullFieldsTest(TypedGraphQLError error, TypedGraphQLError sameError) {
Assertions.assertEquals(error, sameError);
}
private static Stream<Arguments> reflexiveEqualitySource() {
return Stream.of(
Arguments.of(
TypedGraphQLError.newBuilder().build(),
TypedGraphQLError.newBuilder().build()
),
Arguments.of(
TypedGraphQLError.newBadRequestBuilder().build(),
TypedGraphQLError.newBadRequestBuilder().build()
),
Arguments.of(
errorWithoutMessage(),
errorWithoutMessage()
),
Arguments.of(
errorWithoutLocation(),
errorWithoutLocation()
),
Arguments.of(
errorWithoutPath(),
errorWithoutPath()
)
);
}
private static TypedGraphQLError errorWithoutMessage() {
return TypedGraphQLError.newBuilder()
.location(new SourceLocation(0, 0))
.path(ResultPath.parse("/someGraphQlEndpoint"))
.build();
}
private static TypedGraphQLError errorWithoutLocation() {
return TypedGraphQLError.newBuilder()
.message("Some error message")
.path(ResultPath.parse("/someGraphQlEndpoint"))
.build();
}
private static TypedGraphQLError errorWithoutPath() {
return TypedGraphQLError.newBuilder()
.message("Some error message")
.location(new SourceLocation(0, 0))
.build();
}
}
| 4,001 |
0 | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/ErrorDetail.java | /*
* 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.types.errors;
import graphql.ErrorClassification;
import graphql.GraphQLError;
import static com.netflix.graphql.types.errors.ErrorType.*;
/**
* The ErrorDetail is an optional field which will provide more fine grained information on the error condition.
* This allows the ErrorType enumeration to be small and mostly static so that application branching logic
* can depend on it. The ErrorDetail provides a more specific cause for the error. This enumeration will
* be much larger and likely change/grow over time.
* <p>
* For example, a service may be unavailable, resulting in ErrorType UNAVAILABLE. The ErrorDetail may be
* more specific, such as THROTTLED_CPU. The ErrorType should be sufficient to control client behavior,
* while the ErrorDetail is more useful for debugging and real-time operations.
* <p>
* The example below is not to be considered canonical. This enumeration may be defined by the server,
* and should be included with the server schema.
*/
public interface ErrorDetail extends ErrorClassification {
ErrorType getErrorType();
/**
* A set of common error details. Implementations may define additional values.
*/
enum Common implements ErrorDetail {
/**
* The deadline expired before the operation could complete.
* <p>
* For operations that change the state of the system, this error
* may be returned even if the operation has completed successfully.
* For example, a successful response from a server could have been
* delayed long enough for the deadline to expire.
* <p>
* HTTP Mapping: 504 Gateway Timeout
* Error Type: UNAVAILABLE
*/
DEADLINE_EXCEEDED(UNAVAILABLE),
/**
* The server detected that the client is exhibiting a behavior that
* might be generating excessive load.
* <p>
* HTTP Mapping: 429 Too Many Requests or 420 Enhance Your Calm
* Error Type: UNAVAILABLE
*/
ENHANCE_YOUR_CALM(UNAVAILABLE),
/**
* The requested field is not found in the schema.
* <p>
* This differs from `NOT_FOUND` in that `NOT_FOUND` should be used when a
* query is valid, but is unable to return a result (if, for example, a
* specific video id doesn't exist). `FIELD_NOT_FOUND` is intended to be
* returned by the server to signify that the requested field is not known to exist.
* This may be returned in lieu of failing the entire query.
* See also `PERMISSION_DENIED` for cases where the
* requested field is invalid only for the given user or class of users.
* <p>
* HTTP Mapping: 404 Not Found
* Error Type: BAD_REQUEST
*/
FIELD_NOT_FOUND(BAD_REQUEST),
/**
* The client specified an invalid argument.
* <p>
* Note that this differs from `FAILED_PRECONDITION`.
* `INVALID_ARGUMENT` indicates arguments that are problematic
* regardless of the state of the system (e.g., a malformed file name).
* <p>
* HTTP Mapping: 400 Bad Request
* Error Type: BAD_REQUEST
* INVALID_ARGUMENT
*/
INVALID_ARGUMENT(BAD_REQUEST),
/**
* The provided cursor is not valid.
* <p>
* The most common usage for this error is when a client is paginating
* through a list that uses stateful cursors. In that case, the provided
* cursor may be expired.
* <p>
* HTTP Mapping: 404 Not Found
* Error Type: NOT_FOUND
*/
INVALID_CURSOR(NOT_FOUND),
/**
* Unable to perform operation because a required resource is missing.
* <p>
* Example: Client is attempting to refresh a list, but the specified
* list is expired. This requires an action by the client to get a new list.
* <p>
* If the user is simply trying GET a resource that is not found,
* use the NOT_FOUND error type. FAILED_PRECONDITION.MISSING_RESOURCE
* is to be used particularly when the user is performing an operation
* that requires a particular resource to exist.
* <p>
* HTTP Mapping: 400 Bad Request or 500 Internal Server Error
* Error Type: FAILED_PRECONDITION
*/
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.
* <p>
* 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.
* <p>
* HTTP Mapping: 409 Conflict.
* Error Type: FAILED_PRECONDITION
*/
CONFLICT(FAILED_PRECONDITION),
/**
* Service Error.
* <p>
* There is a problem with an upstream service.
* <p>
* This may be returned if a gateway receives an unknown error from a service
* or if a service is unreachable.
* If a request times out which waiting on a response from a service,
* `DEADLINE_EXCEEDED` may be returned instead.
* If a service returns a more specific error Type, the specific error Type may
* be returned instead.
* <p>
* HTTP Mapping: 502 Bad Gateway
* Error Type: UNAVAILABLE
*/
SERVICE_ERROR(UNAVAILABLE),
/**
* Request throttled based on server CPU limits
* <p>
* HTTP Mapping: 503 Unavailable.
* Error Type: UNAVAILABLE
*/
THROTTLED_CONCURRENCY(UNAVAILABLE),
/**
* Request throttled based on server concurrency limits.
* <p>
* HTTP Mapping: 503 Unavailable
* Error Type: UNAVAILABLE
*/
THROTTLED_CPU(UNAVAILABLE),
/**
* The operation is not implemented or is not currently supported/enabled.
* <p>
* HTTP Mapping: 501 Not Implemented
* Error Type: BAD_REQUEST
*/
UNIMPLEMENTED(BAD_REQUEST);
private final ErrorType errorType;
Common(ErrorType errorType) {
this.errorType = errorType;
}
@Override
public Object toSpecification(GraphQLError error) {
return errorType + "." + this;
}
@Override
public ErrorType getErrorType() {
return errorType;
}
}
}
| 4,002 |
0 | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/TypedError.java | /*
* Copyright 2020 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.types.errors;
import java.util.Map;
public interface TypedError {
/**
* The value of the errorType field is an enumeration of error types. An errorType is a fairly coarse
* characterization of an error that should be sufficient for client side branching logic.
*
* @return ErrorType (Should NOT be Null)
*/
ErrorType getErrorType();
/**
* The ErrorDetail is an optional field which will provide more fine grained information on the error condition.
* This allows the ErrorType enumeration to be small and mostly static so that application branching logic
* can depend on it. The ErrorDetail provides a more specific cause for the error. This enumeration will
* be much larger and likely change/grow over time.
*
* @return ErrorDetail (May be null)
*/
ErrorDetail getErrorDetail();
/**
* Indicates the source that issued the error. For example, could
* be a backend service name, a domain graph service name, or a
* gateway. In the case of client code throwing the error, this
* may be a client library name, or the client app name.
*
* @return origin of the error (May be null)
*/
String getOrigin();
/**
* Http URI to a page detailing additional
* information that could be used to debug
* the error. This information may be general
* to the class of error or specific to this
* particular instance of the error.
*
* @return Debug URI (May be null)
*/
String getDebugUri();
/**
* Optionally provided based on request flag
* Could include e.g. stacktrace or info from
* upstream service
*
* @return map of debugInfo (May be null)
*/
Map<String, Object> getDebugInfo();
}
| 4,003 |
0 | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/DebugInfo.java | /*
* Copyright 2020 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.types.errors;
public interface DebugInfo {
}
| 4,004 |
0 | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/InternalError.java | /*
* Copyright 2020 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.types.errors;
public class InternalError {
}
| 4,005 |
0 | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/TypedGraphQLError.java | /*
* 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.types.errors;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import graphql.ErrorClassification;
import graphql.GraphQLError;
import graphql.execution.ResultPath;
import graphql.language.SourceLocation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static graphql.Assert.assertNotNull;
public class TypedGraphQLError implements GraphQLError {
private final String message;
private final List<SourceLocation> locations;
private final ErrorClassification classification;
private final List<Object> path;
private final Map<String, Object> extensions;
@JsonCreator
public TypedGraphQLError(@JsonProperty("message") String message,
@JsonProperty("locations") List<SourceLocation> locations,
@JsonProperty("classification") ErrorClassification classification,
@JsonProperty("path") List<Object> path,
@JsonProperty("extensions") Map<String, Object> extensions) {
this.message = message;
this.locations = locations;
this.classification = classification;
this.path = path;
this.extensions = extensions;
}
@Override
public String getMessage() {
return message;
}
@Override
public List<SourceLocation> getLocations() {
return locations;
}
@Override
// We return null here because we don't want graphql-java to write classification field
public ErrorClassification getErrorType() {
return null;
}
@Override
public List<Object> getPath() {
return path;
}
@Override
public Map<String, Object> getExtensions() {
return extensions;
}
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder UNKNOWN = newBuilder();
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newInternalErrorBuilder() instead.
*/
@Deprecated
public static Builder INTERNAL = newBuilder().errorType(ErrorType.INTERNAL);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newNotFoundBuilder() instead.
*/
@Deprecated
public static Builder NOT_FOUND = newBuilder().errorType(ErrorType.NOT_FOUND);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder UNAUTHENTICATED = newBuilder().errorType(ErrorType.UNAUTHENTICATED);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newPermissionDeniedBuilder() instead.
*/
@Deprecated
public static Builder PERMISSION_DENIED = newBuilder().errorType(ErrorType.PERMISSION_DENIED);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBadRequestBuilder() instead.
*/
@Deprecated
public static Builder BAD_REQUEST = newBuilder().errorType(ErrorType.BAD_REQUEST);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder UNAVAILABLE = newBuilder().errorType(ErrorType.UNAVAILABLE);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder FAILED_PRECONDITION = newBuilder().errorType(ErrorType.FAILED_PRECONDITION);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder FIELD_NOT_FOUND = newBuilder().errorDetail(ErrorDetail.Common.FIELD_NOT_FOUND);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder INVALID_CURSOR = newBuilder().errorDetail(ErrorDetail.Common.INVALID_CURSOR);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder UNIMPLEMENTED = newBuilder().errorDetail(ErrorDetail.Common.UNIMPLEMENTED);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder INVALID_ARGUMENT = newBuilder().errorDetail(ErrorDetail.Common.INVALID_ARGUMENT);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder DEADLINE_EXCEEDED = newBuilder().errorDetail(ErrorDetail.Common.DEADLINE_EXCEEDED);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder SERVICE_ERROR = newBuilder().errorDetail(ErrorDetail.Common.SERVICE_ERROR);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder ENHANCE_YOUR_CALM = newBuilder().errorDetail(ErrorDetail.Common.ENHANCE_YOUR_CALM);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder THROTTLED_CPU = newBuilder().errorDetail(ErrorDetail.Common.THROTTLED_CPU);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder THROTTLED_CONCURRENCY = newBuilder().errorDetail(ErrorDetail.Common.THROTTLED_CONCURRENCY);
/**
* @deprecated Static builder fields are thread-unsafe. Use TypedGraphQLError.newBuilder() instead.
*/
@Deprecated
public static Builder MISSING_RESOURCE = newBuilder().errorDetail(ErrorDetail.Common.MISSING_RESOURCE);
/**
* Create new Builder instance to customize error.
*
* @return A new TypedGraphQLError.Builder instance to further customize the error.
*/
public static Builder newBuilder() {
return new Builder();
}
/**
* Create new Builder instance to customize error.
* @return A new TypedGraphQLError.Builder instance to further customize the error. Pre-sets ErrorType.INTERNAL.
*/
public static Builder newInternalErrorBuilder() {
return new Builder().errorType(ErrorType.INTERNAL);
}
/**
* Create new Builder instance to customize error.
* @return A new TypedGraphQLError.Builder instance to further customize the error. Pre-sets ErrorType.NOT_FOUND.
*/
public static Builder newNotFoundBuilder() {
return new Builder().errorType(ErrorType.NOT_FOUND);
}
/**
* Create new Builder instance to customize error.
* @return A new TypedGraphQLError.Builder instance to further customize the error. Pre-sets ErrorType.PERMISSION_DENIED.
*/
public static Builder newPermissionDeniedBuilder() {
return new Builder().errorType(ErrorType.PERMISSION_DENIED);
}
/**
* Create new Builder instance to customize error.
* @return A new TypedGraphQLError.Builder instance to further customize the error. Pre-sets ErrorType.BAD_REQUEST.
*/
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() {
return "TypedGraphQLError{" +
"message='" + message + '\'' +
", locations=" + locations +
", path=" + path +
", extensions=" + extensions +
'}';
}
@Override
public int hashCode() {
return Objects.hash(message, locations, path, extensions);
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null) return false;
if (obj.getClass() != this.getClass()) return false;
TypedGraphQLError e = (TypedGraphQLError)obj;
if (!Objects.equals(message, e.message)) return false;
if (!Objects.equals(locations, e.locations)) return false;
if (!Objects.equals(path, e.path)) return false;
if (!Objects.equals(extensions, e.extensions)) return false;
return true;
}
public static class Builder {
private String message;
private List<Object> path;
private List<SourceLocation> locations = new ArrayList<>();
private ErrorClassification errorClassification = ErrorType.UNKNOWN;
private Map<String, Object> extensions;
private String origin;
private String debugUri;
private Map<String, Object> debugInfo;
private Builder() {
}
private String defaultMessage() {
return errorClassification.toString();
}
private Map<String, Object> getExtensions() {
HashMap<String, Object> extensionsMap = new HashMap<>();
if (extensions != null) extensionsMap.putAll(extensions);
if (errorClassification instanceof ErrorType) {
extensionsMap.put("errorType", String.valueOf(errorClassification));
} else if (errorClassification instanceof ErrorDetail) {
extensionsMap.put("errorType", String.valueOf(((ErrorDetail) errorClassification).getErrorType()));
extensionsMap.put("errorDetail", String.valueOf(errorClassification));
}
if (origin != null) extensionsMap.put("origin", origin);
if (debugUri != null) extensionsMap.put("debugUri", debugUri);
if (debugInfo != null) extensionsMap.put("debugInfo", debugInfo);
return extensionsMap;
}
public Builder message(String message) {
this.message = assertNotNull(message);
return this;
}
public Builder message(String message, Object... formatArgs) {
this.message = String.format(assertNotNull(message), formatArgs);
return this;
}
public Builder locations(List<SourceLocation> locations) {
this.locations.addAll(assertNotNull(locations));
return this;
}
public Builder location(SourceLocation location) {
this.locations.add(assertNotNull(location));
return this;
}
public Builder path(ResultPath path) {
this.path = assertNotNull(path).toList();
return this;
}
public Builder path(List<Object> path) {
this.path = assertNotNull(path);
return this;
}
public Builder errorType(ErrorType errorType) {
this.errorClassification = assertNotNull(errorType);
return this;
}
public Builder errorDetail(ErrorDetail errorDetail) {
this.errorClassification = assertNotNull(errorDetail);
return this;
}
public Builder origin(String origin) {
this.origin = assertNotNull(origin);
return this;
}
public Builder debugUri(String debugUri) {
this.debugUri = assertNotNull(debugUri);
return this;
}
public Builder debugInfo(Map<String, Object> debugInfo) {
this.debugInfo = assertNotNull(debugInfo);
return this;
}
public Builder extensions(Map<String, Object> extensions) {
this.extensions = assertNotNull(extensions);
return this;
}
/**
* @return a newly built GraphQLError
*/
public TypedGraphQLError build() {
if (message == null) message = defaultMessage();
return new TypedGraphQLError(message, locations, errorClassification, path, getExtensions());
}
}
}
| 4,006 |
0 | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types | Create_ds/dgs-framework/graphql-error-types/src/main/java/com/netflix/graphql/types/errors/ErrorType.java | /*
* Copyright 2020 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.types.errors;
import graphql.ErrorClassification;
/**
* ErrorType is an enumeration of error types. An errorType is a fairly coarse
* characterization of an error that should be sufficient for client side branching logic.
* The enumeration of error types should remain mostly static. More specific errors may be specified
* by the errorDetail field.
* <p>
* Http mappings are provided only as documentation. These are rough mappings intended to provide a
* quick explanation of the semantics by analogy with HTTP.
*/
public enum ErrorType implements ErrorClassification {
/*
* Unknown error.
*
* For example, this error may be returned when
* an error code received from another address space belongs to
* an error space that is not known in this address space. Also
* errors raised by APIs that do not return enough error information
* may be converted to this error.
*
* If a client sees an unknown errorType, it will be interpreted as UNKNOWN.
* Unknown errors MUST NOT trigger any special behavior. These MAY be treated
* by an implementation as being equivalent to INTERNAL.
*
* When possible, a more specific error should be provided.
*
* HTTP Mapping: 520 Unknown Error
*/
UNKNOWN,
/*
* Internal error.
*
* An unexpected internal error was encountered. This means that some
* invariants expected by the underlying system have been broken.
*
* This error code is reserved for serious errors.
*
* HTTP Mapping:500 Internal Server Error
*/
INTERNAL,
/*
* The requested entity was not found.
*
* This could apply to a resource that has never existed (e.g. bad resource id),
* or a resource that no longer exists (e.g. cache expired.)
*
* Note to server developers: if a request is denied for an entire class
* of users, such as gradual feature rollout or undocumented allowlist,
* `NOT_FOUND` may be used. If a request is denied for some users within
* a class of users, such as user-based access control, `PERMISSION_DENIED`
* must be used.
*
* HTTP Mapping: 404 Not Found
*/
NOT_FOUND,
/*
* The request does not have valid authentication credentials.
*
* This is intended to be returned only for routes that require
* authentication.
*
* HTTP Mapping: 401 Unauthorized
*/
UNAUTHENTICATED,
/*
* The caller does not have permission to execute the specified
* operation.
*
* `PERMISSION_DENIED` must not be used for rejections
* caused by exhausting some resource or quota.
* `PERMISSION_DENIED` must not be used if the caller
* cannot be identified (use `UNAUTHENTICATED`
* instead for those errors).
*
* This error Type does not imply the
* request is valid or the requested entity exists or satisfies
* other pre-conditions.
*
* HTTP Mapping: 403 Forbidden
*/
PERMISSION_DENIED,
/*
* Bad Request.
*
* There is a problem with the request.
* Retrying the same request is not likely to succeed.
* An example would be a query or argument that cannot be deserialized.
*
* HTTP Mapping: 400 Bad Request
*/
BAD_REQUEST,
/*
* Currently Unavailable.
*
* The service is currently unavailable. This is most likely a
* transient condition, which can be corrected by retrying with
* a backoff.
*
* HTTP Mapping: 503 Unavailable
*/
UNAVAILABLE,
/*
* The operation was rejected because the system is not in a state
* required for the operation's execution. For example, the directory
* to be deleted is non-empty, an rmdir operation is applied to
* a non-directory, etc.
*
* Service implementers can use the following guidelines to decide
* between `FAILED_PRECONDITION` and `UNAVAILABLE`:
*
* - Use `UNAVAILABLE` if the client can retry just the failing call.
* - Use `FAILED_PRECONDITION` if the client should not retry until
* the system state has been explicitly fixed. E.g., if an "rmdir"
* fails because the directory is non-empty, `FAILED_PRECONDITION`
* should be returned since the client should not retry unless
* the files are deleted from the directory.
*
* HTTP Mapping: 400 Bad Request or 500 Internal Server Error
*/
FAILED_PRECONDITION
}
| 4,007 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared/HelloDataFetcherTest.java | /*
* 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.example.shared;
import com.netflix.graphql.dgs.DgsQueryExecutor;
import com.netflix.graphql.dgs.exceptions.QueryException;
import org.assertj.core.util.Maps;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletRequest;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
@ExampleSpringBootTest
class HelloDataFetcherTest {
@Autowired
DgsQueryExecutor queryExecutor;
@Test
void helloShouldIncludeName() {
String message = queryExecutor.executeAndExtractJsonPath("{ hello(name: \"DGS\")}", "data.hello");
assertThat(message).isEqualTo("hello, DGS!");
}
@Test
void helloShouldIncludeNameWithVariables() {
String message = queryExecutor
.executeAndExtractJsonPath(
"query Hello($name: String) { hello(name: $name)}",
"data.hello",
Maps.newHashMap("name", "DGS")
);
assertThat(message).isEqualTo("hello, DGS!");
}
@Test
void helloShouldWorkWithoutName() {
String message = queryExecutor.executeAndExtractJsonPath("{hello}", "data.hello");
assertThat(message).isEqualTo("hello, Stranger!");
}
@Test
void messageLoaderWithScheduledDispatch() {
LocalDateTime now = LocalDateTime.now();
String message = queryExecutor.executeAndExtractJsonPath("{ messageFromBatchLoaderWithScheduledDispatch }", "data.messageFromBatchLoaderWithScheduledDispatch");
LocalDateTime after = LocalDateTime.now();
assertThat( now.until(after, ChronoUnit.SECONDS)).isGreaterThanOrEqualTo(2);
assertThat( now.until(after, ChronoUnit.SECONDS)).isLessThanOrEqualTo(4);
assertThat(message).isEqualTo("hello, a!");
}
@Test
void getQueryWithInspectError() {
try {
queryExecutor.executeAndExtractJsonPath("{greeting}", "data.greeting");
fail("Exception should have been thrown");
} catch (QueryException ex) {
assertThat(ex.getMessage()).contains("Validation error (FieldUndefined@[greeting]) : Field 'greeting' in type 'Query' is undefined");
assertThat(ex.getErrors().size()).isEqualTo(1);
}
}
@Test
void getQueryWithGraphQlException() {
try {
queryExecutor.executeAndExtractJsonPath("{withGraphqlException}", "data.greeting");
fail("Exception should have been thrown");
} catch (QueryException ex) {
assertThat(ex.getErrors().get(0).getMessage()).isEqualTo("graphql.GraphQLException: that's not going to work!");
assertThat(ex.getErrors().size()).isEqualTo(1);
}
}
@Test
void getQueryWithRuntimeException() {
try {
queryExecutor.executeAndExtractJsonPath("{withRuntimeException}", "data.greeting");
fail("Exception should have been thrown");
} catch (QueryException ex) {
assertThat(ex.getErrors().get(0).getMessage()).isEqualTo("java.lang.RuntimeException: That's broken!");
assertThat(ex.getErrors().size()).isEqualTo(1);
}
}
@Test
void getQueryWithMultipleExceptions() {
try {
queryExecutor.executeAndExtractJsonPath("{withRuntimeException, withGraphqlException}", "data.greeting");
fail("Exception should have been thrown");
} catch (QueryException ex) {
assertThat(ex.getErrors().get(0).getMessage()).isEqualTo("java.lang.RuntimeException: That's broken!");
assertThat(ex.getErrors().get(1).getMessage()).isEqualTo("graphql.GraphQLException: that's not going to work!");
assertThat(ex.getMessage()).isEqualTo("java.lang.RuntimeException: That's broken!, graphql.GraphQLException: that's not going to work!");
assertThat(ex.getErrors().size()).isEqualTo(2);
}
}
}
| 4,008 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared/ConcurrentDataFetcherTest.java | /*
* 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.example.shared;
import com.jayway.jsonpath.DocumentContext;
import com.netflix.graphql.dgs.DgsQueryExecutor;
import org.assertj.core.data.Percentage;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@Disabled("The need of this test is questionable, since the concurrent execution of data fetchers is left to the graphql-java engine.")
@ExampleSpringBootTest
class ConcurrentDataFetcherTest {
@Autowired
DgsQueryExecutor queryExecutor;
@Test
void concurrent() {
DocumentContext documentContext = queryExecutor.executeAndGetDocumentContext("{concurrent1, concurrent2}");
int ts1 = documentContext.read("data.concurrent1");
int ts2 = documentContext.read("data.concurrent2");
// you can't assume the order of execution of unrelated fields, in this case data.concurrent2 can be fetched
// before data.concurrent1 or vice versa.
assertThat(ts1).isCloseTo(ts2, Percentage.withPercentage(10.0));
}
} | 4,009 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared/MovieDataFetcherTest.java | /*
* 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.example.shared;
import com.netflix.graphql.dgs.DgsQueryExecutor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.assertj.core.api.Assertions.assertThat;
@ExampleSpringBootTest
public class MovieDataFetcherTest {
@Autowired
DgsQueryExecutor queryExecutor;
@Test
void moviesShouldHaveDirector() {
String director = queryExecutor.executeAndExtractJsonPath("{ movies { director } }", "data.movies[0].director");
assertThat(director).isEqualTo("some director");
}
}
| 4,010 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared/ExampleSpringBootTest.java | /*
* 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.example.shared;
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.autoconfig.DgsExtendedScalarsAutoConfiguration;
import com.netflix.graphql.dgs.example.datafetcher.HelloDataFetcher;
import com.netflix.graphql.dgs.example.shared.dataLoader.MessageDataLoaderWithDispatchPredicate;
import com.netflix.graphql.dgs.example.shared.datafetcher.*;
import com.netflix.graphql.dgs.pagination.DgsPaginationAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@SpringBootTest(classes = {HelloDataFetcher.class, MovieDataFetcher.class, ConcurrentDataFetcher.class, RequestHeadersDataFetcher.class, RatingMutation.class, CurrentTimeDateFetcher.class, DgsExtendedScalarsAutoConfiguration.class, DgsAutoConfiguration.class, DgsPaginationAutoConfiguration.class, MessageDataLoaderWithDispatchPredicate.class})
public @interface ExampleSpringBootTest {
}
| 4,011 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared/datafetcher/SubscriptionDataFetcherTest.java | /*
* 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.example.shared.datafetcher;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.graphql.dgs.DgsQueryExecutor;
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.autoconfig.DgsExtendedScalarsAutoConfiguration;
import com.netflix.graphql.dgs.example.shared.types.Stock;
import com.netflix.graphql.dgs.pagination.DgsPaginationAutoConfiguration;
import graphql.ExecutionResult;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import reactor.test.StepVerifier;
import reactor.test.scheduler.VirtualTimeScheduler;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = {DgsAutoConfiguration.class, SubscriptionDataFetcher.class, DgsExtendedScalarsAutoConfiguration.class, DgsPaginationAutoConfiguration.class})
class SubscriptionDataFetcherTest {
@Autowired
DgsQueryExecutor queryExecutor;
ObjectMapper objectMapper = new ObjectMapper();
@Test
void stocks() {
ExecutionResult executionResult = queryExecutor.execute("subscription Stocks { stocks { name, price } }");
Publisher<ExecutionResult> publisher = executionResult.getData();
VirtualTimeScheduler virtualTimeScheduler = VirtualTimeScheduler.create();
StepVerifier.withVirtualTime(() -> publisher, 3)
.expectSubscription()
.thenRequest(3)
.assertNext(result -> assertThat(toStock(result).getPrice()).isEqualTo(500))
.assertNext(result -> assertThat(toStock(result).getPrice()).isEqualTo(501))
.assertNext(result -> assertThat(toStock(result).getPrice()).isEqualTo(502))
.thenCancel()
.verify();
}
private Stock toStock(ExecutionResult result) {
Map<String, Object> data = result.getData();
return objectMapper.convertValue(data.get("stocks"), Stock.class);
}
} | 4,012 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/test/java/com/netflix/graphql/dgs/example/shared/datafetcher/TimeDataFetcherTest.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsQueryExecutor;
import com.netflix.graphql.dgs.example.shared.ExampleSpringBootTest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import static org.assertj.core.api.Assertions.assertThat;
@ExampleSpringBootTest
class TimeDataFetcherTest {
@Autowired
DgsQueryExecutor queryExecutor;
@Test
void returnCurrentTime() {
String message = queryExecutor.executeAndExtractJsonPath("{ now }", "data.now");
assertThat(message).isNotNull();
}
@Test
void acceptTime() {
LocalTime aTime = LocalTime.parse("12:01:00");
Boolean result = queryExecutor.executeAndExtractJsonPath("{ schedule(time:\""+aTime.format(DateTimeFormatter.ISO_LOCAL_TIME)+"\") }", "data.schedule");
assertThat(result).isTrue();
}
}
| 4,013 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/ExtraTypeDefinitionRegistry.java | /*
* 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.example.shared;
import graphql.language.FieldDefinition;
import graphql.language.ObjectTypeExtensionDefinition;
import graphql.language.TypeName;
import graphql.schema.idl.TypeDefinitionRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ExtraTypeDefinitionRegistry {
@Bean
public TypeDefinitionRegistry registry() {
ObjectTypeExtensionDefinition objectTypeExtensionDefinition = ObjectTypeExtensionDefinition.newObjectTypeExtensionDefinition().name("Query").fieldDefinition(FieldDefinition.newFieldDefinition().name("myField").type(new TypeName("String")).build())
.build();
TypeDefinitionRegistry typeDefinitionRegistry = new TypeDefinitionRegistry();
typeDefinitionRegistry.add(objectTypeExtensionDefinition);
return typeDefinitionRegistry;
}
}
| 4,014 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/ExtraCodeRegistry.java | /*
* 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.example.shared;
import com.netflix.graphql.dgs.DgsCodeRegistry;
import com.netflix.graphql.dgs.DgsComponent;
import graphql.schema.DataFetcher;
import graphql.schema.FieldCoordinates;
import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.idl.TypeDefinitionRegistry;
@DgsComponent
public class ExtraCodeRegistry {
@DgsCodeRegistry
public GraphQLCodeRegistry.Builder registry(GraphQLCodeRegistry.Builder codeRegistryBuilder, TypeDefinitionRegistry registry) {
DataFetcher<String> df = (dfe) -> "yes, my extra field!";
FieldCoordinates coordinates = FieldCoordinates.coordinates("Query", "myField");
return codeRegistryBuilder.dataFetcher(coordinates, df);
}
}
| 4,015 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/types/Message.java | /*
* 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.example.shared.types;
public class Message {
private final String info;
public Message(String info) {
this.info = info;
}
public String getInfo() {
return info;
}
}
| 4,016 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/types/ScaryMovie.java | /*
* 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.example.shared.types;
public class ScaryMovie implements Movie {
private String title;
private String director;
private boolean gory;
private int scareFactor;
public ScaryMovie() {
}
public ScaryMovie(String title, String director, boolean gory, int scareFactor) {
this.title = title;
this.director = director;
this.gory = gory;
this.scareFactor = scareFactor;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public boolean getGory() {
return gory;
}
public void setGory(boolean gory) {
this.gory = gory;
}
public int getScareFactor() {
return scareFactor;
}
public void setScareFactor(int scareFactor) {
this.scareFactor = scareFactor;
}
@Override
public String toString() {
return "ScaryMovie{" + "title='" + title + "', " +"director='" + director + "', " +"gory='" + gory + "', " +"scareFactor='" + scareFactor + "' " +"}";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ScaryMovie that = (ScaryMovie) o;
return java.util.Objects.equals(title, that.title) &&
java.util.Objects.equals(director, that.director) &&
gory == that.gory &&
scareFactor == that.scareFactor;
}
@Override
public int hashCode() {
return java.util.Objects.hash(title, director, gory, scareFactor);
}
}
| 4,017 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/types/ActionMovie.java | /*
* 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.example.shared.types;
public class ActionMovie implements Movie {
private String title;
private String director;
private int nrOfExplosions;
public ActionMovie() {
}
public ActionMovie(String title, String director, int nrOfExplosions) {
this.title = title;
this.director = director;
this.nrOfExplosions = nrOfExplosions;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public int getNrOfExplosions() {
return nrOfExplosions;
}
public void setNrOfExplosions(int nrOfExplosions) {
this.nrOfExplosions = nrOfExplosions;
}
@Override
public String toString() {
return "ActionMovie{" + "title='" + title + "', " +"director='" + director + "', " +"nrOfExplosions='" + nrOfExplosions + "' " +"}";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ActionMovie that = (ActionMovie) o;
return java.util.Objects.equals(title, that.title) &&
java.util.Objects.equals(director, that.director) &&
nrOfExplosions == that.nrOfExplosions;
}
@Override
public int hashCode() {
return java.util.Objects.hash(title, director, nrOfExplosions);
}
}
| 4,018 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/types/Rating.java | /*
* 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.example.shared.types;
public class Rating {
private final double avgStars;
public Rating(double avgStars) {
this.avgStars = avgStars;
}
public double getAvgStars() {
return avgStars;
}
}
| 4,019 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/types/Stock.java | /*
* 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.example.shared.types;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Stock {
private final String name;
private final double price;
@JsonCreator
public Stock(@JsonProperty("name") String name, @JsonProperty("price") double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
}
| 4,020 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/types/Movie.java | /*
* 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.example.shared.types;
public interface Movie {
String getTitle();
void setTitle(String setTitle);
String getDirector();
void setDirector(String setDirector);
}
| 4,021 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/context/ExampleGraphQLContextContributor.java | /*
* Copyright 2022 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.example.shared.context;
import com.netflix.graphql.dgs.context.GraphQLContextContributor;
import com.netflix.graphql.dgs.internal.DgsRequestData;
import graphql.GraphQLContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* Example GraphQLContextContributor that works with either webflux or mvc based stacks.
*/
@Component
public class ExampleGraphQLContextContributor implements GraphQLContextContributor {
public static final String CONTRIBUTOR_ENABLED_CONTEXT_KEY = "contributorEnabled";
public static final String CONTRIBUTOR_ENABLED_CONTEXT_VALUE = "true";
public static final String CONTEXT_CONTRIBUTOR_HEADER_NAME = "context-contributor-header";
public static final String CONTEXT_CONTRIBUTOR_HEADER_VALUE = "enabled";
@Override
public void contribute(@NotNull GraphQLContext.Builder builder, @Nullable Map<String, ?> extensions, @Nullable DgsRequestData dgsRequestData) {
builder.put("exampleGraphQLContextEnabled", "true");
if (dgsRequestData != null && dgsRequestData.getHeaders() != null) {
String contributedContextHeader = dgsRequestData.getHeaders().getFirst(CONTEXT_CONTRIBUTOR_HEADER_NAME);
if (CONTEXT_CONTRIBUTOR_HEADER_VALUE.equals(contributedContextHeader)) {
builder.put(CONTRIBUTOR_ENABLED_CONTEXT_KEY, CONTRIBUTOR_ENABLED_CONTEXT_VALUE);
}
}
}
} | 4,022 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/context/MyContext.java | /*
* 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.example.shared.context;
public class MyContext {
private final String customState = "Custom state!";
public String getCustomState() {
return customState;
}
}
| 4,023 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/instrumentation/ExampleInstrumentationDependingOnContextContributor.java | /*
* Copyright 2022 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.example.shared.instrumentation;
import com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.GraphQLContext;
import graphql.execution.instrumentation.InstrumentationState;
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* Example Instrumentation that depends on the fact that ContextContributors have already been invoked.
* Specifically the ExampleGraphQLContextContributor has affected the contents of the GraphQLContext object and has set
* the CONTRIBUTOR_ENABLED_CONTEXT_KEY.
*/
@Component
public class ExampleInstrumentationDependingOnContextContributor extends SimplePerformantInstrumentation {
@Override
public InstrumentationState createState(InstrumentationCreateStateParameters parameters) {
GraphQLContext context = parameters.getExecutionInput().getGraphQLContext();
String contextContributorIndicator = context.get(ExampleGraphQLContextContributor.CONTRIBUTOR_ENABLED_CONTEXT_KEY);
if (contextContributorIndicator != null) {
return new InstrumentationState() {
@Override
public String toString() {
return contextContributorIndicator;
}
};
}
return super.createState(parameters);
}
@Override
public CompletableFuture<ExecutionResult> instrumentExecutionResult(
ExecutionResult executionResult, InstrumentationExecutionParameters parameters, InstrumentationState state) {
// skip if the expected property has not been set by context contributor
if (state == null) {
return super.instrumentExecutionResult(executionResult, parameters, state);
}
// otherwise pass its value via extension to make this testable from a client perspective
return CompletableFuture.completedFuture(
ExecutionResultImpl.newExecutionResult()
.from(executionResult)
.addExtension(ExampleGraphQLContextContributor.CONTRIBUTOR_ENABLED_CONTEXT_KEY, state.toString())
.build());
}
} | 4,024 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/CurrentTimeDateFetcher.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import graphql.schema.DataFetchingEnvironment;
import java.time.LocalTime;
@SuppressWarnings("SameReturnValue")
@DgsComponent
public class CurrentTimeDateFetcher {
@DgsData(parentType = "Query", field = "now")
public LocalTime now() {
return LocalTime.now();
}
@DgsData(parentType = "Query", field = "schedule")
public boolean schedule(DataFetchingEnvironment env) {
LocalTime time = env.getArgument("time");
System.out.println(time);
return true;
}
}
| 4,025 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/ConcurrentDataFetcher.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.DgsEnableDataFetcherInstrumentation;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@DgsComponent
public class ConcurrentDataFetcher {
@DgsData(parentType = "Query", field = "concurrent1")
@DgsEnableDataFetcherInstrumentation
public CompletableFuture<Integer> concurrent1() {
System.out.println("Entry concurrent1");
CompletableFuture<Integer> stringCompletableFuture = CompletableFuture.supplyAsync(() -> {
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Done concurrent thing 1");
return new Long(System.currentTimeMillis()).intValue();
});
System.out.println("Exit concurrent1");
return stringCompletableFuture;
}
@DgsData(parentType = "Query", field = "concurrent2")
public CompletableFuture<Integer> concurrent2() {
System.out.println("Entry concurrent2");
CompletableFuture<Integer> stringCompletableFuture = CompletableFuture.supplyAsync(() -> {
try {
TimeUnit.MILLISECONDS.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Done concurrent thing 2");
return new Long(System.currentTimeMillis()).intValue();
});
System.out.println("Exit concurrent2");
return stringCompletableFuture;
}
}
| 4,026 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/ScaryMovieDataFetcher.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.example.shared.types.ActionMovie;
import com.netflix.graphql.dgs.example.shared.types.Movie;
import com.netflix.graphql.dgs.example.shared.types.ScaryMovie;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.List;
@DgsComponent
public class ScaryMovieDataFetcher {
@SuppressWarnings("SameReturnValue")
@DgsData(parentType = "ScaryMovie", field = "director")
public String director() {
return "Scary movie director";
}
}
| 4,027 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/RatingMutation.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.InputArgument;
import com.netflix.graphql.dgs.example.shared.types.Rating;
@DgsComponent
public class RatingMutation {
@DgsData(parentType = "Mutation", field = "addRating")
public Rating addRating(@InputArgument("input") RatingInput ratingInput) {
if(ratingInput.getStars() < 0) {
throw new IllegalArgumentException("Stars must be 1-5");
}
System.out.println("Rated " + ratingInput.getTitle() + " with " + ratingInput.getStars() + " stars") ;
return new Rating(ratingInput.getStars());
}
}
class RatingInput {
private String title;
private int stars;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getStars() {
return stars;
}
public void setStars(int stars) {
this.stars = stars;
}
}
| 4,028 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/HelloDataFetcher.java | /*
* 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.example.datafetcher;
import com.netflix.graphql.dgs.*;
import com.netflix.graphql.dgs.context.DgsContext;
import com.netflix.graphql.dgs.example.shared.context.MyContext;
import com.netflix.graphql.dgs.example.shared.types.Message;
import graphql.GraphQLException;
import graphql.relay.Connection;
import graphql.relay.SimpleListConnection;
import graphql.schema.DataFetchingEnvironment;
import org.dataloader.DataLoader;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestHeader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import static com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor.CONTRIBUTOR_ENABLED_CONTEXT_KEY;
@DgsComponent
public class HelloDataFetcher {
@DgsQuery
@DgsEnableDataFetcherInstrumentation(false)
public String hello(@InputArgument String name) {
if (name == null) {
name = "Stranger";
}
return "hello, " + name + "!";
}
@DgsData(parentType = "Query", field = "messageFromBatchLoader")
public CompletableFuture<String> getMessage(DataFetchingEnvironment env) {
DataLoader<String, String> dataLoader = env.getDataLoader("messages");
return dataLoader.load("a");
}
@DgsData(parentType = "Query", field = "messageFromBatchLoaderWithScheduledDispatch")
public CompletableFuture<String> getMessageScheduled(DataFetchingEnvironment env) {
DataLoader<String, String> dataLoader = env.getDataLoader("messagesWithScheduledDispatch");
CompletableFuture res = dataLoader.load("a");
return res;
}
@DgsData(parentType = "Query", field = "messagesWithExceptionFromBatchLoader")
public CompletableFuture<List<Message>> getMessagesWithException(DgsDataFetchingEnvironment env) {
List<Message> messages = new ArrayList<>();
messages.add(new Message("A"));
messages.add(new Message("B"));
messages.add(new Message("C"));
return CompletableFuture.completedFuture(messages);
}
@DgsData(parentType = "Message", field = "info")
public CompletableFuture<String> getMessageWithException(DgsDataFetchingEnvironment env) {
Message msg = env.getSource();
DataLoader<String, String> dataLoader = env.getDataLoader("messagesDataLoaderWithException");
return dataLoader.load(msg.getInfo());
}
@DgsData(parentType = "Query", field = "withContext")
public String withContext(DataFetchingEnvironment dfe) {
MyContext customContext = DgsContext.getCustomContext(dfe);
return customContext.getCustomState();
}
@DgsData(parentType = "Query", field = "withDataLoaderContext")
@DgsEnableDataFetcherInstrumentation
public CompletableFuture<String> withDataLoaderContext(DataFetchingEnvironment dfe) {
DataLoader<String, String> exampleLoaderWithContext = dfe.getDataLoader("exampleLoaderWithContext");
return exampleLoaderWithContext.load("A");
}
@DgsData(parentType = "Query", field = "withDataLoaderGraphQLContext")
@DgsEnableDataFetcherInstrumentation
public CompletableFuture<String> withDataLoaderGraphQLContext(DataFetchingEnvironment dfe) {
DataLoader<String, String> exampleLoaderWithContext = dfe.getDataLoader("exampleLoaderWithGraphQLContext");
return exampleLoaderWithContext.load(CONTRIBUTOR_ENABLED_CONTEXT_KEY);
}
@DgsData(parentType = "Query", field = "withGraphqlException")
public String withGraphqlException() {
throw new GraphQLException("that's not going to work!");
}
@DgsData(parentType = "Query", field = "withRuntimeException")
public String withRuntimeException() {
throw new RuntimeException("That's broken!");
}
@DgsData(parentType = "Query", field = "withPagination")
public Connection<Message> withPagination(DataFetchingEnvironment env) {
return new SimpleListConnection<>(Collections.singletonList(new Message("This is a generated connection"))).get(env);
}
}
| 4,029 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/SubscriptionDataFetcher.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsSubscription;
import com.netflix.graphql.dgs.example.shared.types.Stock;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import java.time.Duration;
@DgsComponent
public class SubscriptionDataFetcher {
@DgsSubscription
public Publisher<Stock> stocks() {
return Flux.interval(Duration.ofSeconds(0), Duration.ofSeconds(1)).map(t -> new Stock("NFLX", 500 + t));
}
}
| 4,030 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/ActionMovieDataFetcher.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
@DgsComponent
public class ActionMovieDataFetcher {
@SuppressWarnings("SameReturnValue")
@DgsData(parentType = "ActionMovie", field = "director")
public String director() {
return "Action movie director";
}
}
| 4,031 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/RequestHeadersDataFetcher.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.DgsDataFetchingEnvironment;
import com.netflix.graphql.dgs.DgsQuery;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestHeader;
import java.util.List;
import java.util.Map;
@DgsComponent
public class RequestHeadersDataFetcher {
@DgsData(parentType = "Query", field = "headers")
public String headers(DgsDataFetchingEnvironment dfe, @RequestHeader("demo-header") String demoHeader) {
return demoHeader;
}
@DgsData(parentType = "Query", field = "referer")
public String referer(@RequestHeader List<String> referer) {
return referer.toString();
}
}
| 4,032 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/datafetcher/MovieDataFetcher.java | /*
* 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.example.shared.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.example.shared.types.ActionMovie;
import com.netflix.graphql.dgs.example.shared.types.ScaryMovie;
import com.netflix.graphql.dgs.example.shared.types.Movie;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.List;
@DgsComponent
public class MovieDataFetcher {
@DgsData(parentType = "Query", field = "movies")
public List<Movie> movies(DataFetchingEnvironment dfe) {
List<Movie> movies = new ArrayList<>();
movies.add(new ActionMovie("Crouching Tiger", null, 0));
movies.add(new ActionMovie("Black hawk down", null, 10));
movies.add(new ScaryMovie("American Horror Story", null,true, 10));
movies.add(new ScaryMovie("Love Death + Robots",null, false, 4));
return movies;
}
@SuppressWarnings("SameReturnValue")
@DgsData(parentType = "Movie", field = "director")
public String director() {
return "some director";
}
}
| 4,033 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/dataLoader/ExampleLoaderWithGraphQLContext.java | /*
* 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.example.shared.dataLoader;
import com.netflix.graphql.dgs.DgsDataLoader;
import graphql.GraphQLContext;
import org.dataloader.BatchLoaderEnvironment;
import org.dataloader.BatchLoaderWithContext;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import java.util.stream.Collectors;
@DgsDataLoader(name = "exampleLoaderWithGraphQLContext")
public class ExampleLoaderWithGraphQLContext implements BatchLoaderWithContext<String, String> {
@Override
public CompletionStage<List<String>> load(List<String> keys, BatchLoaderEnvironment environment) {
GraphQLContext graphQLContext = environment.getContext();
return CompletableFuture.supplyAsync(() -> keys.stream().map((Function<String, String>) graphQLContext::get).collect(Collectors.toList()));
}
}
| 4,034 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/dataLoader/MessageDataLoader.java | /*
* 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.example.shared.dataLoader;
import com.netflix.graphql.dgs.DgsDataLoader;
import com.netflix.graphql.dgs.DgsDispatchPredicate;
import org.dataloader.BatchLoader;
import org.dataloader.registries.DispatchPredicate;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
@DgsDataLoader(name = "messages")
public class MessageDataLoader implements BatchLoader<String, String> {
@Override
public CompletionStage<List<String>> load(List<String> keys) {
return CompletableFuture.supplyAsync(() -> keys.stream().map(key -> "hello, " + key + "!").collect(Collectors.toList()));
}
}
| 4,035 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/dataLoader/ExampleLoaderWithContext.java | /*
* 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.example.shared.dataLoader;
import com.netflix.graphql.dgs.DgsDataLoader;
import com.netflix.graphql.dgs.context.DgsContext;
import com.netflix.graphql.dgs.example.shared.context.MyContext;
import org.dataloader.BatchLoaderEnvironment;
import org.dataloader.BatchLoaderWithContext;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
@DgsDataLoader(name = "exampleLoaderWithContext")
public class ExampleLoaderWithContext implements BatchLoaderWithContext<String, String> {
@Override
public CompletionStage<List<String>> load(List<String> keys, BatchLoaderEnvironment environment) {
MyContext context = DgsContext.getCustomContext(environment);
return CompletableFuture.supplyAsync(() -> keys.stream().map(key -> context.getCustomState() + " " + key).collect(Collectors.toList()));
}
}
| 4,036 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/dataLoader/MessagesDataLoaderWithException.java | /*
* 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.example.shared.dataLoader;
import com.netflix.graphql.dgs.DgsDataLoader;
import com.netflix.graphql.dgs.context.DgsContext;
import com.netflix.graphql.dgs.example.shared.context.MyContext;
import org.dataloader.BatchLoaderEnvironment;
import org.dataloader.BatchLoaderWithContext;
import org.dataloader.Try;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
@DgsDataLoader(name = "messagesDataLoaderWithException")
public class MessagesDataLoaderWithException implements BatchLoaderWithContext<String, Try<String>> {
@Override
public CompletionStage<List<Try<String>>> load(List<String> keys, BatchLoaderEnvironment environment) {
MyContext context = DgsContext.getCustomContext(environment);
return CompletableFuture.supplyAsync(() -> keys.stream()
.map(key -> Try.tryCall(() -> {
if (key.equals("A")) {
throw new RuntimeException("Invalid key");
}
return context.getCustomState() + " " + key;
})).collect(Collectors.toList()));
}
}
| 4,037 |
0 | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared | Create_ds/dgs-framework/graphql-dgs-example-shared/src/main/java/com/netflix/graphql/dgs/example/shared/dataLoader/MessageDataLoaderWithDispatchPredicate.java | /*
* 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.example.shared.dataLoader;
import com.netflix.graphql.dgs.DgsDataLoader;
import com.netflix.graphql.dgs.DgsDispatchPredicate;
import org.dataloader.BatchLoader;
import org.dataloader.registries.DispatchPredicate;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@DgsDataLoader(name = "messagesWithScheduledDispatch")
public class MessageDataLoaderWithDispatchPredicate implements BatchLoader<String, String> {
private org.slf4j.Logger logger = LoggerFactory.getLogger(MessageDataLoaderWithDispatchPredicate.class);
@DgsDispatchPredicate
DispatchPredicate pred = DispatchPredicate.dispatchIfLongerThan(Duration.ofSeconds(2));
@Override
public CompletionStage<List<String>> load(List<String> keys) {
return CompletableFuture.supplyAsync(() -> keys.stream().map(key -> "hello, " + key + "!").collect(Collectors.toList()));
}
}
| 4,038 |
0 | Create_ds/dgs-framework/graphql-dgs-client/src/test/java/com/netflix/graphql/dgs | Create_ds/dgs-framework/graphql-dgs-client/src/test/java/com/netflix/graphql/dgs/client/MovieInput.java | /*
* 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 com.netflix.graphql.dgs.client.scalar.DateRange;
import java.util.List;
public class MovieInput {
private int movieId;
private String title;
private Genre genre;
private Director director;
private List<Actor> actor;
private DateRange releaseWindow;
public MovieInput(int movieId, String title, Genre genre, Director director, List<Actor> actor, DateRange releaseWindow) {
this.movieId = movieId;
this.title = title;
this.genre = genre;
this.director = director;
this.actor = actor;
this.releaseWindow = releaseWindow;
}
public MovieInput(int movieId) {
this.movieId = movieId;
}
public enum Genre {
ACTION,DRAMA
}
public static class Director {
private String name;
Director(String name) {
this.name = name;
}
}
public static class Actor {
private String name;
private String roleName;
Actor(String name, String roleName) {
this.name = name;
this.roleName = roleName;
}
}
}
| 4,039 |
0 | Create_ds/dgs-framework/graphql-dgs-client/src/test/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs-client/src/test/java/com/netflix/graphql/client/GraphQLResponseJavaTest.java | /*
* 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.client;
import com.netflix.graphql.dgs.client.*;
import org.junit.jupiter.api.Test;
import org.springframework.http.*;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
import reactor.core.publisher.Mono;
import static java.util.Collections.emptyMap;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
@SuppressWarnings("deprecation")
public class GraphQLResponseJavaTest {
private final String query = "query SubmitReview {" +
"submitReview(review:{movieId:1, description:\"\"}) {" +
"submittedBy" +
"}" +
"}";
private final String jsonResponse = "{" +
"\"data\": {" +
"\"submitReview\": {" +
"\"submittedBy\": \"abc@netflix.com\"" +
"}" +
"}" +
"}";
RestTemplate restTemplate = new RestTemplate();
MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
String url = "http://localhost:8080/graphql";
DefaultGraphQLClient client = new DefaultGraphQLClient(url);
RequestExecutor requestExecutor = (url, headers, body) -> {
HttpHeaders httpHeaders = new HttpHeaders();
headers.forEach(httpHeaders::addAll);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(body, httpHeaders),String.class);
return new HttpResponse(exchange.getStatusCodeValue(), exchange.getBody());
};
RequestExecutor requestExecutorWithResponseHeaders = (url, headers, body) -> {
HttpHeaders httpHeaders = new HttpHeaders();
headers.forEach(httpHeaders::addAll);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(body, httpHeaders),String.class);
return new HttpResponse(exchange.getStatusCodeValue(), exchange.getBody(), exchange.getHeaders());
};
@Test
public void responseWithoutHeaders() {
server.expect(requestTo(url))
.andExpect(method(HttpMethod.POST))
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json("{\"operationName\":\"SubmitReview\"}"))
.andRespond(withSuccess(jsonResponse, MediaType.APPLICATION_JSON));
GraphQLResponse graphQLResponse = client.executeQuery(
query,
emptyMap(), "SubmitReview", requestExecutor
);
String submittedBy = graphQLResponse.extractValueAsObject("submitReview.submittedBy", String.class);
assert(submittedBy).contentEquals("abc@netflix.com");
server.verify();
}
@Test
public void responseWithHeaders() {
String jsonResponse = "{" +
"\"data\": {" +
"\"submitReview\": {" +
"\"submittedBy\": \"abc@netflix.com\"" +
"}" +
"}" +
"}";
server.expect(requestTo(url))
.andExpect(method(HttpMethod.POST))
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andRespond(withSuccess(jsonResponse, MediaType.APPLICATION_JSON));
GraphQLResponse graphQLResponse = client.executeQuery(query, emptyMap(), requestExecutorWithResponseHeaders);
String submittedBy = graphQLResponse.extractValueAsObject("submitReview.submittedBy", String.class);
assert(submittedBy).contentEquals("abc@netflix.com");
assert(graphQLResponse.getHeaders().get("Content-Type").get(0)).contentEquals("application/json");
server.verify();
}
@Test
public void testCustom() {
server.expect(requestTo(url))
.andExpect(method(HttpMethod.POST))
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json("{\"operationName\":\"SubmitReview\"}"))
.andRespond(withSuccess(jsonResponse, MediaType.APPLICATION_JSON));
CustomGraphQLClient client = GraphQLClient.createCustom(url, requestExecutor);
GraphQLResponse graphQLResponse = client.executeQuery(query, emptyMap(), "SubmitReview");
String submittedBy = graphQLResponse.extractValueAsObject("submitReview.submittedBy", String.class);
assert(submittedBy).contentEquals("abc@netflix.com");
server.verify();
}
@Test
public void testCustomMono() {
server.expect(requestTo(url))
.andExpect(method(HttpMethod.POST))
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json("{\"operationName\":\"SubmitReview\"}"))
.andRespond(withSuccess(jsonResponse, MediaType.APPLICATION_JSON));
CustomMonoGraphQLClient client = MonoGraphQLClient.createCustomReactive(url, (requestUrl, headers, body) -> {
HttpHeaders httpHeaders = new HttpHeaders();
headers.forEach(httpHeaders::addAll);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(body, httpHeaders),String.class);
return Mono.just(new HttpResponse(exchange.getStatusCodeValue(), exchange.getBody(), exchange.getHeaders()));
});
Mono<GraphQLResponse> graphQLResponse = client.reactiveExecuteQuery(query, emptyMap(), "SubmitReview");
String submittedBy = graphQLResponse.map(r -> r.extractValueAsObject("submitReview.submittedBy", String.class)).block();
assert(submittedBy).contentEquals("abc@netflix.com");
server.verify();
}
}
| 4,040 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/test | Create_ds/dgs-framework/graphql-dgs-example-java/src/test/java/FileUploadMutationTest.java | /*
* 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.
*/
import com.netflix.graphql.dgs.DgsQueryExecutor;
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.autoconfig.DgsExtendedScalarsAutoConfiguration;
import com.netflix.graphql.dgs.example.datafetcher.FileUploadMutation;
import com.netflix.graphql.dgs.example.datafetcher.HelloDataFetcher;
import com.netflix.graphql.dgs.example.shared.datafetcher.ConcurrentDataFetcher;
import com.netflix.graphql.dgs.example.shared.datafetcher.MovieDataFetcher;
import com.netflix.graphql.dgs.example.shared.datafetcher.RatingMutation;
import com.netflix.graphql.dgs.pagination.DgsPaginationAutoConfiguration;
import org.assertj.core.util.Lists;
import org.assertj.core.util.Maps;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = {HelloDataFetcher.class, MovieDataFetcher.class, ConcurrentDataFetcher.class, RatingMutation.class, DgsExtendedScalarsAutoConfiguration.class, DgsAutoConfiguration.class, DgsPaginationAutoConfiguration.class, FileUploadMutation.class})
public class FileUploadMutationTest {
@Autowired
DgsQueryExecutor queryExecutor;
@Test
void fileUpload() {
MultipartFile file = new MockMultipartFile("hello", "hello.txt", MediaType.TEXT_PLAIN_VALUE, "Hello World".getBytes());
Map<String, Object> inputMap = Maps.newHashMap("description", "test");
inputMap.put("files", Lists.newArrayList(file));
boolean result = queryExecutor.executeAndExtractJsonPath("mutation($input: FileUploadInput!) {uploadFile(input: $input)}",
"data.uploadFile", Maps.newHashMap("input", inputMap));
assertThat(result).isTrue();
}
}
| 4,041 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/test | Create_ds/dgs-framework/graphql-dgs-example-java/src/test/java/GraphQLContextContributorTest.java | /*
* 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.
*/
import com.netflix.graphql.dgs.DgsQueryExecutor;
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.autoconfig.DgsExtendedScalarsAutoConfiguration;
import com.netflix.graphql.dgs.example.context.MyContextBuilder;
import com.netflix.graphql.dgs.example.datafetcher.HelloDataFetcher;
import com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor;
import com.netflix.graphql.dgs.example.shared.dataLoader.ExampleLoaderWithContext;
import com.netflix.graphql.dgs.example.shared.dataLoader.ExampleLoaderWithGraphQLContext;
import com.netflix.graphql.dgs.example.shared.instrumentation.ExampleInstrumentationDependingOnContextContributor;
import com.netflix.graphql.dgs.example.shared.datafetcher.MovieDataFetcher;
import com.netflix.graphql.dgs.pagination.DgsPaginationAutoConfiguration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.ServletWebRequest;
import static com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor.CONTEXT_CONTRIBUTOR_HEADER_NAME;
import static com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor.CONTEXT_CONTRIBUTOR_HEADER_VALUE;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = {HelloDataFetcher.class, MovieDataFetcher.class, MyContextBuilder.class, ExampleGraphQLContextContributor.class, ExampleInstrumentationDependingOnContextContributor.class, DgsExtendedScalarsAutoConfiguration.class, DgsAutoConfiguration.class, DgsPaginationAutoConfiguration.class, ExampleLoaderWithContext.class, ExampleLoaderWithGraphQLContext.class})
public class GraphQLContextContributorTest {
@Autowired
DgsQueryExecutor queryExecutor;
@Test
void moviesExtensionShouldHaveContributedEnabledExtension() {
final MockHttpServletRequest mockServletRequest = new MockHttpServletRequest();
mockServletRequest.addHeader(CONTEXT_CONTRIBUTOR_HEADER_NAME, CONTEXT_CONTRIBUTOR_HEADER_VALUE);
ServletWebRequest servletWebRequest = new ServletWebRequest(mockServletRequest);
String contributorEnabled = queryExecutor.executeAndExtractJsonPath("{ movies { director } }", "extensions.contributorEnabled", servletWebRequest);
assertThat(contributorEnabled).isEqualTo("true");
}
@Test
void withDataloaderContext() {
String message = queryExecutor.executeAndExtractJsonPath("{withDataLoaderContext}", "data.withDataLoaderContext");
assertThat(message).isEqualTo("Custom state! A");
}
@Test
void withDataloaderGraphQLContext() {
final MockHttpServletRequest mockServletRequest = new MockHttpServletRequest();
mockServletRequest.addHeader(CONTEXT_CONTRIBUTOR_HEADER_NAME, CONTEXT_CONTRIBUTOR_HEADER_VALUE);
ServletWebRequest servletWebRequest = new ServletWebRequest(mockServletRequest);
String contributorEnabled = queryExecutor.executeAndExtractJsonPath("{ withDataLoaderGraphQLContext }", "data.withDataLoaderGraphQLContext", servletWebRequest);
assertThat(contributorEnabled).isEqualTo("true");
}
} | 4,042 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/test | Create_ds/dgs-framework/graphql-dgs-example-java/src/test/java/RequestHeaderDataFetcherTest.java | /*
* 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.
*/
import com.netflix.graphql.dgs.*;
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.autoconfig.DgsExtendedScalarsAutoConfiguration;
import com.netflix.graphql.dgs.example.datafetcher.HelloDataFetcher;
import com.netflix.graphql.dgs.example.shared.dataLoader.MessageDataLoaderWithDispatchPredicate;
import com.netflix.graphql.dgs.example.shared.datafetcher.*;
import com.netflix.graphql.dgs.pagination.DgsPaginationAutoConfiguration;
import com.netflix.graphql.dgs.webmvc.autoconfigure.DgsWebMvcAutoConfiguration;
import org.assertj.core.util.Maps;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.context.request.ServletWebRequest;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = {HelloDataFetcher.class, MovieDataFetcher.class, ConcurrentDataFetcher.class, RequestHeadersDataFetcher.class, DgsExtendedScalarsAutoConfiguration.class, DgsAutoConfiguration.class, DgsPaginationAutoConfiguration.class, DgsWebMvcAutoConfiguration.class})
class RequestHeaderDataFetcherTest {
@Autowired
DgsQueryExecutor queryExecutor;
@Test
void withHeaders() {
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
servletRequest.addHeader("demo-header", "demo-header-value");
String message = queryExecutor.executeAndExtractJsonPath("{headers}", "data.headers", new ServletWebRequest(servletRequest));
assertThat(message).isEqualTo("demo-header-value");
}
@Test
void withHeadersAndNoRequest() {
HttpHeaders headers = new HttpHeaders();
headers.add("demo-header", "demo-header-value");
String message = queryExecutor.executeAndExtractJsonPath("{headers}", "data.headers", headers);
assertThat(message).isEqualTo("demo-header-value");
}
} | 4,043 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/test/java/subsciption | Create_ds/dgs-framework/graphql-dgs-example-java/src/test/java/subsciption/integrationtest/SubscriptionIntegrationTest.java | /*
* 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 subsciption.integrationtest;
import com.netflix.graphql.dgs.client.WebSocketGraphQLClient;
import com.netflix.graphql.dgs.example.shared.datafetcher.SubscriptionDataFetcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import java.util.Collections;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {SubscriptionDataFetcher.class})
@EnableAutoConfiguration
public class SubscriptionIntegrationTest {
@LocalServerPort
private Integer port;
private WebSocketGraphQLClient webSocketGraphQLClient;
@BeforeEach
public void setup() {
webSocketGraphQLClient = new WebSocketGraphQLClient("ws://localhost:" + port + "/subscriptions", new ReactorNettyWebSocketClient());
}
@Test
public void testWebSocketSubscription() {
String subscriptionRequest = "subscription StockWatch { stocks { name price } }";
Flux<Double> starScore = webSocketGraphQLClient.reactiveExecuteQuery(subscriptionRequest, Collections.emptyMap()).take(3).map(r -> r.extractValue("stocks.price"));
StepVerifier.create(starScore)
.expectNext(500.0)
.expectNext(501.0)
.expectNext(502.0)
.thenCancel()
.verify();
}
}
| 4,044 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example/ExampleApp.java | /*
* 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.example;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import graphql.execution.preparsed.PreparsedDocumentEntry;
import graphql.execution.preparsed.PreparsedDocumentProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
@SpringBootApplication(scanBasePackages = {"com.netflix.graphql.dgs.example.shared", "com.netflix.graphql.dgs.example"})
public class ExampleApp {
public static void main(String[] args) {
SpringApplication.run(ExampleApp.class, args);
}
@Configuration
static class PreparsedDocumentProviderConfig {
private final Cache<String, PreparsedDocumentEntry> cache = Caffeine.newBuilder().maximumSize(250)
.expireAfterAccess(5,TimeUnit.MINUTES).recordStats().build();
@Bean
public PreparsedDocumentProvider preparsedDocumentProvider() {
return (executionInput, parseAndValidateFunction) -> {
Function<String, PreparsedDocumentEntry> mapCompute = key -> parseAndValidateFunction.apply(executionInput);
return cache.get(executionInput.getQuery(), mapCompute);
};
}
}
}
| 4,045 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example/context/MyContextBuilder.java | /*
* 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.example.context;
import com.netflix.graphql.dgs.context.DgsCustomContextBuilder;
import com.netflix.graphql.dgs.example.shared.context.MyContext;
import org.springframework.stereotype.Component;
@Component
public class MyContextBuilder implements DgsCustomContextBuilder<MyContext> {
@Override
public MyContext build() {
return new MyContext();
}
}
| 4,046 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example/datafetcher/WithHeader.java | /*
* 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.example.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestHeader;
@DgsComponent
public class WithHeader {
@DgsQuery
public String helloWithHeaders(@InputArgument String name, @RequestHeader(HttpHeaders.AUTHORIZATION) String authorization) {
return "hello, " + authorization + "!";
}
}
| 4,047 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example/datafetcher/MyInstrumentation.java | /*
* Copyright 2022 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.example.datafetcher;
import com.netflix.graphql.dgs.DgsExecutionResult;
import graphql.ExecutionResult;
import graphql.execution.instrumentation.InstrumentationState;
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
@Component
public class MyInstrumentation extends SimplePerformantInstrumentation {
@NotNull
@Override
public CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionResult executionResult,
InstrumentationExecutionParameters parameters,
InstrumentationState state) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add("myHeader", "hello");
return super.instrumentExecutionResult(
DgsExecutionResult.builder().executionResult(executionResult).headers(responseHeaders).build(),
parameters,
state
);
}
}
| 4,048 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example/datafetcher/WithCookie.java | /*
* 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.example.datafetcher;
import com.netflix.graphql.dgs.*;
import com.netflix.graphql.dgs.internal.DgsWebMvcRequestData;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.context.request.ServletWebRequest;
@DgsComponent
public class WithCookie {
@DgsQuery
public String withCookie(@CookieValue String mydgscookie) {
return mydgscookie;
}
@DgsMutation
public String updateCookie(@InputArgument String value, DgsDataFetchingEnvironment dfe) {
DgsWebMvcRequestData requestData = (DgsWebMvcRequestData) dfe.getDgsContext().getRequestData();
ServletWebRequest webRequest = (ServletWebRequest) requestData.getWebRequest();
jakarta.servlet.http.Cookie cookie = new jakarta.servlet.http.Cookie("mydgscookie", value);
webRequest.getResponse().addCookie(cookie);
return value;
}
}
| 4,049 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-java/src/main/java/com/netflix/graphql/dgs/example/datafetcher/FileUploadMutation.java | /*
* 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.example.datafetcher;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.InputArgument;
import graphql.schema.DataFetchingEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
@DgsComponent
public class FileUploadMutation {
private static final Logger log = LoggerFactory.getLogger(FileUploadMutation.class);
/**
* Implementation of the _Data Fetcher_ that will handle file upload.
*
* To test file upload via the command line you will first have to create a file,
* let's say we name it {@code a.txt} and contains only {@code Hello World!}.
* After that, you can use the {@code curl} command to execute the filue upload of one file as follows:
* {@code
* <pre>
* curl -a http://localhost:8080/graphql \
* --header "graphql-require-preflight:true" \
* -F operations='{ "query" : "mutation ($file: Upload!) { uploadFile(input: { files:[$file]} ) }", "variables": {"file": null } }' \
* -F map='{ "0": ["variables.file"] }' \
* -F 0=@a.txt
* </pre>
* }
*
* @param input the GraphQL input argument of type FileUploadInput, serialized to the java pojo FileUploadInput.
* @param dfe the Data Fetching Environment
* @return boolean that will be true if all files are uploaded.
*/
@DgsData(parentType = "Mutation", field = "uploadFile")
public boolean uploadFile(@InputArgument FileUploadInput input, DataFetchingEnvironment dfe) {
List<MultipartFile> parts = input.getFiles();
for (int i = 0; i < parts.size(); i++) {
try {
String content = new String(parts.get(i).getBytes());
log.debug("File upload contents are\n{}\n", content);
} catch (IOException e) {
log.error("Failed to upload file[{}]!", i, e);
e.printStackTrace();
}
}
return !parts.isEmpty();
}
static class FileUploadInput {
private String description;
private List<MultipartFile> files;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<MultipartFile> getFiles() {
return files;
}
public void setFiles(List<MultipartFile> file) {
this.files = file;
}
}
}
| 4,050 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/test | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/test/java/ReactiveGraphQLContextContributorTest.java | /*
* 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.
*/
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration;
import com.netflix.graphql.dgs.autoconfig.DgsExtendedScalarsAutoConfiguration;
import com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor;
import com.netflix.graphql.dgs.example.shared.datafetcher.MovieDataFetcher;
import com.netflix.graphql.dgs.example.shared.instrumentation.ExampleInstrumentationDependingOnContextContributor;
import com.netflix.graphql.dgs.pagination.DgsPaginationAutoConfiguration;
import com.netflix.graphql.dgs.reactive.DgsReactiveQueryExecutor;
import com.netflix.graphql.dgs.webflux.autoconfiguration.DgsWebFluxAutoConfiguration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.reactive.function.server.MockServerRequest;
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
import reactor.core.publisher.Mono;
import static com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor.CONTEXT_CONTRIBUTOR_HEADER_NAME;
import static com.netflix.graphql.dgs.example.shared.context.ExampleGraphQLContextContributor.CONTEXT_CONTRIBUTOR_HEADER_VALUE;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = {WebFluxConfigurationSupport.class, DgsAutoConfiguration.class, MovieDataFetcher.class, ExampleGraphQLContextContributor.class, ExampleInstrumentationDependingOnContextContributor.class, DgsWebFluxAutoConfiguration.class, DgsPaginationAutoConfiguration.class, DgsExtendedScalarsAutoConfiguration.class})
public class ReactiveGraphQLContextContributorTest {
@Autowired
DgsReactiveQueryExecutor queryExecutor;
@Test
void moviesExtensionShouldHaveContributedEnabledExtensionServerRequestSpecified() {
final MockServerRequest.Builder builder = MockServerRequest.builder();
builder.header(CONTEXT_CONTRIBUTOR_HEADER_NAME, CONTEXT_CONTRIBUTOR_HEADER_VALUE);
Mono<String> contributorEnabled = queryExecutor.executeAndExtractJsonPath(
"{ movies { director } }",
"extensions.contributorEnabled",
builder.build());
assertThat(contributorEnabled.block()).isEqualTo("true");
}
} | 4,051 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/ReactiveExampleApp.java | /*
* 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.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.netflix.graphql.dgs.example.shared", "com.netflix.graphql.dgs.example"})
public class ReactiveExampleApp {
public static void main(String[] args) {
SpringApplication.run(ReactiveExampleApp.class, args);
}
}
| 4,052 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/context/MyContextBuilder.java | /*
* 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.example.context;
import com.netflix.graphql.dgs.example.shared.context.MyContext;
import com.netflix.graphql.dgs.reactive.DgsReactiveCustomContextBuilderWithRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import reactor.core.publisher.Mono;
import java.util.Map;
@Component
public class MyContextBuilder implements DgsReactiveCustomContextBuilderWithRequest<MyContext> {
@NotNull
@Override
public Mono<MyContext> build(@Nullable Map<String, ?> extensions, @Nullable HttpHeaders headers, @Nullable ServerRequest serverRequest) {
return Mono.just(new MyContext());
}
}
| 4,053 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/web/RequestIdWebFilter.java | /*
* Copyright 2022 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.example.web;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;
@Component
public class RequestIdWebFilter implements WebFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange).contextWrite(Context.of("RequestId", exchange.getRequest().getId()));
}
}
| 4,054 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/reactive | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/reactive/datafetchers/WithCookie.java | /*
* 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.example.reactive.datafetchers;
import com.netflix.graphql.dgs.*;
import com.netflix.graphql.dgs.reactive.internal.DgsReactiveRequestData;
import org.springframework.http.ResponseCookie;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.reactive.function.server.ServerRequest;
@DgsComponent
public class WithCookie {
@DgsQuery
public String withCookie(@CookieValue String mydgscookie) {
return mydgscookie;
}
@DgsMutation
public String updateCookie(@InputArgument String value, DgsDataFetchingEnvironment dfe) {
DgsReactiveRequestData requestData = (DgsReactiveRequestData) dfe.getDgsContext().getRequestData();
ServerRequest serverRequest = requestData.getServerRequest();
serverRequest.exchange().getResponse()
.addCookie(ResponseCookie.from("mydgscookie", "webfluxupdated").build());
return value;
}
}
| 4,055 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/reactive | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/reactive/datafetchers/ReactiveDataFetchers.java | /*
* 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.example.reactive.datafetchers;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsQuery;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@DgsComponent
public class ReactiveDataFetchers {
@DgsQuery
public Mono<String> mono() {
return Mono.just("hello mono");
}
@DgsQuery
public Flux<Integer> flux() {
return Flux.just(1, 2, 3);
}
}
| 4,056 |
0 | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/reactive | Create_ds/dgs-framework/graphql-dgs-example-java-webflux/src/main/java/com/netflix/graphql/dgs/example/reactive/datafetchers/UsingWebFluxReactorContext.java | /*
* Copyright 2022 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.example.reactive.datafetchers;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsQuery;
import reactor.core.publisher.Mono;
@DgsComponent
public class UsingWebFluxReactorContext {
@DgsQuery
public Mono<String> usingContext() {
return Mono.deferContextual(context -> Mono.just("Query with request ID: " + context.get("RequestId")));
}
}
| 4,057 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/ExampleMultipleBatchLoadersAsField.java | /*
* Copyright 2020 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;
import org.dataloader.BatchLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@DgsComponent
public class ExampleMultipleBatchLoadersAsField {
@DgsDataLoader(name = "exampleLoaderFromField")
public BatchLoader<String, String> batchLoader = keys -> CompletableFuture.supplyAsync(() -> {
List<String> values = new ArrayList<>();
values.add("a");
values.add("b");
values.add("c");
return values;
});
@DgsDataLoader(name = "privateExampleLoaderFromField")
public BatchLoader<String, String> privateBatchLoader = keys -> CompletableFuture.supplyAsync(() -> {
List<String> values = new ArrayList<>();
values.add("a");
values.add("b");
values.add("c");
return values;
});
}
| 4,058 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/ExampleBatchLoaderWithoutNameFromField.java | /*
* Copyright 2022 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;
import org.dataloader.BatchLoader;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@DgsComponent
public class ExampleBatchLoaderWithoutNameFromField {
@DgsDataLoader
public BatchLoader<String, String> batchLoader = keys -> CompletableFuture.supplyAsync(() -> {
List<String> values = new ArrayList<>();
values.add("a");
values.add("b");
values.add("c");
return values;
});
@DgsDataLoader
BatchLoader<String, String> privateBatchLoader = keys -> CompletableFuture.supplyAsync(() -> {
List<String> values = new ArrayList<>();
values.add("a");
values.add("b");
values.add("c");
return values;
});
}
| 4,059 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/ExampleMappedBatchLoaderFromField.java | /*
* Copyright 2020 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;
import org.dataloader.MappedBatchLoader;
import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
@DgsComponent
public class ExampleMappedBatchLoaderFromField {
@DgsDataLoader(name = "exampleMappedLoaderFromField")
public MappedBatchLoader<String, String> mappedLoader = keys -> CompletableFuture.supplyAsync(() -> {
HashMap<String, String> result = new HashMap<>();
result.put("a", "A");
result.put("b", "B");
result.put("c", "C");
return result;
});
@DgsDataLoader(name = "privateExampleMappedLoaderFromField")
MappedBatchLoader<String, String> privateMappedLoader = keys -> CompletableFuture.supplyAsync(() -> {
HashMap<String, String> result = new HashMap<>();
result.put("a", "A");
result.put("b", "B");
result.put("c", "C");
return result;
});
}
| 4,060 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/ExampleBatchLoaderFromField.java | /*
* Copyright 2020 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;
import org.dataloader.BatchLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@DgsComponent
public class ExampleBatchLoaderFromField {
@DgsDataLoader(name = "exampleLoaderFromField")
public BatchLoader<String, String> batchLoader = keys -> CompletableFuture.supplyAsync(() -> {
List<String> values = new ArrayList<>();
values.add("a");
values.add("b");
values.add("c");
return values;
});
@DgsDataLoader(name = "privateExampleLoaderFromField")
BatchLoader<String, String> privateBatchLoader = keys -> CompletableFuture.supplyAsync(() -> {
List<String> values = new ArrayList<>();
values.add("a");
values.add("b");
values.add("c");
return values;
});
}
| 4,061 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/enums/JInputMessage.java | /*
* 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.internal.java.test.enums;
import graphql.scalars.country.code.CountryCode;
import java.util.List;
public class JInputMessage {
private JGreetingType type;
private List<JGreetingType> typeList;
private CountryCode countryCode;
public JGreetingType getType() {
return type;
}
public void setType(JGreetingType type) {
this.type = type;
}
public List<JGreetingType> getTypeList() {
return typeList;
}
public void setTypeList(List<JGreetingType> typeList) {
this.typeList = typeList;
}
public CountryCode getCountryCode() {
return countryCode;
}
public void setCountryCode(CountryCode countryCode) {
this.countryCode = countryCode;
}
}
| 4,062 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/enums/JGreetingType.java | /*
* 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.internal.java.test.enums;
public enum JGreetingType {
FRIENDLY,
POLITE
}
| 4,063 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JInputObject.java | /*
* 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.internal.java.test.inputobjects;
import java.time.LocalDateTime;
public class JInputObject {
private String simpleString;
private LocalDateTime someDate;
private SomeObject someObject;
public String getSimpleString() {
return simpleString;
}
public void setSimpleString(String simpleString) {
this.simpleString = simpleString;
}
public LocalDateTime getSomeDate() {
return someDate;
}
public void setSomeDate(LocalDateTime someDate) {
this.someDate = someDate;
}
public SomeObject getSomeObject() {
return someObject;
}
public void setSomeObject(SomeObject someObject) {
this.someObject = someObject;
}
public static class SomeObject {
private String key1;
private LocalDateTime key2;
private SubObject key3;
public String getKey1() {
return key1;
}
public void setKey1(String key1) {
this.key1 = key1;
}
public LocalDateTime getKey2() {
return key2;
}
public void setKey2(LocalDateTime key2) {
this.key2 = key2;
}
public SubObject getKey3() {
return key3;
}
public void setKey3(SubObject key3) {
this.key3 = key3;
}
}
public static class SubObject {
private String subkey1;
public String getSubkey1() {
return subkey1;
}
public void setSubkey1(String subkey1) {
this.subkey1 = subkey1;
}
}
}
| 4,064 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JFooInput.java | /*
* 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.internal.java.test.inputobjects;
import java.util.List;
public class JFooInput {
private List<JBarInput> bars;
public List<JBarInput> getBars() {
return bars;
}
public void setBars(List<JBarInput> bars) {
this.bars = bars;
}
}
| 4,065 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JPerson.java | /*
* 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.internal.java.test.inputobjects;
import java.util.Objects;
public class JPerson {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof JPerson)) return false;
JPerson jPerson = (JPerson) o;
return Objects.equals(getName(), jPerson.getName());
}
@Override
public int hashCode() {
return Objects.hash(getName());
}
@Override
public String toString() {
return "JPerson{" +
"name='" + name + '\'' +
'}';
}
}
| 4,066 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JEnum.java | /*
* 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.internal.java.test.inputobjects;
public enum JEnum {
A, B, C;
}
| 4,067 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JGenericBaseInputObject.java | /*
* 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.internal.java.test.inputobjects;
public class JGenericBaseInputObject<T> {
private String someField;
private T fieldA;
public String getSomeField() {
return someField;
}
public void setSomeField(String someField) {
this.someField = someField;
}
public T getFieldA() {
return fieldA;
}
public void setFieldA(T fieldA) {
this.fieldA = fieldA;
}
}
| 4,068 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JGenericInputObjectTwoTypeParams.java | /*
* 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.internal.java.test.inputobjects;
public class JGenericInputObjectTwoTypeParams<A, B> {
private A fieldA;
private B fieldB;
public A getFieldA() {
return fieldA;
}
public void setFieldA(A fieldA) {
this.fieldA = fieldA;
}
public B getFieldB() {
return fieldB;
}
public void setFieldB(B fieldB) {
this.fieldB = fieldB;
}
}
| 4,069 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JFilter.java | /*
* 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.internal.java.test.inputobjects;
import java.util.Objects;
public class JFilter {
private Object query;
public JFilter() {}
public JFilter(Object query) {
this.query = query;
}
public Object getQuery() {
return query;
}
public void setQuery(Object query) {
this.query = query;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof JFilter)) return false;
JFilter jFilter = (JFilter) o;
return Objects.equals(getQuery(), jFilter.getQuery());
}
@Override
public int hashCode() {
return Objects.hash(getQuery());
}
@Override
public String toString() {
return "JFilter{" +
"query=" + query +
'}';
}
}
| 4,070 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JInputObjectWithSet.java | /*
* 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.internal.java.test.inputobjects;
import java.util.Set;
public class JInputObjectWithSet {
private Set<Integer> items;
public Set<Integer> getItems() {
return items;
}
public void setItems(Set<Integer> items) {
this.items = items;
}
}
| 4,071 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JListOfListsOfLists.java | /*
* 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.internal.java.test.inputobjects;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class JListOfListsOfLists {
public static class JListOfListOfFilters extends JListOfListOfThings<JFilter> {
}
public static class JListOfListOfEnums extends JListOfListOfThings<JEnum> {
public JListOfListOfEnums() {
super();
}
}
public static class JListOfListOfStrings extends JListOfListOfThings<String> {
public JListOfListOfStrings() {
super();
}
}
abstract static class JListOfListOfThings<T> {
private List<List<List<T>>> lists = Collections.emptyList();
public List<List<List<T>>> getLists() {
return lists;
}
public void setLists(List<List<List<T>>> lists) {
this.lists = lists;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof JListOfListOfThings)) return false;
JListOfListOfThings<?> that = (JListOfListOfThings<?>) o;
return Objects.equals(getLists(), that.getLists());
}
@Override
public int hashCode() {
return Objects.hash(getLists());
}
@Override
public String toString() {
return getClass().getName() + "{" +
"lists=" + lists +
'}';
}
}
}
| 4,072 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JInputObjectWithMap.java | /*
* 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.internal.java.test.inputobjects;
import java.util.Map;
public class JInputObjectWithMap {
private Map<String,Object> json;
public Map<String, Object> getJson() {
return json;
}
public void setJson(Map<String, Object> json) {
this.json = json;
}
}
| 4,073 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JGenericSubInputObject.java | /*
* 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.internal.java.test.inputobjects;
public class JGenericSubInputObject extends JGenericBaseInputObject<Integer>{
}
| 4,074 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JBarInput.java | /*
* 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.internal.java.test.inputobjects;
public class JBarInput {
private String name;
private Object value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
| 4,075 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/JInputObjectWithKotlinProperty.java | /*
* 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.internal.java.test.inputobjects;
import com.netflix.graphql.dgs.internal.InputObjectMapperTest;
public class JInputObjectWithKotlinProperty {
private String name;
private InputObjectMapperTest.KotlinInputObject objectProperty;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public InputObjectMapperTest.KotlinInputObject getObjectProperty() {
return objectProperty;
}
public void setObjectProperty(InputObjectMapperTest.KotlinInputObject objectProperty) {
this.objectProperty = objectProperty;
}
}
| 4,076 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/sortby/JMovieSortBy.java | /*
* 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.internal.java.test.inputobjects.sortby;
public class JMovieSortBy extends JSortBy<JMovieSortByField> {
}
| 4,077 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/sortby/JSortBy.java | /*
* 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.internal.java.test.inputobjects.sortby;
public class JSortBy<T extends Enum<T>> {
private T field;
public T getField() {
return field;
}
public void setField(T field) {
this.field = field;
}
}
| 4,078 |
0 | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects | Create_ds/dgs-framework/graphql-dgs/src/test/java/com/netflix/graphql/dgs/internal/java/test/inputobjects/sortby/JMovieSortByField.java | /*
* 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.internal.java.test.inputobjects.sortby;
public enum JMovieSortByField {
TITLE,
RELEASEDATE
}
| 4,079 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java21 | Create_ds/dgs-framework/graphql-dgs/src/main/java21/com.netflix.graphql.dgs.internal.VirtualThreadTaskExecutor/VirtualThreadTaskExecutor.java | /*
* Copyright 2023 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.internal;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.task.AsyncTaskExecutor;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadFactory;
/**
* AsyncTaskExecutor based on Virtual Threads.
* JDK21+ only.
*/
@SuppressWarnings("unused")
public class VirtualThreadTaskExecutor implements AsyncTaskExecutor {
private final ThreadFactory threadFactory;
public VirtualThreadTaskExecutor() {
this.threadFactory = Thread.ofVirtual().name("dgs-virtual-thread-", 0).factory();
}
@Override
public void execute(@NotNull Runnable task) {
threadFactory.newThread(task).start();
}
@Override
public void execute(@NotNull Runnable task, long startTimeout) {
var future = new FutureTask<>(task, null);
execute(future);
}
@NotNull
@Override
public Future<?> submit(@NotNull Runnable task) {
var future = new FutureTask<>(task, null);
execute(future);
return future;
}
@NotNull
@Override
public <T> Future<T> submit(@NotNull Callable<T> task) {
var future = new FutureTask<>(task);
execute(future);
return future;
}
} | 4,080 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java21/com/netflix/graphql/dgs | Create_ds/dgs-framework/graphql-dgs/src/main/java21/com/netflix/graphql/dgs/conditionals/Java21Condition.java | /*
* Copyright 2023 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.conditionals;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
* Condition used in @ConditionalOnJava21.
* This is the JDK 21 version of the condition, which is only loaded on JDK 21+ using the multi-release JAR feature.
*/
@SuppressWarnings("unused")
public class Java21Condition implements Condition {
@Override
public boolean matches(@NotNull ConditionContext context, @NotNull AnnotatedTypeMetadata metadata) {
return true;
}
} | 4,081 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsTypeResolver.java | /*
* Copyright 2020 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;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DgsTypeResolver {
String name();
}
| 4,082 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsData.java | /*
* 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;
import java.lang.annotation.*;
/**
* Mark a method to be a data fetcher.
* A data fetcher can receive the DataFetchingEnvironment.
* The "parentType" property is the type that contains this field.
* For root queries that is "Query", and for root mutations "Mutation".
* The field is the name of the field this data fetcher is responsible for.
* See https://netflix.github.io/dgs/getting-started/
*/
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(DgsData.List.class)
@Inherited
public @interface DgsData {
String parentType();
String field() default "";
/**
* Container annotation that aggregates several {@link DgsData @DgsData} annotations.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@interface List {
/**
* Return the contained {@link DgsData} associated with this method.
*/
DgsData[] value();
}
}
| 4,083 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsMutation.java | /*
* 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;
import org.springframework.core.annotation.AliasFor;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@DgsData(parentType = "Mutation")
@Inherited
public @interface DgsMutation {
@AliasFor(annotation = DgsData.class)
String field() default "";
}
| 4,084 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/Internal.java | /*
* 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;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.ElementType.FIELD;
/**
* This represents code considered internal to the DGS framework and therefore its API is not stable between releases.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {CONSTRUCTOR, METHOD, TYPE, FIELD})
@Inherited
public @interface Internal {
}
| 4,085 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsRuntimeWiring.java | /*
* Copyright 2020 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;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to mark a function as a provider of runtime wiring.
* This allows customization of the runtime wiring before it is made executable.
* This is a low level extension feature that is typically not necessary.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DgsRuntimeWiring {
}
| 4,086 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsDataLoader.java | /*
* Copyright 2022 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;
import com.netflix.graphql.dgs.internal.utils.DataLoaderNameUtil;
import org.dataloader.registries.DispatchPredicate;
import org.springframework.stereotype.Component;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks a class or field as a DataLoader, which will be registered to the framework as a DataLoader.
* The class or field must implement one of the BatchLoader interfaces.
* See https://netflix.github.io/dgs/data-loaders/
*/
@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Component
@Inherited
public @interface DgsDataLoader {
/**
* Used internally by {@link DataLoaderNameUtil#getDataLoaderName(Class, DgsDataLoader)}.
* <p>
* The <strong>value</strong> of this constant may change in future versions,
* and should therefore not be relied upon.
*/
String GENERATE_DATA_LOADER_NAME = "NETFLIX_DGS_GENERATE_DATALOADER_NAME";
String name() default GENERATE_DATA_LOADER_NAME;
boolean caching() default true;
boolean batching() default true;
int maxBatchSize() default 0;
}
| 4,087 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsSubscription.java | /*
* 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;
import org.springframework.core.annotation.AliasFor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@DgsData(parentType = "Subscription")
@Inherited
public @interface DgsSubscription {
@AliasFor(annotation = DgsData.class)
String field() default "";
}
| 4,088 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsCodeRegistry.java | /*
* 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;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to mark a method a provider of a CodeRegistry, which is a programmatic way of creating a schema.
* https://netflix.github.io/dgs/advanced/schema-from-code/
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DgsCodeRegistry {
}
| 4,089 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsDefaultTypeResolver.java | /*
* Copyright 2020 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;
import java.lang.annotation.*;
/**
* Mark a type resolver method to be the default.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DgsDefaultTypeResolver {
}
| 4,090 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsEntityFetcher.java | /*
* Copyright 2020 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;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DgsEntityFetcher {
String name();
}
| 4,091 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsDirective.java | /*
* 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;
import org.springframework.stereotype.Component;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Mark a class as a custom Directive implementation that gets registered to the framework.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
@Inherited
public @interface DgsDirective {
String name() default "";
}
| 4,092 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsComponent.java | /*
* Copyright 2020 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;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to mark a class for the DGS framework.
* Each DgsComponent is also a regular Spring Component.
* The framework will scan each DgsComponent for other annotations.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
@Qualifier("dgs")
@Inherited
public @interface DgsComponent {
}
| 4,093 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsQueryExecutor.java | /*
* 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;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.TypeRef;
import graphql.ExecutionResult;
import org.intellij.lang.annotations.Language;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import java.util.Collections;
import java.util.Map;
/**
* Represents the core query executing capability of the framework.
* Use this interface to easily execute GraphQL queries, without using the HTTP endpoint.
* This is meant to be used in tests, and is also used internally in the framework.
* <p>
* The executeAnd* methods use the <a href="https://github.com/json-path/JsonPath">JsonPath library</a> library to easily get specific fields out of a nested Json structure.
* The {@link #executeAndGetDocumentContext(String)} method sets up a DocumentContext, which can then be reused to get multiple fields.
*
* @see <a href="https://netflix.github.io/dgs/query-execution-testing/">Query Execution Testing docs</a>
*/
public interface DgsQueryExecutor {
/**
* @param query The query string
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
*/
default ExecutionResult execute(@Language("GraphQL") @Nullable String query) {
return execute(query, Collections.emptyMap(), null, null, null, null);
}
/**
* @param query The query string
* @param variables A map of variables
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
default ExecutionResult execute(@Language("GraphQL") @Nullable String query,
@NonNull Map<String, Object> variables) {
return execute(query, variables, null, null, null, null);
}
/**
* @param query The query string
* @param variables A map of variables
* @param operationName The operation name
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://graphql.org/learn/queries/#operation-name">Operation name</a>
*/
default ExecutionResult execute(@Language("GraphQL") @Nullable String query,
@NonNull Map<String, Object> variables,
@Nullable String operationName) {
return execute(query, variables, null, null, operationName, null);
}
/**
* @param query The query string
* @param variables A map of variables
* @param extensions A map representing GraphQL extensions.
* This is made available in the {@link com.netflix.graphql.dgs.internal.DgsRequestData} object on {@link }com.netflix.graphql.dgs.context.DgsContext}.
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
default ExecutionResult execute(@Language("GraphQL") String query,
@NonNull Map<String, Object> variables,
@Nullable Map<String, Object> extensions,
@Nullable HttpHeaders headers) {
return execute(query, variables, extensions, headers, null, null);
}
/**
* Executes a GraphQL query. This method is used internally by all other methods in this interface.
*
* @param query The query string
* @param variables A map of variables
* @param extensions A map representing GraphQL extensions. This is made available in the {@link com.netflix.graphql.dgs.internal.DgsRequestData} object on {@link com.netflix.graphql.dgs.context.DgsContext}.
* @param headers Request headers represented as a Spring Framework {@link HttpHeaders}
* @param operationName Operation name
* @param webRequest A Spring {@link WebRequest} giving access to request details. Can cast to an environment specific class such as {@link org.springframework.web.context.request.ServletWebRequest}.
* @return Returns a GraphQL {@link ExecutionResult}. This includes data and errors.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://graphql.org/learn/queries/#operation-name">Operation name</a>
*/
ExecutionResult execute(@Language("GraphQL") String query,
@NonNull Map<String, Object> variables,
@Nullable Map<String, Object> extensions,
@Nullable HttpHeaders headers,
@Nullable String operationName,
@Nullable WebRequest webRequest);
/**
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)}instead.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param <T> The type of primitive or map representation that should be returned.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
default <T> T executeAndExtractJsonPath(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath) {
return executeAndExtractJsonPath(query, jsonPath, Collections.emptyMap());
}
/**
* <p>
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)}instead.
* <p>
* This only works for primitive types and map representations.
* Use {@link #executeAndExtractJsonPathAsObject(String, String, Class)} for complex types and lists.*
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param <T> The type of primitive or map representation that should be returned.
* @return The extracted value from the result, converted to type T
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
<T> T executeAndExtractJsonPath(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull Map<String, Object> variables);
/**
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)}instead.
* <p>
* This only works for primitive types and map representations.
* Use {@link #executeAndExtractJsonPathAsObject(String, String, Class)} for complex types and lists. *
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param headers Spring {@link HttpHeaders}
* @param <T> The type of primitive or map representation that should be returned.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
<T> T executeAndExtractJsonPath(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull HttpHeaders headers);
/**
* Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
* The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use {@link #executeAndExtractJsonPathAsObject(String, String, TypeRef)}instead.
* <p>
* This only works for primitive types and map representations.
* Use {@link #executeAndExtractJsonPathAsObject(String, String, Class)} for complex types and lists. *
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param servletWebRequest Spring {@link ServletWebRequest}
* @param <T> The type of primitive or map representation that should be returned.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
<T> T executeAndExtractJsonPath(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull ServletWebRequest servletWebRequest);
/**
* Executes a GraphQL query, parses the returned data, and return a {@link DocumentContext}.
* A {@link DocumentContext} can be used to extract multiple values using JsonPath, without re-executing the query.
*
* @param query Query string
* @return {@link DocumentContext} is a JsonPath type used to extract values from.
*/
default DocumentContext executeAndGetDocumentContext(@Language("GraphQL") @NonNull String query) {
return executeAndGetDocumentContext(query, Collections.emptyMap());
}
/**
* Executes a GraphQL query, parses the returned data, and return a {@link DocumentContext}.
* A {@link DocumentContext} can be used to extract multiple values using JsonPath, without re-executing the query.
*
* @param query Query string
* @param variables A Map of variables
* @return {@link DocumentContext} is a JsonPath type used to extract values from.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
DocumentContext executeAndGetDocumentContext(@Language("GraphQL") @NonNull String query, @NonNull Map<String, Object> variables);
/**
* Executes a GraphQL query, parses the returned data, and return a {@link DocumentContext}.
* A {@link DocumentContext} can be used to extract multiple values using JsonPath, without re-executing the query.
*
* @param query Query string
* @param variables A Map of variables
* @param headers Spring {@link HttpHeaders}
* @return {@link DocumentContext} is a JsonPath type used to extract values from.
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
DocumentContext executeAndGetDocumentContext(@Language("GraphQL") @NonNull String query,
@NonNull Map<String, Object> variables,
@Nullable HttpHeaders headers);
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param clazz The type to convert the extracted value to.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
*/
default <T> T executeAndExtractJsonPathAsObject(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull Class<T> clazz) {
return executeAndExtractJsonPathAsObject(query, jsonPath, Collections.emptyMap(), clazz, HttpHeaders.EMPTY);
}
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param clazz The type to convert the extracted value to.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
default <T> T executeAndExtractJsonPathAsObject(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull Map<String, Object> variables,
@NonNull Class<T> clazz) {
return executeAndExtractJsonPathAsObject(query, jsonPath, variables, clazz, HttpHeaders.EMPTY);
}
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param clazz The type to convert the extracted value to.
* @param headers Request headers represented as a Spring Framework {@link HttpHeaders}
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
*/
<T> T executeAndExtractJsonPathAsObject(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull Map<String, Object> variables,
@NonNull Class<T> clazz,
@Nullable HttpHeaders headers);
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Uses a {@link TypeRef} to specify the expected type, which is useful for Lists and Maps.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param typeRef A JsonPath [TypeRef] representing the expected result type.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://github.com/json-path/JsonPath#what-is-returned-when">Using TypeRef</a>
*/
default <T> T executeAndExtractJsonPathAsObject(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull TypeRef<T> typeRef) {
return executeAndExtractJsonPathAsObject(query, jsonPath, Collections.emptyMap(), typeRef, HttpHeaders.EMPTY);
}
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Uses a {@link TypeRef} to specify the expected type, which is useful for Lists and Maps.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param typeRef A JsonPath {@link TypeRef} representing the expected result type.
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://github.com/json-path/JsonPath#what-is-returned-when">Using TypeRef</a>
*/
default <T> T executeAndExtractJsonPathAsObject(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull Map<String, Object> variables,
@NonNull TypeRef<T> typeRef) {
return executeAndExtractJsonPathAsObject(query, jsonPath, variables, typeRef, HttpHeaders.EMPTY);
}
/**
* Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
* Uses a {@link TypeRef} to specify the expected type, which is useful for Lists and Maps.
* Be aware that this method can't guarantee type safety.
*
* @param query Query string
* @param jsonPath JsonPath expression.
* @param variables A Map of variables
* @param typeRef A JsonPath {@link TypeRef} representing the expected result type.
* @param headers Request headers represented as a Spring Framework {@link HttpHeaders}
* @param <T> The type that the extracted value should be converted to.
* @return The extracted value from the result, converted to type T
* @see <a href="https://github.com/json-path/JsonPath">JsonPath syntax docs</a>
* @see <a href="https://graphql.org/learn/queries/#variables">Query Variables</a>
* @see <a href="https://github.com/json-path/JsonPath#what-is-returned-when">Using TypeRef</a>
*/
<T> T executeAndExtractJsonPathAsObject(@Language("GraphQL") @NonNull String query,
@Language("JSONPath") @NonNull String jsonPath,
@NonNull Map<String, Object> variables,
@NonNull TypeRef<T> typeRef,
@Nullable HttpHeaders headers);
}
| 4,094 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsDataLoaderRegistryConsumer.java | /*
* 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;
import org.dataloader.DataLoaderRegistry;
/**
* Interface indicating that this DataLoader wants to be call-backed with a reference to the DataLoaderReference.
*/
public interface DgsDataLoaderRegistryConsumer {
/**
* Callback to retrieve the DataLoaderRegistry instance.
* @param dataLoaderRegistry Typically this is stored as an instance variable for later use.
*/
void setDataLoaderRegistry(DataLoaderRegistry dataLoaderRegistry);
}
| 4,095 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/InputArgument.java | /*
* 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;
import org.springframework.core.annotation.AliasFor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface InputArgument {
@AliasFor("name")
String value() default "";
@AliasFor("value")
String name() default "";
/**
* @deprecated Explicitly specifying the collectionType is not necessary, it will be inferred from the parameter type
*/
@Deprecated
Class<?> collectionType() default Object.class;
}
| 4,096 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsTypeDefinitionRegistry.java | /*
* 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;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DgsTypeDefinitionRegistry {
}
| 4,097 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsScalar.java | /*
* 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;
import org.springframework.stereotype.Component;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Mark a class as a custom Scalar implementation that gets registered to the framework.
* See https://netflix.github.io/dgs/scalars/
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
@Inherited
public @interface DgsScalar {
String name();
}
| 4,098 |
0 | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql | Create_ds/dgs-framework/graphql-dgs/src/main/java/com/netflix/graphql/dgs/DgsDispatchPredicate.java | /*
* Copyright 2022 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;
import com.netflix.graphql.dgs.internal.utils.DataLoaderNameUtil;
import org.springframework.stereotype.Component;
import java.lang.annotation.*;
/**
* Marks a class or field as a Dispatch Predicate for a ScheduledDataLoaderRegistry, which will be registered to the framework.
* The method must return an instance of DispatchPredicate.
* See https://netflix.github.io/dgs/data-loaders/
*/
//@Target(ElementType.METHOD)
@Target(ElementType.FIELD)
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface DgsDispatchPredicate {
}
| 4,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.