Class JavaGraphQLTypeMapper

java.lang.Object
io.github.besi97.graphql.codegen.mapper.GraphQLTypeMapper
io.github.besi97.graphql.codegen.java.JavaGraphQLTypeMapper

public class JavaGraphQLTypeMapper extends GraphQLTypeMapper
Mapper class for converting GraphQL types to Java types
  • Field Details

    • JAVA_UTIL_LIST

      public static final String JAVA_UTIL_LIST
      See Also:
    • JAVA_UTIL_LIST_ELEMENT_REGEX

      public static final Pattern JAVA_UTIL_LIST_ELEMENT_REGEX
  • Constructor Details

    • JavaGraphQLTypeMapper

      public JavaGraphQLTypeMapper()
  • Method Details

    • isJavaPrimitive

      public static boolean isJavaPrimitive(String possiblyPrimitiveType)
    • wrapIntoList

      public String wrapIntoList(MappingContext mappingContext, String type, boolean mandatory)
      Description copied from class: GraphQLTypeMapper
      Wrap language-specific type (java/kotlin/etc) into List. E.g.: String becomes List<String>
      Specified by:
      wrapIntoList in class GraphQLTypeMapper
      Parameters:
      mappingContext - Global mapping context
      type - The name of a type that will be wrapped into List<>
      mandatory - Type is it mandatory
      Returns:
      String The name of the given type, wrapped into List<>
    • wrapSuperTypeIntoList

      public String wrapSuperTypeIntoList(MappingContext mappingContext, String type, boolean mandatory)
      Description copied from class: GraphQLTypeMapper
      Return upper bounded wildcard for the given interface type: "Foo" becomes "List<? extends Foo>".
      Specified by:
      wrapSuperTypeIntoList in class GraphQLTypeMapper
      Parameters:
      mappingContext - Global mapping context
      type - The name of a type whose upper bound wildcard will be wrapped into a list.
      mandatory - Type is it mandatory
      Returns:
      String The name of the the wrapped type.
    • wrapApiReturnTypeIfRequired

      public String wrapApiReturnTypeIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, String parentTypeName)
      Wrap return type of the API interface with generics and/or Optional and/or apiReturnType (as specified in the mapping configuration)
      Specified by:
      wrapApiReturnTypeIfRequired in class GraphQLTypeMapper
      Parameters:
      mappingContext - Global mapping context
      namedDefinition - Named definition
      parentTypeName - Name of the parent type
      Returns:
      API interface name
    • isPrimitive

      public boolean isPrimitive(String possiblyPrimitiveType)
      Description copied from class: GraphQLTypeMapper
      Check if the time is primitive.
      Specified by:
      isPrimitive in class GraphQLTypeMapper
      Parameters:
      possiblyPrimitiveType - type to check
      Returns:
      true if the provided type is primitive, false if the provided type is not primitive
    • getLanguageType

      public NamedDefinition getLanguageType(MappingContext mappingContext, String graphQLType, String name, String parentTypeName, boolean mandatory, boolean collection, List<graphql.language.Directive> directives)
      Description copied from class: GraphQLTypeMapper
      Convert GraphQL type to a corresponding language-specific type (java/kotlin/etc)
      Overrides:
      getLanguageType in class GraphQLTypeMapper
      Parameters:
      mappingContext - Global mapping context
      graphQLType - GraphQL type
      name - GraphQL type name
      parentTypeName - Name of the parent type
      mandatory - GraphQL type is non-null
      collection - GraphQL type is collection
      directives - GraphQL field directives
      Returns:
      Corresponding language-specific type (java/kotlin/etc)
    • wrapApiInputTypeIfRequired

      public String wrapApiInputTypeIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, String parentTypeName)
      Description copied from class: GraphQLTypeMapper
      Wraps type into ArgumentValue, if required.

      Example 1: * Given GraphQL schema: input MyInput { name: String! } * Given config: useWrapperForNullableInputTypes = true * Return: String

      Example 2: * Given GraphQL schema: input MyInput { name: String } * Given config: useWrapperForNullableInputTypes = true * Return: ArgumentValue<String>

      Example 2: * Given GraphQL schema: input MyInput { name: String[] } * Given config: useWrapperForNullableInputTypes = true * Return: List<String>

      Specified by:
      wrapApiInputTypeIfRequired in class GraphQLTypeMapper
      Parameters:
      mappingContext - Global mapping context
      namedDefinition - Named definition
      parentTypeName - Name of the parent type
      Returns:
      Java type wrapped into ArgumentValue
    • wrapApiDefaultValueIfRequired

      public String wrapApiDefaultValueIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, graphql.language.InputValueDefinition inputValueDefinition, String defaultValue, String parentTypeName)
      Description copied from class: GraphQLTypeMapper
      Wraps type into ArgumentValue, if required.

      Example 1: * Given GraphQL schema: input MyInput { name: String } * Given config: useWrapperForNullableInputTypes = true * Return: ArgumentValue.omitted()

      Example 2: * Given GraphQL schema: input MyInput { name: String = null } * Given config: useWrapperForNullableInputTypes = true * Return: ArgumentValue.ofNullable(null)

      Example 2: * Given GraphQL schema: input MyInput { name: String = "some value" } * Given config: useWrapperForNullableInputTypes = true * Return: ArgumentValue.ofNullable("some value")

      Specified by:
      wrapApiDefaultValueIfRequired in class GraphQLTypeMapper
      Parameters:
      mappingContext - Global mapping context
      namedDefinition - Named definition
      inputValueDefinition - Input value definition
      defaultValue - Default value
      parentTypeName - Name of the parent type
      Returns:
      Java type wrapped into ArgumentValue