-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spring-graphql compatible code generation #983
Comments
The custom annotations mapping you provided works well for me too. The main issue for me is not being able to annotate the arguments with @argument. Maybe a customResolverArgumentAnnotations option would be good? It could just take a list of annotations to be applied to all arguments. But not the DataFetchingEnvironment etc |
We recently adopted Spring for GraphQL and set up graphql-java-codegen today. Thanks to the comment of @msl-at-fcb we've got up and running relatively easy. In addition to using customAnnotationsMapping for the root types tasks {
named<GraphQLCodegenGradleTask>("graphqlCodegen") {
// ...
fieldsWithResolvers = setOf("Foo.bar")
val customResolverMappings = fieldsWithResolvers.associateWith { field ->
val type = field.substringBefore('.')
listOf("""org.springframework.graphql.data.method.annotation.SchemaMapping(typeName = "$type")""")
}
customAnnotationsMapping.addAll(customResolverMappings)
}
} This works fine but involves quite some boilerplate which is likely to to be duplicated for other projects as well. Thus I would love to see explicit support for Spring for GraphQL being part of graphql-java-codegen. Beside the aforementioned annotations I would like to see support for @BatchMapping. This however we did not get to work as I don't see any way to tell graphql-java-codegen to generate a mapping of e.g. Disclaimer: There might be some typos in the code above, as I'm writing this on my phone right now. But I assume one gets the idea. |
Added support of 2 configs:
|
Very nice, thanks for adding this @kobylynskyi! We'll migrate as soon as it's available. Any chance for adding |
@EndzeitBegins the problem with supporting FieldType field(Type type); // that's what we generate today
Mono<Map<Type, FieldType>> field(List<Type> types); // that's what should be generated to support @BatchMapping |
This looks perfect, will also give it a try as soon as it's available, thanks! |
I'm aware of that. Actually, there are multiple type signatures supported by Spring for GraphQL, e.g. But I can understand if that's a lot more difficult to support than just adding additional annotations. |
Given @kobylynskyi's other helpful commits for the other annotations, is it implied that for Is that configuration expressible with the Maven plugin? "customAnnotationsMapping": {
"^Query\\.\\w+$": ["org.springframework.graphql.data.method.annotation.QueryMapping"],
"^Mutation\\.\\w+$": ["org.springframework.graphql.data.method.annotation.MutationMapping"],
"^Subscription\\.\\w+$": ["org.springframework.graphql.data.method.annotation.SubscriptionMapping"]
} My understanding was this would have to map to something like: <customAnnotationsMapping>
<^Query\\.\\w+$>
<annotation>org.springframework.graphql.data.method.annotation.QueryMapping</annotation>
</^Query\\.\\w+$>
</customAnnotationsMapping> Which I don't believe is expressible in xml unless I'm missing some way of escaping it. If I understand correctly it is these lines which allow the key to be a pattern, which would appear to explain how the configuration@msl-at-fcb provided works, I'm just not sure how to express it in maven. graphql-java-codegen/src/main/java/com/kobylynskyi/graphql/codegen/mapper/AnnotationsMapper.java Lines 134 to 139 in 9a64c33
If it's not currently expressible as-is, I wonder if it can be passed as a tag attribute instead? e.g. <Query pattern="^Query\\.\\w+$"> I'm not sure if that's possible with Maven though since it would appear that the code already receives the tag as a string, but I admit I know nothing about maven plugins: Line 671 in 0198f41
|
@blaenk Yeah I'm not sure it is possible directly in your pom but you can just use the .json config instead so your json config would include this:
And in your pom:
Using the json config makes your pom way less cluttered too |
Thank you @JamesPeters98 I completely missed that a JSON config was even possible. It did seem like that's what that code snippet was (JSON) but I thought for sure there couldn't be a JSON config mechanism and assumed it to be Groovy/Gradle! Thanks again I appreciate it! |
A bit off topic, but...
Yep, that's pretty much our setup. Anything that needs to know about maven goes in pom.xml (eg |
🚀 Released version 5.5.0 today which contains new configs: Support for |
@kobylynskyi , can we also add a configuration to add arbitrary parameters in generated resolvers? With this, we could provide a list of additional parameter names/types and also do not need Best, |
Now that spring-graphql is 1.0 and reasonably stable, it would be good to provide first class support for their structures.
Currently @QueryMapping, @MutationMapping and @SubscriptionMapping can be shoe-horned in via customAnnotationsMapping with something like:
But that falls short on parameterised resolvers, or resolvers for extensions which are generated separately which rely on spring's
@SchemaMapping(typeName = "MyGraphQLType")
(and so need to be manually added)Likewise use of
@Argument
for all input parameters can be manually added to the implementing classes, but would be convenient to have on the generated interfaces.There are other parameter types that can be provided (see https://docs.spring.io/spring-graphql/docs/current/reference/html/#controllers). Adding these with similar configuration as exists today for DataFetchingEnvironment would also be useful and would provide reasonably complete with what spring-graphql offers.
Also note that there is a feature request in spring-graphql for code generation: spring-projects/spring-graphql#159 which would effectively be solved with this functionality.
The text was updated successfully, but these errors were encountered: