Skip to content
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

ClosureDataFetchingEnvironment's fetchArguments is always empty #63

Closed
jamesdh opened this issue Jan 26, 2021 · 2 comments
Closed

ClosureDataFetchingEnvironment's fetchArguments is always empty #63

jamesdh opened this issue Jan 26, 2021 · 2 comments

Comments

@jamesdh
Copy link
Contributor

jamesdh commented Jan 26, 2021

When defining a custom property/field, the docs say we can use the provided fetchArguments for retrieving the fetch options or the list of join properties. However, it's perpetually empty, and hence we lose out on the automatic join operations.

Oddly enough, the test for this functionality appears to actually confirm this:

when:
def resp = graphQL.graphql("""
{
tag(id: ${grailsId}) {
id
name
posts {
id
tags {
name
}
}
}
}
""")
Map obj = resp.body().data.tag
then:
//queries.size() == 2 ignored due to GORM issue https://github.com/grails/grails-data-mapping/issues/989
queries[0] ==~ 'Hibernate: select this_.id as id[0-9]+_[0-9]+_[0-9]+_, this_.version as version[0-9]+_[0-9]+_[0-9]+_, this_.name as name[0-9]+_[0-9]+_[0-9]+_ from tag this_ where this_.id=\\? limit \\?\n'
queries[1] ==~ 'Hibernate: select this_.id as id[0-9]+_[0-9]+_[0-9]+_, this_.version as version[0-9]+_[0-9]+_[0-9]+_, this_.title as title[0-9]+_[0-9]+_[0-9]+_, this_.date_created as date_cre[0-9]+_[0-9]+_[0-9]+_, this_.last_updated as last_upd[0-9]+_[0-9]+_[0-9]+_, tags3_.post_tags_id as post_tag[0-9]+_[0-9]+_, tags_alias1_.id as tag_id[0-9]+_[0-9]+_, tags_alias1_.id as id[0-9]+_[0-9]+_[0-9]+_, tags_alias1_.version as version[0-9]+_[0-9]+_[0-9]+_, tags_alias1_.name as name[0-9]+_[0-9]+_[0-9]+_ from post this_ inner join post_tag tags3_ on this_.id=tags3_.post_tags_id inner join tag tags_alias1_ on tags3_.tag_id=tags_alias1_.id where tags_alias1_.id=\\?\n'

If you look at the second query, you can see it queried for more properties than were specified in the original query, and if you debug the actual test, you'll see that env.fetchArguments is always an empty Map. Hence the test is incorrect, given the actually expected behavior.

It appears this is the root cause:

if (properties.isEmpty()) {
return new LinkedHashMap<>();
}

So either that is intended (and arguably not very useful) and the docs are misleading, or the docs are correct and this is actually not functioning as intended.

@jamesdh
Copy link
Contributor Author

jamesdh commented Jan 27, 2021

Took another look at this tonight and I'm not sure what I was doing wrong earlier but I'm seeing the fetchArguments correctly now when debugging. Closing for now at least.

@jamesdh jamesdh closed this as completed Jan 27, 2021
@jamesdh
Copy link
Contributor Author

jamesdh commented Jan 27, 2021

Reopening this as it appears that fetchArguments is always null when using the property dsl to modify a current properties dataFetcher, but appears to be working correctly when using the add dsl.

@jamesdh jamesdh reopened this Jan 27, 2021
@jamesdh jamesdh closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant