Skip to content

Commit

Permalink
fix(GRAPHQL): Undo the breaking change and tag it as deprecated. (#7602)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JatinDev543 authored and aman-bansal committed Mar 25, 2021
1 parent 0ef503a commit 9857b63
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 369 deletions.
13 changes: 11 additions & 2 deletions graphql/schema/gqlschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ func addGetQuery(schema *ast.Schema, defn *ast.Definition, providesTypeMap map[s
hasIDField := hasID(defn)
hasXIDField := hasXID(defn)
xidCount := xidsCount(defn.Fields)
if !hasIDField && (defn.Kind == "INTERFACE" || !hasXIDField) {
if !hasIDField && !hasXIDField {
return
}
qry := &ast.FieldDefinition{
Expand All @@ -1956,7 +1956,16 @@ func addGetQuery(schema *ast.Schema, defn *ast.Definition, providesTypeMap map[s
},
})
}
if hasXIDField && defn.Kind != "INTERFACE" {
if hasXIDField {
if defn.Kind == "INTERFACE" {
qry.Directives = append(
qry.Directives, &ast.Directive{Name: deprecatedDirective,
Arguments: ast.ArgumentList{&ast.Argument{Name: "reason",
Value: &ast.Value{Raw: "@id argument for get query on interface is being deprecated, " +
"it will be removed in v21.11.0, " +
"please update your query to not use that argument",
Kind: ast.StringValue}}}})
}
for _, fld := range defn.Fields {
if hasIDDirective(fld) {
qry.Arguments = append(qry.Arguments, &ast.ArgumentDefinition{
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9857b63

Please sign in to comment.