-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Made the field definition lookup more optimised #3494
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aaa0083
Made the field definition lookup more optimised
bbakerman abb8801
Merge remote-tracking branch 'origin/master' into make-get-field-defi…
bbakerman 6b242d4
Removed old usages and deprecated the old
bbakerman a27be65
No longer deprecated
bbakerman b5f3df8
Made old code the same
bbakerman d656741
Made old code the same - more of that
bbakerman 9669753
Made old code the same - more of that - bad import
bbakerman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -784,7 +784,8 @@ public static boolean isIntrospectionTypes(String typeName) { | |
|
|
||
| /** | ||
| * This will look up a field definition by name, and understand that fields like __typename and __schema are special | ||
| * and take precedence in field resolution | ||
| * and take precedence in field resolution. If the parent type is a union type, then the only field allowed | ||
| * is `__typename`. | ||
| * | ||
| * @param schema the schema to use | ||
| * @param parentType the type of the parent object | ||
|
|
@@ -794,6 +795,43 @@ public static boolean isIntrospectionTypes(String typeName) { | |
| */ | ||
| public static GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLCompositeType parentType, String fieldName) { | ||
|
|
||
| GraphQLFieldDefinition fieldDefinition = getSystemFieldDef(schema, parentType, fieldName); | ||
| if (fieldDefinition != null) { | ||
| return fieldDefinition; | ||
| } | ||
|
|
||
| assertTrue(parentType instanceof GraphQLFieldsContainer, "should not happen : parent type must be an object or interface %s", parentType); | ||
| GraphQLFieldsContainer fieldsContainer = (GraphQLFieldsContainer) parentType; | ||
| fieldDefinition = schema.getCodeRegistry().getFieldVisibility().getFieldDefinition(fieldsContainer, fieldName); | ||
| assertTrue(fieldDefinition != null, "Unknown field '%s' for type %s", fieldName, fieldsContainer.getName()); | ||
| return fieldDefinition; | ||
| } | ||
|
|
||
| /** | ||
| * This will look up a field definition by name, and understand that fields like __typename and __schema are special | ||
| * and take precedence in field resolution | ||
| * | ||
| * @param schema the schema to use | ||
| * @param parentType the type of the parent {@link GraphQLFieldsContainer} | ||
| * @param fieldName the field to look up | ||
| * | ||
| * @return a field definition otherwise throws an assertion exception if it's null | ||
| */ | ||
| public static GraphQLFieldDefinition getFieldDefinition(GraphQLSchema schema, GraphQLFieldsContainer parentType, String fieldName) { | ||
| // this method is optimized to look up the most common case first (type for field) and hence suits the hot path of the execution engine | ||
| // and as a small benefit does not allocate any assertions unless it completely failed | ||
| GraphQLFieldDefinition fieldDefinition = schema.getCodeRegistry().getFieldVisibility().getFieldDefinition(parentType, fieldName); | ||
| if (fieldDefinition == null) { | ||
| // we look up system fields second because they are less likely to be the field in question | ||
| fieldDefinition = getSystemFieldDef(schema, parentType, fieldName); | ||
| if (fieldDefinition == null) { | ||
| Assert.assertShouldNeverHappen(String.format("Unknown field '%s' for type %s", fieldName, parentType.getName())); | ||
| } | ||
| } | ||
| return fieldDefinition; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments above outlines the reasoning |
||
|
|
||
| private static GraphQLFieldDefinition getSystemFieldDef(GraphQLSchema schema, GraphQLCompositeType parentType, String fieldName) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a common private method for the system field lookup code to share some between the two methods |
||
| if (schema.getQueryType() == parentType) { | ||
| if (fieldName.equals(schema.getIntrospectionSchemaFieldDefinition().getName())) { | ||
| return schema.getIntrospectionSchemaFieldDefinition(); | ||
|
|
@@ -805,11 +843,6 @@ public static GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLCo | |
| i AF00 f (fieldName.equals(schema.getIntrospectionTypenameFieldDefinition().getName())) { | ||
| return schema.getIntrospectionTypenameFieldDefinition(); | ||
| } | ||
|
|
||
| assertTrue(parentType instanceof GraphQLFieldsContainer, "Should not happen : parent type must be an object or interface %s", parentType); | ||
| GraphQLFieldsContainer fieldsContainer = (GraphQLFieldsContainer) parentType; | ||
| GraphQLFieldDefinition fieldDefinition = schema.getCodeRegistry().getFieldVisibility().getFieldDefinition(fieldsContainer, fieldName); | ||
| assertTrue(fieldDefinition != null, "Unknown field '%s' for type %s", fieldName, fieldsContainer.getName()); | ||
| return fieldDefinition; | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left the old method in place for semantic reasons and also its signature is not what the execution engine needs.
The
parentType instanceof GraphQLFieldsContaineris not needed say.