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

fix(GRAPHQL):[Breaking] Don't generate get query on interface if it doesn't have field of type ID and also disallow get query on field of type @id in inerface. #7158

Merged
merged 3 commits into from
Dec 21, 2020

Conversation

JatinDev543
Copy link
Contributor

@JatinDev543 JatinDev543 commented Dec 17, 2020

Fixes GRAPHQL-886
We were allowing get query on the field of type @id on the interface type. This causes an error in cases when interface is implemented by multiple types and they try to have same value for field of type @id.
To resolve this we are disallowing get query on the interface if it doesn't have a field of type ID , and if we have both fields of type ID and @id then we don't allow get query on the field of type @id.


This change is Reviewable

@github-actions github-actions bot added the area/graphql Issues related to GraphQL support on Dgraph. label Dec 17, 2020
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.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @jatindevdg, @MichaelJCompton, and @pawanrawal)


graphql/schema/testdata/schemagen/output/interface-with-id-directive.graphql, line 455 at r1 (raw file):

type Query {
	getLibraryItem(refID: String!): LibraryItem

Is there also a test where interface has both id: ID! and a field with @id directive.

@JatinDev543
Copy link
Contributor Author

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @jatindevdg, @MichaelJCompton, and @pawanrawal)

graphql/schema/testdata/schemagen/output/interface-with-id-directive.graphql, line 455 at r1 (raw file):

type Query {
	getLibraryItem(refID: String!): LibraryItem

Is there also a test where interface has both id: ID! and a field with @id directive.

added test

Copy link
Contributor

@abhimanyusinghgaur abhimanyusinghgaur left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 0 of 4 files reviewed, 2 unresolved discussions (waiting on @jatindevdg, @MichaelJCompton, and @pawanrawal)


graphql/schema/gqlschema.go, line 1735 at r2 (raw file):

if (!hasIDField && defn.Kind == "INTERFACE") || (!hasIDField && !hasXIDField)

can be simplified to:

if !hasIDField && (defn.Kind == "INTERFACE" || !hasXIDField)

@JatinDev543 JatinDev543 merged commit 96b1fa5 into master Dec 21, 2020
@JatinDev543 JatinDev543 deleted the jatin/GRAPHQL-886 branch December 21, 2020 11:00
JatinDev543 added a commit that referenced this pull request Jan 15, 2021
…oesn't have field of type ID and also disallow get query on field of type @id in inerface. (#7158)

Fixes GRAPHQL-886
We were allowing get query on the field of type @id on the interface type. This causes an error in cases when interface is implemented by multiple types and they try to have same value for field of type @id.
To resolve this we are disallowing get query on the interface if it doesn't have a field of type ID , and if we have both fields of type ID and @id then we don't allow get query on the field of type @id.

(cherry picked from commit 96b1fa5)
JatinDev543 added a commit that referenced this pull request Jan 15, 2021
…oesn't have field of type ID and also disallow get query on field of type @id in inerface. (#7158) (#7305)

Fixes GRAPHQL-886
We were allowing get query on the field of type @id on the interface type. This causes an error in cases when interface is implemented by multiple types and they try to have same value for field of type @id.
To resolve this we are disallowing get query on the interface if it doesn't have a field of type ID , and if we have both fields of type ID and @id then we don't allow get query on the field of type @id.

(cherry picked from commit 96b1fa5)
JatinDev543 added a commit that referenced this pull request Mar 18, 2021
Fixes GRAPHQL-1119
We had this bug fix PR #7158 that also went into 20.11 release branch which disallow id argument in get queries on interfaces.
Because it was breaking change , we are now rolling back this change and mark it as deprecated, and change later.

Orignal bug
https://discuss.dgraph.io/t/id-directive-and-interfaces/11642

Workaround
So, we have disallowed @id argument from get query on interface, but the normal query still have it. So, users can change their
get queries with simple query as follows.

Interface with @id field

interface Foo {
 id: String! @id
}

We can change below query

query{
getFoo(id:"test"){
      id
 }
}
to

query{
queryFoo(filter: {id:{eq: "test"}}){ 
        id
   } 
}
Related Posts
https://discuss.dgraph.io/t/id-directive-and-interfaces/11642
https://discuss.dgraph.io/t/was-there-a-change-to-generated-queries-with-id-directives-in-v20-11-1/12591
aman-bansal pushed a commit that referenced this pull request Mar 25, 2021
Fixes GRAPHQL-1119
We had this bug fix PR #7158 that also went into 20.11 release branch which disallow id argument in get queries on interfaces.
Because it was breaking change , we are now rolling back this change and mark it as deprecated, and change later.

Orignal bug
https://discuss.dgraph.io/t/id-directive-and-interfaces/11642

Workaround
So, we have disallowed @id argument from get query on interface, but the normal query still have it. So, users can change their
get queries with simple query as follows.

Interface with @id field

interface Foo {
 id: String! @id
}

We can change below query

query{
getFoo(id:"test"){
      id
 }
}
to

query{
queryFoo(filter: {id:{eq: "test"}}){
        id
   }
}
Related Posts
https://discuss.dgraph.io/t/id-directive-and-interfaces/11642
https://discuss.dgraph.io/t/was-there-a-change-to-generated-queries-with-id-directives-in-v20-11-1/12591
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.
Development

Successfully merging this pull request may close these issues.

3 participants