Package io.leangen.graphql.generator
Class OperationMapper
- java.lang.Object
-
- io.leangen.graphql.generator.OperationMapper
-
public class OperationMapper extends Object
Drives the work of mapping Java structures into their GraphQL representations.
While the task of mapping types is delegated to instances ofTypeMapper, selection of mappers, construction and attachment of resolvers (modeled byDataFetchers in graphql-java), and other universal tasks are encapsulated in this class.
-
-
Constructor Summary
Constructors Constructor Description OperationMapper(String queryRoot, String mutationRoot, String subscriptionRoot, BuildContext buildContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,org.dataloader.BatchLoaderWithContext<?,?>>getBatchResolvers()Collection<graphql.schema.GraphQLDirective>getDirectives()List<graphql.schema.GraphQLFieldDefinition>getMutations()Fetches all the mapped GraphQL fields representing mutations, ready to be attached to the root mutation type.List<graphql.schema.GraphQLFieldDefinition>getQueries()Fetches all the mapped GraphQL fields representing top-level queries, ready to be attached to the root query type.List<graphql.schema.GraphQLAppliedDirective>getSchemaDirectives()List<graphql.schema.GraphQLFieldDefinition>getSubscriptions()graphql.schema.GraphQLAppliedDirectivetoGraphQLAppliedDirective(Directive directive, BuildContext buildContext)graphql.schema.GraphQLDirectivetoGraphQLDirective(Directive directive, BuildContext buildContext)graphql.schema.GraphQLFieldDefinitiontoGraphQLField(String parentType, Operation operation, BuildContext buildContext)Maps a single operation to a GraphQL output field (as queries in GraphQL are nothing but fields of the root operation type).graphql.schema.GraphQLInputObjectFieldtoGraphQLInputField(InputField inputField, BuildContext buildContext)Maps a single field/property to a GraphQL input field.graphql.schema.GraphQLInputTypetoGraphQLInputType(AnnotatedType javaType, TypeMappingEnvironment env)graphql.schema.GraphQLInputTypetoGraphQLInputType(AnnotatedType javaType, Set<Class<? extends TypeMapper>> mappersToSkip, TypeMappingEnvironment env)Maps a Java type to a GraphQL input type.graphql.schema.GraphQLOutputTypetoGraphQLType(AnnotatedType javaType, TypeMappingEnvironment env)graphql.schema.GraphQLOutputTypetoGraphQLType(AnnotatedType javaType, Set<Class<? extends TypeMapper>> mappersToSkip, TypeMappingEnvironment env)Maps a Java type to a GraphQL output type.
-
-
-
Constructor Detail
-
OperationMapper
public OperationMapper(String queryRoot, String mutationRoot, String subscriptionRoot, BuildContext buildContext)
- Parameters:
buildContext- The shared context containing all the global information needed for mapping
-
-
Method Detail
-
toGraphQLField
public graphql.schema.GraphQLFieldDefinition toGraphQLField(String parentType, Operation operation, BuildContext buildContext)
Maps a single operation to a GraphQL output field (as queries in GraphQL are nothing but fields of the root operation type).- Parameters:
operation- The operation to map to a GraphQL output fieldbuildContext- The shared context containing all the global information needed for mapping- Returns:
- GraphQL output field representing the given operation
-
toGraphQLType
public graphql.schema.GraphQLOutputType toGraphQLType(AnnotatedType javaType, TypeMappingEnvironment env)
-
toGraphQLType
public graphql.schema.GraphQLOutputType toGraphQLType(AnnotatedType javaType, Set<Class<? extends TypeMapper>> mappersToSkip, TypeMappingEnvironment env)
Maps a Java type to a GraphQL output type. Delegates most of the work to applicableTypeMappers.See
TypeMapper.toGraphQLType(AnnotatedType, java.util.Set, TypeMappingEnvironment)- Parameters:
javaType- The Java type that is to be mapped to a GraphQL output typeenv- Contextual information about the current mapping- Returns:
- GraphQL output type corresponding to the given Java type
-
toGraphQLInputField
public graphql.schema.GraphQLInputObjectField toGraphQLInputField(InputField inputField, BuildContext buildContext)
Maps a single field/property to a GraphQL input field.- Parameters:
inputField- The field/property to map to a GraphQL input fieldbuildContext- The shared context containing all the global information needed for mapping- Returns:
- GraphQL input field representing the given field/property
-
toGraphQLInputType
public graphql.schema.GraphQLInputType toGraphQLInputType(AnnotatedType javaType, TypeMappingEnvironment env)
-
toGraphQLInputType
public graphql.schema.GraphQLInputType toGraphQLInputType(AnnotatedType javaType, Set<Class<? extends TypeMapper>> mappersToSkip, TypeMappingEnvironment env)
Maps a Java type to a GraphQL input type. Delegates most of the work to applicableTypeMappers.See
TypeMapper.toGraphQLInputType(AnnotatedType, java.util.Set, TypeMappingEnvironment)- Parameters:
javaType- The Java type that is to be mapped to a GraphQL input typeenv- Contextual information about the current mapping- Returns:
- GraphQL input type corresponding to the given Java type
-
toGraphQLDirective
public graphql.schema.GraphQLDirective toGraphQLDirective(Directive directive, BuildContext buildContext)
-
toGraphQLAppliedDirective
public graphql.schema.GraphQLAppliedDirective toGraphQLAppliedDirective(Directive directive, BuildContext buildContext)
-
getQueries
public List<graphql.schema.GraphQLFieldDefinition> getQueries()
Fetches all the mapped GraphQL fields representing top-level queries, ready to be attached to the root query type.- Returns:
- A list of GraphQL fields representing top-level queries
-
getMutations
public List<graphql.schema.GraphQLFieldDefinition> getMutations()
Fetches all the mapped GraphQL fields representing mutations, ready to be attached to the root mutation type.- Returns:
- A list of GraphQL fields representing mutations
-
getSubscriptions
public List<graphql.schema.GraphQLFieldDefinition> getSubscriptions()
-
getDirectives
public Collection<graphql.schema.GraphQLDirective> getDirectives()
-
getSchemaDirectives
public List<graphql.schema.GraphQLAppliedDirective> getSchemaDirectives()
-
-