Type extension field name uniqueness is checked only once#4076
Type extension field name uniqueness is checked only once#4076
Conversation
…raphql-java into xuorig-field-extension-uniqueness-perf
| forEachBut(extension, extensions, | ||
| otherTypeExt -> checkForFieldRedefinition(errors, otherTypeExt, otherTypeExt.getFieldDefinitions(), fieldDefinitions)); | ||
|
|
||
| // |
There was a problem hiding this comment.
This code here is inside a loop already - so
- for every type extentions
- do this check where we loop every type extension
This created a N*M loop
| extensions, | ||
| ObjectTypeDefinition::getFieldDefinitions | ||
| ); | ||
|
|
There was a problem hiding this comment.
The new code is OUTSIDE the extentions loop and the new checkForTypeExtensionFieldUniqueness loops extensions only once for field unique names so its order N
| errors, | ||
| extensions, | ||
| InterfaceTypeDefinition::getFieldDefinitions | ||
| ); |
There was a problem hiding this comment.
same but for interfaces
| errors, | ||
| extensions, | ||
| InputObjectTypeDefinition::getInputValueDefinitions | ||
| ); |
There was a problem hiding this comment.
some but for input types
Test Results 325 files - 650 325 suites - 650 3m 31s ⏱️ - 7m 5s Results for commit 1001ed4. ± Comparison against base commit 0b5c762. This pull request removes 517 and adds 148 tests. Note that renamed tests count towards both.This pull request skips 1 test.♻️ This comment has been updated with latest results. |
|
I just looked into graphql-js to see how they do it and they dont do "extends type" validation at "node -> fields creation time" function buildFieldMap( } This might be faster but its likely less precise - eg which extend type led to the error say. Maybe this is not true. The spec is not precise here https://spec.graphql.org/October2021/#sec-Object-Extensions Object type extensions have the potential to be invalid if incorrectly defined. The named type must already be defined and must be an Object type. Does this mean unique with a single extend type node or with all extend type nodes? I guess its all nodes since this is how we are treating it today (via our repeated looping) |
…tensions - for completeness did enums as well
| expect: | ||
|
|
||
| !result.isEmpty() | ||
| result.size() == 4 |
There was a problem hiding this comment.
I was curious what the extra error was: it is a field redefinition error, not a NonUniqueNameError like the others in this list.
'Query' extension type [@8:13] tried to redefine field 'fieldB' [@10:17]
There was a problem hiding this comment.
This is fine to have another error, it is correct anyway
…ion-uniqueness-perf # Conflicts: # src/main/java/graphql/schema/idl/SchemaTypeExtensionsChecker.java
…ion-uniqueness-perf
This is related to #4034 but supersedes it. This is more performant than @xuorig original PR.
This iterates the list of type extensions (for a type kind) only once to check if fields are unique
Before this iterated ALL type extensions (for a type kind) multiple times (once per type extension)