Class GraphqlServerUtils
java.lang.Object
com.graphql_java_generator.server.util.GraphqlServerUtils
A class that contains utility method for the server mode
- Author:
- etienne-sf
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclassNameExtractor(Class<?> cls) Implementation of aClassNameTypeResolverto manage the possible prefix and suffix on the generated POJOs.enumValueToString(Object enumValue) Returns the given enumValue transformed a String, based on the String representation for this enumValues.
This method is based on thegraphQlValue()generated for each enum POJO.getArgument(Object jsonParsedValue, String graphQLTypeName, String javaTypeForIDType, Class<?> clazz) This method returns a GraphQL argument into the relevant Java object, within a data fetcher, from what has been parsed by the graphql-java engine from the incoming JSON request
-
Field Details
-
graphqlServerUtils
-
-
Constructor Details
-
GraphqlServerUtils
public GraphqlServerUtils()
-
-
Method Details
-
classNameExtractor
Implementation of aClassNameTypeResolverto manage the possible prefix and suffix on the generated POJOs.- Parameters:
cls- The class which name must be retrieved- Returns:
- The GraphQL type name that matches this class
-
getArgument
public Object getArgument(Object jsonParsedValue, String graphQLTypeName, String javaTypeForIDType, Class<?> clazz) This method returns a GraphQL argument into the relevant Java object, within a data fetcher, from what has been parsed by the graphql-java engine from the incoming JSON request- Type Parameters:
T- The class expected to be returned- Parameters:
jsonParsedValue- The value, read from the JSON in the GraphQL request. Only the part of the JSON map, related to the expected class is sent. It can be:- A
Map. This map will be transformed into an input object, as defined in the GraphQL schema, from the Map that has been read from the JSON object sent to the server. - A
List. In this case, returns a list of instances of the given clazz type. - Otherwise, the value is a scalar. At this stage, Custom Scalars have already been transformed into the relevant Java Type. So it must be a standard scalar. It is then mapped to the asked java type
- A
graphQLTypeName- The name of the GraphQL type, as defined in the GraphQL schema. This can be guessed from the given class for input types and objects, but not for scalars. So it must be provided.javaTypeForIDType- Value of the plugin parameter of the same name. This is necessary to properly manage fields of the ID GraphQL type, which must be transformed to this java type. This is useful only when mapping into input types.clazz- The class of the expected type. A new instance of this type will be returned, with its fields having been set by this method from the value in the map- Returns:
- An instance of the expected class. If the map is null, null is returned. Of the map is empty, anew instance is returned, with all its fields are left empty
-
enumValueToString
Returns the given enumValue transformed a String, based on the String representation for this enumValues.
This method is based on thegraphQlValue()generated for each enum POJO.- Parameters:
enumValue- May be null, a value of an enum POJO generated from the GraphQL schema, a list of values of any depth (for instance [[[Episode]]] would be a list of Episode enums of depth 3). The item of the list may be either enums (generated by the plugin) or Optional<? extends Enum> (where the content of the Optional is an enum generated by the plugin)- Returns:
- The same kind of list, but all enum values are replaced by the relevant String representation, based on the GraphQL schema.
-