Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I found this one while doing some changes in Strawberry, it's a small bug, @Cito the fix looks ok to me, but not sure if it is the way you'd approach it, so feel free to change it :D
Basically when a
GraphQLDefaultInputis used with more than one type, which happens withextend_schema, every type gets the default value coerced for whichever type was queried first.Description from Claude:
coerce_default_valuememoizes the coerced default on theGraphQLDefaultInputobject, but the same object can be used with more than one type, and the memoized value was then reused for all of them: whichever type was coerced first decided the default for the others.extend_schemaruns into this, as it keeps thedefaultof existing arguments and input fields but replaces their types, so the original and the extended schema share the memoized value:Querying the extended schema first gives
{'newField': 'new'}to the original schema instead. The same happens when oneGraphQLDefaultInputis passed to arguments of different types. This gist runs that case with graphql-core 3.3.0 and graphql-js 17.0.2, which memoizes on the argument and isn't affected: https://gist.github.com/patrick91/f4c61c55dea911a9da311ad724e03f99The fix keeps the memoization on
GraphQLDefaultInput, so it still works for the variable signatures of fragment arguments, but stores the type the value was coerced to along with it, and only reuses the value for that type. Both are stored as one tuple, so concurrent coercions can't pair a type with another type's value.Tests:
memoizes_coercion_per_typeintest_coerce_input_value.pyandcoerces_default_values_with_extended_input_typesintest_extend_schema.py, which both fail without the change. The full test suite (also on Python 3.10), the doctests of both modules,ruff check src tests,ruff format --check src testsandmypy src testspass.I found this while looking into how defaults are shared between requests for strawberry-graphql/strawberry#4660 (Strawberry still uses
default_value, so it isn't affected).AI: I've done this with Claude.