Skip to content

Commit

Permalink
fix(GRAPHQL):[Breaking] Don't generate get query on interface if it d…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
JatinDev543 committed Jan 15, 2021
1 parent 32557ec commit 23e45d9
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 8 deletions.
14 changes: 7 additions & 7 deletions graphql/schema/gqlschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ func addAggregationResultType(schema *ast.Schema, defn *ast.Definition) {
func addGetQuery(schema *ast.Schema, defn *ast.Definition, generateSubscription bool) {
hasIDField := hasID(defn)
hasXIDField := hasXID(defn)
if !hasIDField && !hasXIDField {
if !hasIDField && (defn.Kind == "INTERFACE" || !hasXIDField) {
return
}

Expand All @@ -1749,12 +1749,12 @@ func addGetQuery(schema *ast.Schema, defn *ast.Definition, generateSubscription
},
})
}
if hasXIDField {
name := xidTypeFor(defn)
if hasXIDField && defn.Kind != "INTERFACE" {
name, dtype := xidTypeFor(defn)
qry.Arguments = append(qry.Arguments, &ast.ArgumentDefinition{
Name: name,
Type: &ast.Type{
NamedType: "String",
NamedType: dtype,
NonNull: !hasIDField,
},
})
Expand Down Expand Up @@ -2363,13 +2363,13 @@ func idTypeFor(defn *ast.Definition) string {
return "ID"
}

func xidTypeFor(defn *ast.Definition) string {
func xidTypeFor(defn *ast.Definition) (string, string) {
for _, fld := range defn.Fields {
if hasIDDirective(fld) {
return fld.Name
return fld.Name, fld.Type.Name()
}
}
return ""
return "", ""
}

func appendIfNotNull(errs []*gqlerror.Error, err *gqlerror.Error) gqlerror.List {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Student {
rollNo: String! @id
regNo: ID!
name: String!
}

0 comments on commit 23e45d9

Please sign in to comment.