Skip to content

Commit

Permalink
Add logic to handle both forms of id filter types that can be encounted
Browse files Browse the repository at this point in the history
Include a test for the single ID JWT variable
  • Loading branch information
matthewmcneely committed Sep 27, 2022
1 parent 250dd72 commit 50ee38a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
24 changes: 24 additions & 0 deletions graphql/resolve/auth_query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2127,3 +2127,27 @@
Person.id : uid
}
}
-
name: "Query auth rules with filter on field with ID type, single JWT ID param"
gqlquery: |
query{
queryPerson{
id
name
}
}
jwtvar:
USER: "0x5"
dgquery: |-
query {
queryPerson(func: uid(PersonRoot)) {
Person.id : uid
Person.name : Person.name
}
PersonRoot as var(func: uid(Person_1)) @filter(uid(Person_Auth2))
Person_1 as var(func: type(Person))
Person_Auth2 as var(func: uid(0x5)) @filter(type(Person)) @cascade {
Person.id : uid
}
}
13 changes: 12 additions & 1 deletion graphql/resolve/query_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,18 @@ func idFilter(filter map[string]interface{}, idField schema.FieldDefinition) []u
if idsFilter == nil {
return nil
}
idsSlice := idsFilter.([]interface{})
var idsSlice []interface{}
// idsFilter can be an single string value (most common) or
// an interface{} slice
switch idsFilter.(type) {
case string:
idsSlice = append(idsSlice, idsFilter)
case []interface{}:
idsSlice = idsFilter.([]interface{})
default:
// if an unexpected type is encountered, fail silently
return nil
}
return convertIDs(idsSlice)
}

Expand Down

0 comments on commit 50ee38a

Please sign in to comment.