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

Add directive support #94

Merged
merged 2 commits into from
Jun 6, 2022
Merged

Add directive support #94

merged 2 commits into from
Jun 6, 2022

Conversation

david-bain
Copy link
Contributor

Situations where only a directive is present requires the GraphQLName to search directly for the @ rune.

Example: name graphql:"name @skip(if: skipThis=true)"

This issues allows the following to succeed:

type TeamsQuery struct {
	Organization struct {
		ID    githubv4.String
		Teams struct {
			Nodes []struct {
				ID          githubv4.String
				DatabaseID  githubv4.Int
				Slug        githubv4.String
				Name        githubv4.String
				Description githubv4.String
				Privacy     githubv4.String
				Members     struct {
					Nodes []struct {
						Login githubv4.String
					}
+				} `graphql:"members @skip(if: $summaryOnly)"`
				Repositories struct {
					Nodes []struct {
						Name githubv4.String
					}
+				} `graphql:"repositories @skip(if: $summaryOnly)"`
			}
			PageInfo PageInfo
		} `graphql:"teams(first:$first, after:$cursor, rootTeamsOnly:$rootTeamsOnly)"`
	} `graphql:"organization(login:$login)"`
}

Situations where only a directive is present requires the GraphQLName to search directly for the `@` rune.

Example: name `graphql:"name @Skip(if: skipThis=true)"`
The strings.Index check for "@" is the third separator we look for.
There's no reason to look separately, since we just want the first
field name separator.

Add test covering a GraphQL directive that immediately follows the
field name.
@dmitshur
Copy link
Member

dmitshur commented Jun 6, 2022

Thanks, this change makes sense.

I'll refactor it slightly and add a test before merging.

@dmitshur dmitshur merged commit 3cf50f8 into shurcooL:master Jun 6, 2022
hgiasac pushed a commit to hasura/go-graphql-client that referenced this pull request Apr 8, 2023
Also consider "@" when looking for the end of the field name, since
GraphQL directives can follow a field name immediately without any
arguments or aliases being involved. For example:

	query {
		me {
			firstName
			lastName @include(if: $expandedInfo)
		}
	}

The strings.Index check for "@" is the third separator we look for.
There's no reason to look separately, since we just want the first
field name separator.

Add test covering a GraphQL directive that immediately follows the
field name.

Co-authored-by: Dmitri Shuralyov <dmitri@shuralyov.com>
GitHub-Pull-Request: shurcooL#94
hgiasac pushed a commit to hasura/go-graphql-client that referenced this pull request Apr 8, 2023
Also consider "@" when looking for the end of the field name, since
GraphQL directives can follow a field name immediately without any
arguments or aliases being involved. For example:

	query {
		me {
			firstName
			lastName @include(if: $expandedInfo)
		}
	}

The strings.Index check for "@" is the third separator we look for.
There's no reason to look separately, since we just want the first
field name separator.

Add test covering a GraphQL directive that immediately follows the
field name.

Co-authored-by: Dmitri Shuralyov <dmitri@shuralyov.com>
GitHub-Pull-Request: shurcooL#94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants