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) #7305

Merged
merged 1 commit into from Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions graphql/schema/gqlschema.go
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
@@ -0,0 +1,5 @@
interface Student {
rollNo: String! @id
regNo: ID!
name: String!
}