From 7c29a15dc4b50053c27bf747799c9a3e851a7aae Mon Sep 17 00:00:00 2001 From: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com> Date: Fri, 4 Sep 2020 22:30:28 +0530 Subject: [PATCH] fix(GraphQL): don't generate orderable enum value for list fields (#6392) Fixes GRAPHQL-650. For this user schema: ``` type Starship { id: ID! name: String! @search(by: [term]) length: Int64 tags: [String] createdAt: DateTime } ``` we were generating complete GraphQL schema with StarshipOrderable as: ``` enum StarshipOrderable { name length tags createdAt } ``` that would cause a DQL query to be formed which errors out, see this GraphQL query: ``` query { queryStarship(order: {asc: tags}) { id name length tags } } ``` It gives back: ``` { "errors": [ { "message": "Dgraph query failed because Dgraph execution failed because : Sorting not supported on attr: Starship.tags of type: [scalar]" } ], "data": { "queryStarship": [] } } ``` which means we should not allow even list of scalar along with object types in orderable. Only scalar field should be allowed in orderable. So, the correct orderable should be without tags field: ``` enum StarshipOrderable { name length createdAt } ``` This PR fixes the above bug. (cherry picked from commit dc66617abf96a87595cc1a677e9aaa4f97e076f5) --- graphql/schema/gqlschema.go | 2 +- graphql/schema/testdata/schemagen/output/searchables.graphql | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/graphql/schema/gqlschema.go b/graphql/schema/gqlschema.go index 48790002775..bd64ea50f55 100644 --- a/graphql/schema/gqlschema.go +++ b/graphql/schema/gqlschema.go @@ -955,7 +955,7 @@ func addTypeOrderable(schema *ast.Schema, defn *ast.Definition) { } for _, fld := range defn.Fields { - if orderable[fld.Type.Name()] { + if fld.Type.NamedType != "" && orderable[fld.Type.NamedType] { order.EnumValues = append(order.EnumValues, &ast.EnumValueDefinition{Name: fld.Name}) } diff --git a/graphql/schema/testdata/schemagen/output/searchables.graphql b/graphql/schema/testdata/schemagen/output/searchables.graphql index 0a57337e274..7463ef9b29c 100755 --- a/graphql/schema/testdata/schemagen/output/searchables.graphql +++ b/graphql/schema/testdata/schemagen/output/searchables.graphql @@ -180,9 +180,6 @@ enum PostOrderable { title titleByEverything text - tags - tagsHash - tagsExact publishByYear publishByMonth publishByDay