-
Notifications
You must be signed in to change notification settings - Fork 492
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
Expose the tree of field subselections to the resolver on demand #169
Open
xmirya
wants to merge
6
commits into
graph-gophers:master
Choose a base branch
from
xmirya:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+40
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c68f55e
Expose the tree of field subselections to the resolver on demand
xmirya 2a507de
Merge branch 'master' into master
xmirya c9d9655
Fix padding
xmirya 3e1e609
The NOTE no longer applies
xmirya 456d7ff
Merge remote-tracking branch 'upstream/master'
xmirya 2118539
Merge remote-tracking branch 'upstream/master'
xmirya 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 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 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 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"github.com/graph-gophers/graphql-go/internal/common" | ||
"github.com/graph-gophers/graphql-go/internal/exec/packer" | ||
"github.com/graph-gophers/graphql-go/internal/schema" | ||
pubselected "github.com/graph-gophers/graphql-go/selected" | ||
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. What does the |
||
) | ||
|
||
type Schema struct { | ||
|
@@ -36,6 +37,7 @@ type Field struct { | |
FieldIndex int | ||
HasContext bool | ||
HasError bool | ||
HasSelected bool | ||
ArgsPacker *packer.StructPacker | ||
ValueExec Resolvable | ||
TraceLabel string | ||
|
@@ -281,6 +283,7 @@ func (b *execBuilder) makeObjectExec(typeName string, fields schema.FieldList, p | |
} | ||
|
||
var contextType = reflect.TypeOf((*context.Context)(nil)).Elem() | ||
var selectedType = reflect.TypeOf([]pubselected.SelectedField(nil)) | ||
var errorType = reflect.TypeOf((*error)(nil)).Elem() | ||
|
||
func (b *execBuilder) makeFieldExec(typeName string, f *schema.Field, m reflect.Method, sf reflect.StructField, | ||
|
@@ -289,6 +292,7 @@ func (b *execBuilder) makeFieldExec(typeName string, f *schema.Field, m reflect. | |
var argsPacker *packer.StructPacker | ||
var hasError bool | ||
var hasContext bool | ||
var hasSelected bool | ||
|
||
// Validate resolver method only when there is one | ||
if methodIndex != -1 { | ||
|
@@ -317,6 +321,11 @@ func (b *execBuilder) makeFieldExec(typeName string, f *schema.Field, m reflect. | |
in = in[1:] | ||
} | ||
|
||
hasSelected = len(in) > 0 && in[0] == selectedType | ||
if hasSelected { | ||
in = in[1:] | ||
} | ||
|
||
if len(in) > 0 { | ||
return nil, fmt.Errorf("too many parameters") | ||
} | ||
|
@@ -344,6 +353,7 @@ func (b *execBuilder) makeFieldExec(typeName string, f *schema.Field, m reflect. | |
MethodIndex: methodIndex, | ||
FieldIndex: fieldIndex, | ||
HasContext: hasContext, | ||
HasSelected: hasSelected, | ||
ArgsPacker: argsPacker, | ||
HasError: hasError, | ||
TraceLabel: fmt.Sprintf("GraphQL field: %s.%s", typeName, f.Name), | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package selected | ||
|
||
type SelectedField struct { | ||
pavelnikolov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Name string | ||
Selected []SelectedField | ||
} |
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 don't like the repetition of the work "selected" in:
selected.SelectedField
. It'd be nice if we can avoid that.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.
Maybe
selected.Field
🤔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.
Ideally, even better package name...
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.
Just came across this PR. Given the author has not replied, I'm happy to do these changes (along with tests) if there's any chance that this gets approved and merged afterwards cc/ @pavelnikolov
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.
@jesushernandez this is the most requested feature and I really want it to get some traction but I'm not sure that this is the best approach.
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.
How can I help getting more traction?