Skip to content

feat(graphql+-): Allow parameterized @cascade directive. #5607

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 12 commits into from
Jun 29, 2020

Conversation

parasssh
Copy link
Contributor

@parasssh parasssh commented Jun 9, 2020

Fixes DGRAPH-1279


This change is Reviewable

@github-actions github-actions bot added area/graphql Issues related to GraphQL support on Dgraph. area/querylang Issues related to the query language specification and implementation. labels Jun 9, 2020
@parasssh parasssh self-assigned this Jun 12, 2020
@parasssh parasssh changed the title [WIP]: Allow parameterized @cascade directive. feat(graphql+-): Allow parameterized @cascade directive. Jun 18, 2020
parasssh added 2 commits June 25, 2020 18:19
Copy link
Contributor

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

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

:lgtm: mostly looking good, some minor comments

Reviewed 4 of 6 files at r1, 1 of 2 files at r2, 2 of 2 files at r3.
Reviewable status: all files reviewed, 16 unresolved discussions (waiting on @manishrjain, @MichaelJCompton, @parasssh, and @vvbalaji-dgraph)


gql/parser.go, line 70 at r3 (raw file):

	RecurseArgs      RecurseArgs
	ShortestPathArgs ShortestPathArgs
	Cascade          []string

Please add some docs about how does this look like under different scenarios.


gql/parser.go, line 2117 at r3 (raw file):

	if items[0].Typ == itemLeftCurl || items[0].Typ == itemRightCurl || items[0].
		Typ == itemAt || items[0].Typ == itemName {
		gq.Cascade = append(gq.Cascade, "__all__") // __all__ implies @cascade, the old directive.

all implies values for all the children are mandatory.


gql/parser.go, line 2125 at r3 (raw file):

	it.Next()
	item = it.Item()
	//alias := ""

can be removed?


gql/parser.go, line 2133 at r3 (raw file):

	for it.Next() {
		item := it.Item()
		switch item.Typ {

should this have a default error case? What if someone gives a query like

friends @cascade(n: name)

graphql/dgraph/graphquery.go, line 72 at r3 (raw file):

	}

	if len(query.Cascade) != 0 {

In GraphQL we don't support @cascade with parameters for now. Supporting it would take some more work. That is supported only for GraphQL+-. So we just need the first part of the code here and don't need writeCascade as it won't be used.

if len(query.Cascade) != 0 {
  x.Check2(b.WriteString(" @cascade"))
}

graphql/dgraph/graphquery.go, line 187 at r3 (raw file):

}

func writeCascade(b *strings.Builder, params []string) {

don't need it


query/query.go, line 159 at r3 (raw file):

	// RecurseArgs stores the arguments passed to the @recurse directive.
	RecurseArgs gql.RecurseArgs
	// Cascade is the list of predicates to apply @cascade to. __all__ is special to mean @cascade.

New folks coming to this code might not know about the old meaning of @cascade. We should make it explicit to say __all__ means that all the children of this subgraph are mandatory and should have values otherwise the node will be excluded.


query/query.go, line 553 at r3 (raw file):

		// If parent has @cascade (with or without params), inherit @cascade (with no params)
		if len(sg.Params.Cascade) > 0 {
			args.Cascade = append(args.Cascade, "__all__")

Can we make this __all__ value a constant and use it everywhere? Also, I am assuming @cascade(__all__) also has the same effect as just @cascade? Another question is that do we allow __all__ as a predicate name? If we do, then that might cause some confusion.


query/query.go, line 1354 at r3 (raw file):

			// If the length of child UID list is zero and it has no valid value, then the
			// current UID should be removed from this level.
			if (cascadeAllPreds || cascadeArgMap[child.Attr]) &&

looks good


systest/queries_test.go, line 751 at r3 (raw file):

	}{
		{
			in: `schema(pred: [name]) {}`,

doesn't need to be checked for the purpose of this test


systest/queries_test.go, line 803 at r3 (raw file):

				q(func: anyoftext(name, "Alice")) @cascade(name, age, friend)   {
				  name
				  age

something is up with the formatting, fix if its easy to do so.


systest/queries_test.go, line 868 at r3 (raw file):

				  name
				  age
					  friend {

formatting is a bit messed up


systest/queries_test.go, line 1099 at r3 (raw file):

					  friend @facets(eq(close, true) OR eq(close, false)) {
					name
					# friend {

can be removed if unused


systest/queries_test.go, line 1141 at r3 (raw file):

					name
					age
					# friend {

can be removed


systest/queries_test.go, line 1167 at r3 (raw file):

		},

		// {

Can be removed


systest/queries_test.go, line 1176 at r3 (raw file):

	for _, tc := range tests {
		resp, err := c.NewTxn().Query(ctx, tc.in)

nice comprehensive set of tests

Copy link
Contributor Author

@parasssh parasssh left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 16 unresolved discussions (waiting on @manishrjain, @MichaelJCompton, @pawanrawal, and @vvbalaji-dgraph)


gql/parser.go, line 70 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Please add some docs about how does this look like under different scenarios.

Not here. But added docs as suggested by you below in other comments.


gql/parser.go, line 2117 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

all implies values for all the children are mandatory.

Done.


gql/parser.go, line 2125 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

can be removed?

Done.


gql/parser.go, line 2133 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

should this have a default error case? What if someone gives a query like

friends @cascade(n: name)

Done.


graphql/dgraph/graphquery.go, line 72 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

In GraphQL we don't support @cascade with parameters for now. Supporting it would take some more work. That is supported only for GraphQL+-. So we just need the first part of the code here and don't need writeCascade as it won't be used.

if len(query.Cascade) != 0 {
  x.Check2(b.WriteString(" @cascade"))
}

Done. I check for len as well as make sure it contains all


graphql/dgraph/graphquery.go, line 187 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

don't need it

Done.


query/query.go, line 159 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

New folks coming to this code might not know about the old meaning of @cascade. We should make it explicit to say __all__ means that all the children of this subgraph are mandatory and should have values otherwise the node will be excluded.

Done.


query/query.go, line 553 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Can we make this __all__ value a constant and use it everywhere? Also, I am assuming @cascade(__all__) also has the same effect as just @cascade? Another question is that do we allow __all__ as a predicate name? If we do, then that might cause some confusion.

  • There seems no good place to defined constants. Many other directives have hard-coded. We can sweep all this in a separate PR.
  • Yes. @cascade(all) = @cascade
  • all is allowed as a predicate name. But so is many other keywords. We can sweep this as well in a separate PR so all reserved keywords are disallowed from pred name.

query/query.go, line 1354 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

looks good

Done.


systest/queries_test.go, line 751 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

doesn't need to be checked for the purpose of this test

Done.


systest/queries_test.go, line 803 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

something is up with the formatting, fix if its easy to do so.

Done.


systest/queries_test.go, line 868 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

formatting is a bit messed up

Done.


systest/queries_test.go, line 1099 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

can be removed if unused

Done.


systest/queries_test.go, line 1141 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

can be removed

Done.


systest/queries_test.go, line 1167 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Can be removed

Done.


systest/queries_test.go, line 1176 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

nice comprehensive set of tests

Done.

@parasssh parasssh merged commit 58ce809 into master Jun 29, 2020
@parasssh parasssh deleted the paras/factset_cascade branch June 29, 2020 21:54
parasssh pushed a commit that referenced this pull request Jun 29, 2020
Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com>
(cherry picked from commit 58ce809)
arijitAD pushed a commit that referenced this pull request Jul 14, 2020
Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com>
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request Jul 18, 2020
…c#5607)

Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com>
parasssh pushed a commit that referenced this pull request Aug 27, 2020
Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com>
(cherry picked from commit 58ce809)
parasssh pushed a commit that referenced this pull request Aug 27, 2020
Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com>
(cherry picked from commit 58ce809)
parasssh pushed a commit that referenced this pull request Aug 27, 2020
Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com>
(cherry picked from commit 58ce809)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/graphql Issues related to GraphQL support on Dgraph. area/querylang Issues related to the query language specification and implementation.
Development

Successfully merging this pull request may close these issues.

3 participants