-
Notifications
You must be signed in to change notification settings - Fork 347
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
FunctionBuilder ignores parameters annotated with GraphQLIgnore #207
FunctionBuilder ignores parameters annotated with GraphQLIgnore #207
Conversation
Codecov Report
@@ Coverage Diff @@
## master #207 +/- ##
============================================
+ Coverage 98.35% 98.36% +<.01%
- Complexity 170 171 +1
============================================
Files 55 55
Lines 548 549 +1
Branches 94 95 +1
============================================
+ Hits 539 540 +1
Misses 4 4
Partials 5 5
Continue to review full report at Codecov.
|
Nice change! I agree that it makes sense to add even without the context of needing it in Spring |
@sgeb I am releasing 0.2.12 with the changes. https://github.com/ExpediaDotCom/graphql-kotlin/releases/tag/0.2.12 |
Great, thanks for the super quick reaction. BTW, I have a couple of more changes which could make sense to merge upstream. For example, I'm currently working around the fact that Not sure when I'll get to providing a PR though. |
Also, the Spring DI approach for nested queries described above has proven very convenient in my project. Happy to contribute it into this repo's example project. Is that something you'd be interested in? (again, not sure when I'll get to providing a PR though). |
More examples are always helpful and we would welcome any PRs made. With the changes to I.e. You can modify the return value used here: https://github.com/ExpediaDotCom/graphql-kotlin/blob/af9667df8fa8901e64dc11cf56147b01b0ab5dc5/src/main/kotlin/com/expedia/graphql/execution/FunctionDataFetcher.kt#L65 Is there some data that is not available to you that you need? |
Currently
FunctionBuilder
includes all parameters except those annotated withGraphQLContext
and those of typeDataFetchingEnvironment
: https://github.com/ExpediaDotCom/graphql-kotlin/blob/9915070a96b68d36528ee7cf28ba825e1e53dd85/src/main/kotlin/com/expedia/graphql/generator/types/FunctionBuilder.kt#L38-L41With this present change,
FunctionBuilder
would also ignore parameters annotated with@GraphQLIgnore
.What follows is my concrete use case in the context of a Spring app, but the change would be convenient in other situations as well.
===
The example in the repo resolves nested queries by virtue of a
lateinit var
field (see https://github.com/ExpediaDotCom/graphql-kotlin/blob/3132d8851d67f2147f08590207279841a74338ad/example/src/main/kotlin/com/expedia/graphql/sample/query/NestedQueries.kt), with the associated data fetcher component getting resolved from theBeanFactory
via a customSpringDataFetcherFactory
. This is quite cumbersome when nested queries require parameters, as seen here: https://github.com/ExpediaDotCom/graphql-kotlin/blob/3132d8851d67f2147f08590207279841a74338ad/example/src/main/kotlin/com/expedia/graphql/sample/query/NestedQueries.kt#L44-L49A more convenient way would be to provide the nested query as a function in the data class, with bean component parameters annotated with Spring's
@Autowired
. A customAutowiringFunctionDataFetcher
resolves these annotated parameters to appropriate beans retrieved from theBeanFactory
. The resulting data class looks as follows (contrived to match the repo's example):Consequently the logic of the nested query lives in the data class itself instead of a separate
DataFetcher
class. Note that in my project I don't actually call data repositories directly in the data classes. Instead, the business logic is encapsulated in UseCase classes and the query is merely a call to a specific UseCase or Service (usually a one-liner). In this case having the logic in the data class isn't an issue.Unfortunately the above approach doesn't currently work due to
FunctionBuilder
including all parameters, including the@Autowired @GraphQLIgnore
parameters. Hence my proposed change.