Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.kobylynskyi.graphql.codegen.mapper.GraphQLTypeMapper.getDirectives;
import static com.kobylynskyi.graphql.codegen.mapper.GraphQLTypeMapper.getMandatoryType;
Expand Down Expand Up @@ -123,9 +124,12 @@ public List<String> getAnnotations(MappingContext mappingContext, String graphQL
}
}
// 6. Add annotations for resolver arguments
if (!Utils.isEmpty(mappingContext.getResolverArgumentAnnotations())
&& mappingContext.getOperationsName().contains(parentTypeName)) {
annotations.addAll(mappingContext.getResolverArgumentAnnotations());
if (!Utils.isEmpty(mappingContext.getResolverArgumentAnnotations())) {
if (mappingContext.getOperationsName().contains(parentTypeName)
|| (def instanceof InputValueDefinition
&& !mappingContext.getInputsName().contains(parentTypeName))) {
annotations.addAll(mappingContext.getResolverArgumentAnnotations());
}
}
// 7. Add annotations for parametrized resolvers
if (!Utils.isEmpty(mappingContext.getParametrizedResolverAnnotations())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MappingContext implements GraphQLCodegenConfiguration {
private final Set<String> interfacesName;
private final Set<String> unionsName;
private final Set<String> operationsName;
private final Set<String> inputsName;
private final Map<String, Set<String>> interfaceChildren;
private final GeneratedInformation generatedInformation;
private final DataModelMapperFactory dataModelMapperFactory;
Expand All @@ -49,6 +50,8 @@ private MappingContext(File outputDirectory,
this.typesUnionsInterfacesNames = document.getTypesUnionsInterfacesNames();
this.interfacesName = document.getInterfacesNames();
this.unionsName = document.getUnionsNames();
this.inputsName = document.getInputDefinitions().stream().map(ExtendedDefinition::getName)
.collect(Collectors.toSet());
this.interfaceChildren = document.getInterfaceChildren();
this.generatedInformation = generatedInformation;
this.operationsName = document.getOperationsNames();
Expand Down Expand Up @@ -366,6 +369,10 @@ public Set<String> getOperationsName() {
return operationsName;
}

public Set<String> getInputsName() {
return inputsName;
}

public Map<String, Set<String>> getInterfaceChildren() {
return interfaceChildren;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ void generate_CustomAnnotationMappings_Multiple() throws Exception {
@Test
void generate_ResolverArgumentAnnotations() throws Exception {
mappingConfig.setGenerateDataFetchingEnvironmentArgumentInApis(true);
mappingConfig.setGenerateParameterizedFieldsResolvers(true);
mappingConfig.setResolverArgumentAnnotations(singleton(
"@org.springframework.graphql.data.method.annotation.Argument"));

Expand All @@ -212,6 +213,9 @@ void generate_ResolverArgumentAnnotations() throws Exception {
assertSameTrimmedContent(
new File("src/test/resources/expected-classes/annotation/QueryResolver_ArgumentAnnotations.java.txt"),
getFileByName(files, "QueryResolver.java"));
assertSameTrimmedContent(new File("src/test/resources/expected-classes/annotation/" +
"EventPropertyResolver_ArgumentAnnotations.java.txt"),
getFileByName(files, "EventPropertyResolver.java"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.kobylynskyi.graphql.test1;


/**
* Resolver for EventProperty
*/
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public interface EventPropertyResolver {

/**
* Properties
*/
java.util.List<EventProperty> child(EventProperty eventProperty, @org.springframework.graphql.data.method.annotation.Argument Integer first, @org.springframework.graphql.data.method.annotation.Argument Integer last, graphql.schema.DataFetchingEnvironment env) throws Exception;

/**
* Parent event of the property
*/
Event parent(EventProperty eventProperty, @org.springframework.graphql.data.method.annotation.Argument EventStatus withStatus, @org.springframework.graphql.data.method.annotation.Argument String createdAfter, graphql.schema.DataFetchingEnvironment env) throws Exception;

}