Class KotlinGraphQLTypeMapper

java.lang.Object
io.github.besi97.graphql.codegen.mapper.GraphQLTypeMapper
io.github.besi97.graphql.codegen.kotlin.KotlinGraphQLTypeMapper

public class KotlinGraphQLTypeMapper extends GraphQLTypeMapper
Mapper class for converting GraphQL types to Kotlin types
Since:
2020/12/09
  • Field Details

    • KOTLIN_UTIL_LIST_ELEMENT_REGEX

      public static final Pattern KOTLIN_UTIL_LIST_ELEMENT_REGEX
  • Constructor Details

    • KotlinGraphQLTypeMapper

      public KotlinGraphQLTypeMapper()
  • Method Details

    • isKotlinPrimitive

      public static boolean isKotlinPrimitive(String scalaType)
    • defaultValueKotlinPrimitive

      public static String defaultValueKotlinPrimitive(String kotlinType)
      This method is used in kotlin template, do not remove it.
      Parameters:
      kotlinType - type get from Type template
      Returns:
      default value
    • 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)
      Description copied from class: GraphQLTypeMapper
      Wraps type into apiReturnType or subscriptionReturnType (defined in the mapping configuration).

      Example 1: * Given GraphQL schema: type Query { events: [Event!]! } * Given config: useOptionalForNullableReturnTypes = true * Return: java.util.Optional<Event>

      Example 2: * Given GraphQL schema: type Subscription { eventsCreated: [Event!]! } * Given subscriptionReturnType in config: org.reactivestreams.Publisher * Return: org.reactivestreams.Publisher<Event>

      Example 3: * Given GraphQL schema: type Mutation { createEvent(inp: Inp): Event } * Given apiReturnType in config: reactor.core.publisher.Mono * Return: reactor.core.publisher.Mono<Event>

      Example 4: * Given GraphQL schema: type Query { events: [Event!]! } * Given apiReturnListType in config: reactor.core.publisher.Flux * Return: reactor.core.publisher.Flux<Event>

      Specified by:
      wrapApiReturnTypeIfRequired in class GraphQLTypeMapper
      Parameters:
      mappingContext - Global mapping context
      namedDefinition - Named definition
      parentTypeName - Name of the parent type
      Returns:
      Java/Kotlin type wrapped into the subscriptionReturnType
    • isPrimitive

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

      public String getTypeConsideringPrimitive(MappingContext mappingContext, NamedDefinition namedDefinition, String computedTypeName)
      Overrides:
      getTypeConsideringPrimitive in class GraphQLTypeMapper
    • getResponseReturnType

      public String getResponseReturnType(MappingContext mappingContext, ExtendedFieldDefinition operationDef, NamedDefinition namedDefinition, String computedTypeName)
      Overrides:
      getResponseReturnType in class GraphQLTypeMapper
    • 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