Class GraphQLTypeMapper
- Direct Known Subclasses:
JavaGraphQLTypeMapper,KotlinGraphQLTypeMapper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<graphql.language.Directive>getDirectives(graphql.language.NamedNode<?> def) getGenericsString(MappingContext mappingContext, String genericType, String typeParameter) Wrap string into generics typegetLanguageType(MappingContext mappingContext, graphql.language.Type<?> type) Convert GraphQL type to a corresponding language-specific typegetLanguageType(MappingContext mappingContext, graphql.language.Type<?> graphqlType, String name, String parentTypeName) Convert GraphQL type to a corresponding language-specific type (java/kotlin/etc)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)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)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)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)static StringgetMandatoryType(String typeName) static StringgetNestedTypeName(graphql.language.Type<?> graphqlType) Get nested type of GraphQL Type.getResponseReturnType(MappingContext mappingContext, ExtendedFieldDefinition operationDef, NamedDefinition namedDefinition, String computedTypeName) getTypeConsideringPrimitive(MappingContext mappingContext, NamedDefinition namedDefinition, String computedTypeName) protected booleanisInterfaceOrUnion(MappingContext mappingContext, String graphQLType) abstract booleanisPrimitive(String possiblyPrimitiveType) Check if the time is primitive.abstract StringwrapApiDefaultValueIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, graphql.language.InputValueDefinition inputValueDefinition, String defaultValue, String parentTypeName) Wraps type into ArgumentValue, if required.abstract StringwrapApiInputTypeIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, String parentTypeName) Wraps type into ArgumentValue, if required.abstract StringwrapApiReturnTypeIfRequired(MappingContext mappingContext, NamedDefinition namedDefinition, String parentTypeName) Wraps type into apiReturnType or subscriptionReturnType (defined in the mapping configuration).abstract StringwrapIntoList(MappingContext mappingContext, String type, boolean mandatory) Wrap language-specific type (java/kotlin/etc) intoList.abstract StringwrapSuperTypeIntoList(MappingContext mappingContext, String type, boolean mandatory) Return upper bounded wildcard for the given interface type:"Foo"becomes"List<? extends Foo>".
-
Constructor Details
-
GraphQLTypeMapper
public GraphQLTypeMapper()
-
-
Method Details
-
getNestedTypeName
Get nested type of GraphQL Type. Example:Event -> EventEvent! -> Event[Event!]! -> Event[[Event]] -> Event- Parameters:
graphqlType- GraphQL type- Returns:
- GraphQL type without List/NonNull wrapping
-
getMandatoryType
-
getDirectives
-
wrapIntoList
- Parameters:
type- The name of a type that will be wrapped intoList<>mappingContext- Global mapping contextmandatory- 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 contextmandatory- 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 contextnamedDefinition- Named definitionparentTypeName- 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:StringExample 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 contextnamedDefinition- Named definitionparentTypeName- 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 contextnamedDefinition- Named definitioninputValueDefinition- Input value definitiondefaultValue- Default valueparentTypeName- Name of the parent type- Returns:
- Java type wrapped into ArgumentValue
-
isPrimitive
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 contextgenericType- Generics typetypeParameter- Parameter of generics type- Returns:
- type wrapped into generics
-
getLanguageType
Convert GraphQL type to a corresponding language-specific type- Parameters:
mappingContext- Global mapping contexttype- 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 contextgraphqlType- GraphQL typename- GraphQL type nameparentTypeName- 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 contextgraphqlType- GraphQL typename- GraphQL type nameparentTypeName- Name of the parent typedirectives- 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 contextgraphqlType- GraphQL typename- GraphQL type nameparentTypeName- Name of the parent typemandatory- GraphQL type is non-nullcollection- 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 contextgraphqlType- GraphQL typename- GraphQL type nameparentTypeName- Name of the parent typemandatory- GraphQL type is non-nullcollection- GraphQL type is collectiondirectives- 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 contextgraphQLType- GraphQL typename- GraphQL type nameparentTypeName- Name of the parent typemandatory- GraphQL type is non-nullcollection- GraphQL type is collectiondirectives- 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
-