Skip to content

Commit

Permalink
fix graphql get by xid (#4586)
Browse files Browse the repository at this point in the history
* add test for get xid

* fix get by xid
  • Loading branch information
MichaelJCompton authored and pawanrawal committed Jan 16, 2020
1 parent c0bb4ee commit 44cbf94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 16 additions & 0 deletions graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,22 @@
}
}
-
name: "Get with XID where no ID in type"
gqlquery: |
query {
getState(code: "NSW") {
name
}
}
dgquery: |-
query {
getState(func: eq(State.code, "NSW")) @filter(type(State)) {
name : State.name
dgraph.uid : uid
}
}
-
name: "Query editor using code"
gqlquery: |
Expand Down
5 changes: 2 additions & 3 deletions graphql/schema/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func (f *field) IDArgValue() (xid *string, uid uint64, err error) {
// 3. ID and XID fields
// Therefore, the non ID field is an XID field.
for _, arg := range f.field.Arguments {
if arg.Name != idField.Name() {
if idField == nil || arg.Name != idField.Name() {
xidArgName = arg.Name
}
}
Expand All @@ -508,8 +508,7 @@ func (f *field) IDArgValue() (xid *string, uid uint64, err error) {
xid = &xidArgVal
}

if idField == nil && xid == nil {
// This means that both were optional and were not supplied, lets return here.
if idField == nil {
return
}

Expand Down

0 comments on commit 44cbf94

Please sign in to comment.