Filter for several UIDs

Hi there,

I am currently building a webapp with Golang and dgraph. My problem is the following:

My starting point from all queries is the logged in user. From the user I get his company which has again groups/teams. Out of the complete list of these groups which belong to the company, I want to filter for the uids which are provided in the POST request. However when I use the method QueryWithVars, the UIDs which are inserted as a comma separated string are not recognized correctly. I think this is because they are being interpreted as one uid instead of several ones. But I am not sure, if I am doing something wrong here or if this is actually a bug.

Here is my code:

	variables := database.QueryVariables{
		"$id":       userID,
		"$idOwners": strings.Join(objectiveInput.IDGroups, ","), // objectiveInput.IDGroups is of type []string
	}

	query :=  `query Owner($id: string, $idOwners: string){
	   var(func: uid($id))  {
				company as user_company {
			}
		}

		groups(func: uid($idOwners)) {
			group_company @filter(uid(company))
			uid
			groupName
		}
	}`
	response, err := a.dgraph.NewTxn().QueryWithVars(ctx, query, variables)

Any help would be highly appreciated!

Thanks
Sebastian

Can you try giving the array input surrounded by square brackets [ ], for e.g. [13, 14]?

Hi Pawan,

that works! Thanks a lot! Can you tell me if I actually missed that in the docs? If not, maybe that could be something to be added since I guess others will have the same problems…

Cheers!

Note added at the end of https://docs.dgraph.io/master/query-language/#graphql-variables. Feel free to send a PR for future doc fixes. The code is located at dgraph/wiki/content at master · dgraph-io/dgraph · GitHub

1 Like