Skip to content

Commit

Permalink
fix(GraphQL): don't generate orderable enum value for list fields (#6392
Browse files Browse the repository at this point in the history
) (#6413)

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 dc66617)
  • Loading branch information
abhimanyusinghgaur committed Sep 18, 2020
1 parent 23d72a8 commit 1e81ff6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
2 changes: 1 addition & 1 deletion graphql/schema/gqlschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
3 changes: 0 additions & 3 deletions graphql/schema/testdata/schemagen/output/searchables.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ enum PostOrderable {
title
titleByEverything
text
tags
tagsHash
tagsExact
publishByYear
publishByMonth
publishByDay
Expand Down

0 comments on commit 1e81ff6

Please sign in to comment.