Interface GraphqlClient
-
@ProviderType public interface GraphqlClient
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T,U>
GraphqlResponse<T,U>execute(GraphqlRequest request, java.lang.reflect.Type typeOfT, java.lang.reflect.Type typeOfU)Executes the given GraphQL request and deserializes the response data based on the types T and U.<T,U>
GraphqlResponse<T,U>execute(GraphqlRequest request, java.lang.reflect.Type typeOfT, java.lang.reflect.Type typeOfU, RequestOptions options)Executes the given GraphQL request and deserializes the response data based on the types T and U.GraphqlClientConfigurationgetConfiguration()Returns the complete configuration of the GraphQL client.java.lang.StringgetGraphQLEndpoint()Returns the URL of the used GraphQL server endpoint.java.lang.StringgetIdentifier()Returns the identifier of this GraphQL client and backing OSGi service.
-
-
-
Method Detail
-
getIdentifier
java.lang.String getIdentifier()
Returns the identifier of this GraphQL client and backing OSGi service. This can be set on JCR resources with thecq:graphqlClientproperty.- Returns:
- The identifier value of this client.
-
getGraphQLEndpoint
java.lang.String getGraphQLEndpoint()
Returns the URL of the used GraphQL server endpoint.- Returns:
- The backend GraphQL server endpoint used by this client.
-
getConfiguration
GraphqlClientConfiguration getConfiguration()
Returns the complete configuration of the GraphQL client.- Returns:
- GraphQL client configuration.
-
execute
<T,U> GraphqlResponse<T,U> execute(GraphqlRequest request, java.lang.reflect.Type typeOfT, java.lang.reflect.Type typeOfU)
Executes the given GraphQL request and deserializes the response data based on the types T and U. The type T is used to deserialize the 'data' object of the GraphQL response, and the type U is used to deserialize the 'errors' array of the GraphQL response. Each generic type can be a simple class or a generic class. To specify a simple class, just do:GraphqlResponse<MyData, MyError> response = graphqlClient.execute(request, MyData.class, MyError.class); MyData data = response.getData(); List<MyError> errors = response.getErrors();
To specify a generic type (usually for the type T), one can use theTypeTokenclass. For example:Type typeOfT = new TypeToken<List<String>>() {}.getType(); GraphqlResponse<List<String>, MyError> response = graphqlClient.execute(request, typeOfT, MyError.class); List<String> data = response.getData();- Type Parameters:
T- The generic type of the 'data' object in the JSON GraphQL response.U- The generic type of the elements of the 'errors' array in the JSON GraphQL response.- Parameters:
request- The GraphQL request.typeOfT- The type of the expected GraphQL response 'data' field.typeOfU- The type of the elements of the expected GraphQL response 'errors' field.- Returns:
- A GraphQL response.
- Throws:
java.lang.RuntimeException- if the GraphQL HTTP request does not return 200 or if the JSON response cannot be parsed or deserialized.
-
execute
<T,U> GraphqlResponse<T,U> execute(GraphqlRequest request, java.lang.reflect.Type typeOfT, java.lang.reflect.Type typeOfU, RequestOptions options)
Executes the given GraphQL request and deserializes the response data based on the types T and U. The type T is used to deserialize the 'data' object of the GraphQL response, and the type U is used to deserialize the 'errors' array of the GraphQL response. Each generic type can be a simple class or a generic class. To specify a simple class, just do:GraphqlResponse<MyData, MyError> response = graphqlClient.execute(request, MyData.class, MyError.class); MyData data = response.getData(); List<MyError> errors = response.getErrors();
To specify a generic type (usually for the type T), one can use theTypeTokenclass. For example:Type typeOfT = new TypeToken<List<String>>() {}.getType(); GraphqlResponse<List<String>, MyError> response = graphqlClient.execute(request, typeOfT, MyError.class); List<String> data = response.getData();- Type Parameters:
T- The generic type of the 'data' object in the JSON GraphQL response.U- The generic type of the elements of the 'errors' array in the JSON GraphQL response.- Parameters:
request- The GraphQL request.typeOfT- The type of the expected GraphQL response 'data' field.typeOfU- The type of the elements of the expected GraphQL response 'errors' field.options- An object holding options that can be set when executing the request.- Returns:
- A GraphQL response.
- Throws:
java.lang.RuntimeException- if the GraphQL HTTP request does not return 200 or if the JSON response cannot be parsed or deserialized.
-
-