Class GraphQLTypeMapper

java.lang.Object
io.github.besi97.graphql.codegen.mapper.GraphQLTypeMapper
Direct Known Subclasses:
JavaGraphQLTypeMapper, KotlinGraphQLTypeMapper

public abstract class GraphQLTypeMapper extends Object
Map GraphQL type to language-specific type (java/kotlin/etc)
  • Constructor Details

    • GraphQLTypeMapper

      public GraphQLTypeMapper()
  • Method Details

    • getNestedTypeName

      public static String getNestedTypeName(graphql.language.Type<?> graphqlType)
      Get nested type of GraphQL Type. Example: Event -> Event Event! -> Event [Event!]! -> Event [[Event]] -> Event
      Parameters:
      graphqlType - GraphQL type
      Returns:
      GraphQL type without List/NonNull wrapping
    • getMandatoryType

      public static String getMandatoryType(String typeName)
    • getDirectives

      public static List<graphql.language.Directive> getDirectives(graphql.language.NamedNode<?> def)
    • wrapIntoList

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

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

      public abstract String wrapApiReturnTypeIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, String parentTypeName)
      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>

      Parameters:
      mappingContext - Global mapping context
      namedDefinition - Named definition
      parentTypeName - Name of the parent type
      Returns:
      Java/Kotlin type wrapped into the subscriptionReturnType
    • wrapApiInputTypeIfRequired

      public abstract String wrapApiInputTypeIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, String parentTypeName)
      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>

      Parameters:
      mappingContext - Global mapping context
      namedDefinition - Named definition
      parentTypeName - Name of the parent type
      Returns:
      Java type wrapped into ArgumentValue
    • wrapApiDefaultValueIfRequired

      public abstract String wrapApiDefaultValueIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, graphql.language.InputValueDefinition inputValueDefinition, String defaultValue, String parentTypeName)
      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")

      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
    • isPrimitive

      public abstract boolean isPrimitive(String possiblyPrimitiveType)
      Check if the time is primitive.
      Parameters:
      possiblyPrimitiveType - type to check
      Returns:
      true if the provided type is primitive, false if the provided type is not primitive
    • getGenericsString

      public String getGenericsString(MappingContext mappingContext, String genericType, String typeParameter)
      Wrap string into generics type
      Parameters:
      mappingContext - Global mapping context
      genericType - Generics type
      typeParameter - Parameter of generics type
      Returns:
      type wrapped into generics
    • getLanguageType

      public String getLanguageType(MappingContext mappingContext, graphql.language.Type<?> type)
      Convert GraphQL type to a corresponding language-specific type
      Parameters:
      mappingContext - Global mapping context
      type - GraphQL type
      Returns:
      Corresponding language-specific type (java/kotlin/etc)
    • getLanguageType

      public NamedDefinition getLanguageType(MappingContext mappingContext, graphql.language.Type<?> graphqlType, String name, String parentTypeName)
      Convert GraphQL type to a corresponding language-specific type (java/kotlin/etc)
      Parameters:
      mappingContext - Global mapping context
      graphqlType - GraphQL type
      name - GraphQL type name
      parentTypeName - Name of the parent type
      Returns:
      Corresponding language-specific type (java/kotlin/etc)
    • getLanguageType

      public NamedDefinition getLanguageType(MappingContext mappingContext, graphql.language.Type<?> graphqlType, String name, String parentTypeName, List<graphql.language.Directive> directives)
      Convert GraphQL type to a corresponding language-specific type (java/kotlin/etc)
      Parameters:
      mappingContext - Global mapping context
      graphqlType - GraphQL type
      name - GraphQL type name
      parentTypeName - Name of the parent type
      directives - GraphQL field directives
      Returns:
      Corresponding language-specific type (java/kotlin/etc)
    • getLanguageType

      public NamedDefinition getLanguageType(MappingContext mappingContext, graphql.language.Type<?> graphqlType, String name, String parentTypeName, boolean mandatory, boolean collection)
      Convert GraphQL type to a corresponding language-specific type (java/kotlin/etc)
      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
      Returns:
      Corresponding language-specific type (java/kotlin/etc)
    • getLanguageType

      public NamedDefinition getLanguageType(MappingContext mappingContext, graphql.language.Type<?> graphqlType, String name, String parentTypeName, boolean mandatory, boolean collection, List<graphql.language.Directive> directives)
      Convert GraphQL type to a corresponding language-specific type (java/kotlin/etc)
      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)
    • getLanguageType

      public NamedDefinition getLanguageType(MappingContext mappingContext, String graphQLType, String name, String parentTypeName, boolean mandatory, boolean collection, List<graphql.language.Directive> directives)
      Convert GraphQL type to a corresponding language-specific type (java/kotlin/etc)
      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)
    • getTypeConsideringPrimitive

      public String getTypeConsideringPrimitive(MappingContext mappingContext, NamedDefinition namedDefinition, String computedTypeName)
    • getResponseReturnType

      public String getResponseReturnType(MappingContext mappingContext, ExtendedFieldDefinition operationDef, NamedDefinition namedDefinition, String computedTypeName)
    • isInterfaceOrUnion

      protected boolean isInterfaceOrUnion(MappingContext mappingContext, String graphQLType)