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

Improved Collect Fields API and Documentation #551

Merged
merged 3 commits into from
Feb 18, 2019

Conversation

mathewbyrne
Copy link
Contributor

This adds a new API helper method CollectAllFields(context.Context) []string as discussed in #280 and #533. The goal is to add a simple API for the common case of wanting to know which fields were requested, and add some documentation around how this feature works.

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

@mathewbyrne mathewbyrne changed the base branch from master to next February 18, 2019 01:24
@@ -38,7 +41,7 @@ func collectFields(reqCtx *RequestContext, selSet ast.SelectionSet, satisfies []
if !shouldIncludeNode(sel.Directives, reqCtx.Variables) {
continue
}
if !instanceOf(sel.TypeCondition, satisfies) {
if len(satisfies) > 0 && !instanceOf(sel.TypeCondition, satisfies) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be an explicit nil check? is there a difference between satisfies = nil and satisfies = []? maybe [] is not useful so the distinction is not important?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah perhaps. Currently on next an empty slice will collect object fields, and skip any Fragments. Is that useful? Maybe, I guess it does potentially break BC if anyone is using it for this use-case.

Still, a nil slice vs and empty slice having different behaviours seems a little fragile to me?

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@mathewbyrne mathewbyrne merged commit 327a1a3 into next Feb 18, 2019
@vektah vektah deleted the improved-collect-fields-api branch March 4, 2019 05:01
@vektah vektah mentioned this pull request Mar 4, 2019
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
…ds-api

Improved Collect Fields API and Documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants