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

Don't check for a convention when not one isn't needed #7019

Merged
merged 2 commits into from May 21, 2024

Conversation

SeanTAllen
Copy link
Contributor

When setting up filtering and sorting with UseFiltering and UseSorting, there are 3 different code paths that are traversed. Prior to this change, all 3 of them required that a convention be registered otherwise an exception would occur. However, for both filtering and sorting, only 1 of the code paths actually needs a convention. The other two do not use the convention at all.

This commit changes the filtering and sorting object field descriptor extensions to attempt to get a convention only within the block of code that requires a convention. By making this small change, the other two code paths that do not require a convention will no longer encounter an exception. Instead, filtering and sorting can be set up as expected.

This commit partially addresses #6983. We are able locally, with these changes applied, to use filtering and sorting from a type module by calling the versions of UseFiltering and UseSorting that take a type. Without the changes in this commit, we get the "no convention registered" error.

This change does not close #6983 as it is still possible to encounter the "no convention registered" exception and its suggested remedy of "Call AddFiltering() on the schema builder" doesn't work.

From what we can see, and have detailed in #6983, no conventions registered with the schema builder either directly or the defaults provided by AddFiltering and AddSorting are available at the time that a type module is run.

The result of this commit is to allow the usage UseFiltering and UseSorting with types created via a type module. The other option we are aware of is detailed by @jimitndiaye in #6975. Jimit routes around the convention problem by not using a convention at all in his custom middleware. A close examination of UseFilteringInternal at #6975 (reply in thread) will show this lack of convention usage as key to his fix. Instead of going the custom middleware route, we made these two small changes to Hot Chocolate. We prefer this approach.

When setting up filtering and sorting with UseFiltering and UseSorting,
there are 3 different code paths that are traversed. Prior to
this change, all 3 of them required that a convention be registered otherwise
an exception would occur. However, for both filtering and sorting, only 1 of
the code paths actually needs a convention. The other two do not use the
convention at all.

This commit changes the filtering and sorting object field descriptor extensions
to attempt to get a convention only within the block of code that requires a
convention. By making this small change, the other two code paths that do not
require a convention will no longer encounter an exception. Instead, filtering
and sorting can be set up as expected.

This commit partially addresses ChilliCream#6983. We are able locally, with these changes
applied, to use filtering and sorting from a type module by calling the versions
of `UseFiltering` and `UseSorting` that take a type. Without the changes in this
commit, we get the "no convention registered" error.

This change does not close ChilliCream#6983 as it is still possible to encounter the "no
convention registered" exception and its suggested remedy of
"Call `AddFiltering()` on the schema builder" doesn't work.

From what we can see, and have detailed in ChilliCream#6983, no conventions registered with
the schema builder either directly or the defaults provided by `AddFiltering`
and `AddSorting` are available at the time that a type module is run.

The result of this commit is to allow the usage `UseFiltering` and `UseSorting`
with types created via a type module. The other option we are aware of is
detailed by @jimitndiaye in ChilliCream#6975.
Jimit routes around the convention problem by not using a convention at all
in his custom middleware. A close examination of `UseFilteringInternal` at
ChilliCream#6975 (reply in thread)
will show this lack of convention usage as key to his fix. Instead of going
the custom middleware route, we made these two small changes to Hot Chocolate.
We prefer this approach.
@SeanTAllen
Copy link
Contributor Author

My editor made a couple extraneous whitespace changes. Let me know if you would like me to revert them.

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.16%. Comparing base (ab3909e) to head (c762100).
Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7019      +/-   ##
==========================================
- Coverage   72.85%   70.16%   -2.69%     
==========================================
  Files        2585     2585              
  Lines      129190   129491     +301     
==========================================
- Hits        94115    90857    -3258     
- Misses      35075    38634    +3559     
Flag Coverage Δ
unittests 70.16% <100.00%> (-2.69%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SeanTAllen
Copy link
Contributor Author

@michaelstaib ping to get your attention on this per your comment #6983 (comment)

@SeanTAllen
Copy link
Contributor Author

@PascalSenn in #6983, @michaelstaib said you should be pinged about this.

Copy link
Member

@PascalSenn PascalSenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PascalSenn
Copy link
Member

@SeanTAllen, sorry, I didn't have this on my radar! @michaelstaib, this looks good to me. It's just moving the convention resolution into the branch that actually needs it.

@michaelstaib michaelstaib merged commit 5db3777 into ChilliCream:main May 21, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to use Hot Chocolate's builtin in filtering with type modules
3 participants