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
)

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.
  • Loading branch information
abhimanyusinghgaur authored Sep 4, 2020
1 parent 0287838 commit dc66617
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 @@ -1020,7 +1020,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 @@ -227,9 +227,6 @@ enum PostOrderable {
title
titleByEverything
text
tags
tagsHash
tagsExact
publishByYear
publishByMonth
publishByDay
Expand Down

0 comments on commit dc66617

Please sign in to comment.