leangen / graphql-spqr

Build a GraphQL service in seconds
Apache License 2.0
1.09k stars 179 forks source link

Fix: Description for input fields not set correctly (@GraphQLInputField#description is ignored) #468

Closed ErtugrulSener closed 11 months ago

ErtugrulSener commented 11 months ago

As I wrote here in my original thread: https://github.com/leangen/graphql-spqr/issues/466#issuecomment-1625892403 Descriptions set via the @GraphQLInputField annotation are not considered. I realized that when I printed the graphql schema by doing:

The source for the demo:

@GraphQLApi
@Component
public class DemoAPI {
    @GraphQLQuery(name = "demo")
    public DemoObject demoMethod(DemoObject demoObject) {
        return new DemoObject();
    }
}
@GraphQLType(name = "demo_object")
@Getter
@Setter
public class DemoObject {
    @GraphQLInputField(description = "important description\nabc")
    private String field;
}

The test class to generate the schema:

@SpringBootTest
class DemoApplicationTests {
    @Autowired
    private GraphQLSchema graphQLSchema;

    @Test
    void generateGraphQLSchema() throws IOException {
        String str = new SchemaPrinter().print(graphQLSchema);
        File newFile = new File("schema.graphqls");
        var fileWriter = new FileWriter(newFile);
        fileWriter.write(str);
        fileWriter.close();
    }
}

This will result in the following graphql schema:

... Directives left out for readability

"Query root"
type Query {
  demo(demoObject: demo_objectInput): demo_object
}

type demo_object {
  field: String
}

input demo_objectInput {
  field: String
}

With the fix:

... Directives left out for readability

"Query root"
type Query {
  demo(demoObject: demo_objectInput): demo_object
}

type demo_object {
  field: String
}

input demo_objectInput {
  """
  important description
  abc
  """
  field: String
}
kaqqao commented 11 months ago

This shouldn't be needed. The description is already discovered by Jackson here: https://github.com/leangen/graphql-spqr/blob/9b899d0defee4562534b7d8ce2fb17c1dc715e67/src/main/java/io/leangen/graphql/metadata/strategy/value/jackson/AnnotationIntrospector.java#L74

kaqqao commented 11 months ago

Oh, before trying anything else: are you using the jackson-kotlin module? That's practically a prerequisite for correct Kotlin⇔Jackson integration.

ErtugrulSener commented 11 months ago

Oh, before trying anything else: are you using the jackson-kotlin module? That's practically a prerequisite for correct Kotlin⇔Jackson integration.

@kaqqao No, I am not using it with kotlin or the jackson-kotlin module. I have a spring boot 3 java application. Here is the demo to reproduce the issue: https://github.com/ErtugrulSener/description-issue-demo-app

kaqqao commented 11 months ago

Oops, sorry, I saw no methods and immediately assumed Kotlin (when it was actually Lombok). Because a similar issue was reported with Kotlin recently.

kaqqao commented 11 months ago

Fixed it in AnnotationIntrospector in https://github.com/leangen/graphql-spqr/issues/469. But thanks again for discovering the bug!

ErtugrulSener commented 11 months ago

Fixed it in AnnotationIntrospector in https://github.com/leangen/graphql-spqr/issues/469. But thanks again for discovering the bug!

No problem, glad the bug is fixed now!