question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Java] Directive on ARGUMENT_DEFINITION is not propagated to generated mutation interface

See original GitHub issue

[Java] Custom directive for ARGUMENT_DEFINITION is not propagated to generated Java interface

Issue Description

Hello team,

I’m trying to declare a custom directive that is mapped to Java annotation. However, when applied to mutation’s argument it is not propagated to the generated Java’s interface method. Is there some important detail that I’m missing?

Thank you!

Steps to Reproduce

schema.graphql


directive @valid on ARGUMENT_DEFINITION

input SampleInput {
    name: String
}

type Mutation {
   sampleAction(input: SampleInput! @valid): String!
}

Expected Result

The generated method sampleAction has a parameter input annotated with @javax.validation.Valid.

public interface SampleActionMutationResolver extends graphql.kickstart.tools.GraphQLMutationResolver {

    @javax.validation.constraints.NotNull
    String sampleAction(@javax.validation.Valid SampleInput input);
}

Actual Result

The generated method sampleAction has a parameter input without @javax.validation.Valid annotation.

public interface SampleActionMutationResolver extends graphql.kickstart.tools.GraphQLMutationResolver {

    @javax.validation.constraints.NotNull
    String sampleAction(SampleInput input);
}

Your Environment and Setup

  • graphql-java-codegen version: 4.1.5
  • com.graphql-java-kickstart version: 11.0.0
  • Build tool: Gradle 6.8
  • Mapping Config:
graphqlCodegen {
    generateApis = true
    generateApisWithThrowsException = false
    parentInterfaces {
        queryResolver = "graphql.kickstart.tools.GraphQLQueryResolver"
        mutationResolver = "graphql.kickstart.tools.GraphQLMutationResolver"
        subscriptionResolver = "graphql.kickstart.tools.GraphQLSubscriptionResolver"
        resolver = "graphql.kickstart.tools.GraphQLResolver<{{TYPE}}>"
    }
    directiveAnnotationsMapping = [
            'valid': ['javax.validation.Valid']
    ]
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kobylynskyicommented, Mar 21, 2021

@enttq, Thanks for the contribution! I will soon release your changes as part of 4.1.6.

0reactions
jxnu-liguobincommented, Mar 22, 2021

My pleasure.

I tested the NotNull annotation in Scala and it seems to be useless. kotlin doesn’t need the NotNull annotation ,so I didn’t test

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add a non-schema directive? · Issue #246 - GitHub
I am supposed to be able to define a directive like this: directive ... ... to add a non-schema directive (I.E. for a...
Read more >
GraphQL specification
A document may contain operations (queries, mutations, and subscriptions) as well as fragments, a common unit of composition allowing for query reuse. A...
Read more >
GraphQL
A schema is defined in terms of the types and directives it supports as well as the root operation types for each kind...
Read more >
Graphql no resolver definied for interface/union - java
1 Answer 1 · how did you compile this line? if (javaObject instanceof Car) { how this CAR class is generated? · It's...
Read more >
Spring for GraphQL Documentation
A DataFetcher and other components invoked by GraphQL Java may not always execute on the same thread as the Spring MVC handler, for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found