Skip to content

Commit bebdc29

Browse files
Add resolver argument annotation on input value
Signed-off-by: Clément BUCHART <[email protected]>
1 parent cbc426c commit bebdc29

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/main/java/com/kobylynskyi/graphql/codegen/mapper/AnnotationsMapper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.stream.Collectors;
2324

2425
import static com.kobylynskyi.graphql.codegen.mapper.GraphQLTypeMapper.getDirectives;
2526
import static com.kobylynskyi.graphql.codegen.mapper.GraphQLTypeMapper.getMandatoryType;
@@ -123,9 +124,12 @@ public List<String> getAnnotations(MappingContext mappingContext, String graphQL
123124
}
124125
}
125126
// 6. Add annotations for resolver arguments
126-
if (!Utils.isEmpty(mappingContext.getResolverArgumentAnnotations())
127-
&& mappingContext.getOperationsName().contains(parentTypeName)) {
128-
annotations.addAll(mappingContext.getResolverArgumentAnnotations());
127+
if (!Utils.isEmpty(mappingContext.getResolverArgumentAnnotations())) {
128+
if (mappingContext.getOperationsName().contains(parentTypeName)
129+
|| (def instanceof InputValueDefinition
130+
&& !mappingContext.getInputsName().contains(parentTypeName))) {
131+
annotations.addAll(mappingContext.getResolverArgumentAnnotations());
132+
}
129133
}
130134
// 7. Add annotations for parametrized resolvers
131135
if (!Utils.isEmpty(mappingContext.getParametrizedResolverAnnotations())

src/main/java/com/kobylynskyi/graphql/codegen/model/MappingContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class MappingContext implements GraphQLCodegenConfiguration {
3131
private final Set<String> interfacesName;
3232
private final Set<String> unionsName;
3333
private final Set<String> operationsName;
34+
private final Set<String> inputsName;
3435
private final Map<String, Set<String>> interfaceChildren;
3536
private final GeneratedInformation generatedInformation;
3637
private final DataModelMapperFactory dataModelMapperFactory;
@@ -49,6 +50,8 @@ private MappingContext(File outputDirectory,
4950
this.typesUnionsInterfacesNames = document.getTypesUnionsInterfacesNames();
5051
this.interfacesName = document.getInterfacesNames();
5152
this.unionsName = document.getUnionsNames();
53+
this.inputsName = document.getInputDefinitions().stream().map(ExtendedDefinition::getName)
54+
.collect(Collectors.toSet());
5255
this.interfaceChildren = document.getInterfaceChildren();
5356
this.generatedInformation = generatedInformation;
5457
this.operationsName = document.getOperationsNames();
@@ -366,6 +369,10 @@ public Set<String> getOperationsName() {
366369
return operationsName;
367370
}
368371

372+
public Set<String> getInputsName() {
373+
return inputsName;
374+
}
375+
369376
public Map<String, Set<String>> getInterfaceChildren() {
370377
return interfaceChildren;
371378
}

src/test/resources/expected-classes/annotation/EventPropertyResolver_ArgumentAnnotations.java.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public interface EventPropertyResolver {
1313
/**
1414
* Properties
1515
*/
16-
java.util.List<EventProperty> child(EventProperty eventProperty, Integer first, Integer last, graphql.schema.DataFetchingEnvironment env) throws Exception;
16+
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;
1717

1818
/**
1919
* Parent event of the property
2020
*/
21-
Event parent(EventProperty eventProperty, EventStatus withStatus, String createdAfter, graphql.schema.DataFetchingEnvironment env) throws Exception;
21+
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;
2222

2323
}

0 commit comments

Comments
 (0)