graphql-java-codegen icon indicating copy to clipboard operation
graphql-java-codegen copied to clipboard

Test for ResolverArgumentAnnotations on ParameterizedFieldsResolvers

Open velo opened this issue 3 years ago • 1 comments

Hi peeps,

While testing the new ResolverArgumentAnnotations I noticed they are not applied to parameterized resolvers.

I made a test to show it, and start my way on code to fix, but, I was not happy with how I got it working (boolean forceAnnotations = true)

I narrow it down to this call. https://github.com/kobylynskyi/graphql-java-codegen/blob/master/src/main/java/com/kobylynskyi/graphql/codegen/mapper/FieldDefinitionsToResolverDataModelMapper.java#L239-L241

But not sure what I should do to fix it, should I add a boolean? Update mappingContext?

Any advice on how to do the fix is welcome


Description

Related to #983


Changes were made to:

  • [ ] Codegen library - Java
  • [ ] Codegen library - Kotlin
  • [ ] Codegen library - Scala
  • [ ] Maven plugin
  • [ ] Gradle plugin
  • [ ] SBT plugin ` I

velo avatar Sep 19 '22 21:09 velo

can confirm, the Annotation is not added to parameterized resolvers

PhilippS93 avatar Oct 12 '22 11:10 PhilippS93

Here is my current workaround, to be applied here : https://github.com/kobylynskyi/graphql-java-codegen/blob/f488214ac4ffcf8cd7e44f79f6a02695482ae644/src/main/java/com/kobylynskyi/graphql/codegen/mapper/AnnotationsMapper.java#L125

        // 6. Add annotations for resolver arguments
        if (!Utils.isEmpty(mappingContext.getResolverArgumentAnnotations())
                && (mappingContext.getOperationsName().contains(parentTypeName) 
                   || (def instanceof InputValueDefinition) && !mappingContext.getDocument().getInputDefinitions().stream().map(o -> o.getName()).collect(Collectors.toList()).contains(parentTypeName) ) ) {
            annotations.addAll(mappingContext.getResolverArgumentAnnotations());
        }

Basically annotate anything that is a InputValue, but is not a InputType, leaving (i think) only argument resolvers.

@kobylynskyi Not sure if this is satisfactory or if there is an existing utils method to do this assertion ?

clement-buchart avatar Oct 31 '22 07:10 clement-buchart