Skip to content

feat: open FunctionDataFetcher methods for extension #582

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

Merged

Conversation

smyrick
Copy link
Contributor

@smyrick smyrick commented Jan 28, 2020

📝 Description

Open the internal methods to the protected scope so that we can more easily override specific methods to provide more features. Internally to Expedia Group we have the need to provide a CustomFunctionDataFetcher that overrides the get method. However we don't want to have to reimplement all the other methods as well that convert the classes and parse the arguments. Right now we are actually missing out on using the new feature to use List over array for input types. This could be fixed internally but it is already done in open source so we would like to take advantage of that.

Also this will now allow users to override the coroutine context that is used for suspending functions without having to create an entirely new data fetcher implementation.

For context I found this more helpful for our upgrade to graphql-kotlin 2.0.0-RC4.3

Open the internal methods to the protected scope so that we can more easily override specific methods to provide more features. Internally to Expedia Group we have the need to provide a CustomFunctionDataFetcher that overrides the get method. However we don't want to have to reimplement all the other methods as well that covert the classes and parse the names. Right now we are actually missing out on using the new feature to use List over array for input types. This could be fixed internally but it is already done in open source so we would like to take advantage of that
@smyrick smyrick added type: enhancement New feature or request changes: minor Changes require a minor version labels Jan 28, 2020
@dariuszkuc
Copy link
Collaborator

FunctionDataFetcher is an implementation of DataFetcher interface which only exposes single fun get(environment: DataFetchingEnvironment): Any? function. If one were to extend the FunctionDataFetcher there is no guarantee that any of those methods will be called as one could potentially just override get method again therefore I don't think this is a good idea (also unsure why FunctionDataFetcher is an open class anyway).

Maybe those functions should be made extensions functions (i.e. Java static methods) on the DataFetcher instead?

@smyrick
Copy link
Contributor Author

smyrick commented Jan 29, 2020

@dariuszkuc This came up because in our CustomFunctionDataFetcher we override get with our own implementation because we need to get data from the context to set the thread execution for our tracing data using Haystack.

Is there a better way we can run this custom code but still reuse the other parts in graphql-kotlin around parsing parameter values? Currently we don't have access to get the simple graphql name of a param by checking the annotation and we would also have to implement the logic to get the proper class info

See the logic in convertParameterValue

@dariuszkuc
Copy link
Collaborator

@smyrick "proper way" would be to rewrite query execution logic in Kotlin native way and eliminate the dependency on CompletableFuture. Currently we are switching from reactor->coroutine->completable future->coroutine which breaks structured concurrency and requires those workarounds.

That being said for the time being, even though it is not ideal I'm fine with this workaround.

@dariuszkuc dariuszkuc merged commit 7de847b into ExpediaGroup:master Jan 30, 2020
smyrick pushed a commit to smyrick/graphql-kotlin that referenced this pull request Jan 31, 2020
In ExpediaGroup#582 we opened some method of the FunctionDataFetcher so we could run some custom behaviour. Looking back at that change I realize that we only need to make the methods protected, not open, and that we can hide some others still as private. We just need to expose all the methods that we call in the basic implementation of get as protected so we can all those from custom implementations.
@smyrick smyrick deleted the function-data-fetcher-override branch September 3, 2020 21:55
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
Open the internal methods to the protected scope so that we can more easily override specific methods to provide more features. Internally to Expedia Group we have the need to provide a CustomFunctionDataFetcher that overrides the get method. However we don't want to have to reimplement all the other methods as well that covert the classes and parse the names. Right now we are actually missing out on using the new feature to use List over array for input types. This could be fixed internally but it is already done in open source so we would like to take advantage of that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: minor Changes require a minor version type: enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants