I have a GraphQL schema that looks like this:
type User {
firstName: String
lastName: String
email: String
groups: [Group] @relation(name: "members")
}
type Group {
name: String
members: [User] @relation(name: "members")
startDate: String
}
This creates an index called members_by_group
and a Collection called members
.
I have a Query:
findGroupByID(id: $id){
_id
startDate
members{
data{
_id
firstName
lastName
}
}
}
This query results in an instance not found error. But there is data in the members collection.
{
"ref": Ref(Collection("members"), "351058485137375832"),
"ts": 1671054310890000,
"data": {
"groupID": Ref(Collection("Group"), "329795413068481106"),
"userID": Ref(Collection("User"), "329431630822244946")
}
}
Using the fauna shell however results in no data:
Paginate(Match(Index("members_by_group"), "329795413068481106"))
{
data: []
}
I have tried rebuilding the index multiple times but that does not seem to work.
These are the index settings:
There are only 6 members documents and 8 Group documents and nothing seems a miss there.
Any ideas on how I can get the above query working again? Any ideas would be greatly appreciated.
Thanks in advance.
Hi @levimoore !
What id
are you passing in the fundGroupByID
query?
I have tried importing your schema and I was able to get results with this query
query findGroupMembers{
findGroupByID(id: "354335889813405781"){
_id
startDate
members{
data{
_id
firstName
lastName
}
}
}
}
Here is my Group
document
{
"ref": Ref(Collection("Group"), "354335889813405781"),
"ts": 1674179887540000,
"data": {
"name": "writers",
"startDate": "01-20-2022"
}
}
levimoore:
Using the fauna shell however results in no data:
Paginate(Match(Index("members_by_group"), "329795413068481106"))
{
data: []
}
The index takes groupID
as the term which is defined as a ref
(as opposed to a string) in the members
collection.
"groupID": Ref(Collection("Group"), "329795413068481106")
So the following query should return the document:
Paginate(Match(Index("members_by_group"), Ref(Collection("Group"), "329795413068481106")))
Hope that helps!
The above did work thank you for the clarification. My query still does not work though…
Sorry for all the screenshots but you can see the Paginate call in the shell returns the three user Refs, and those members are the only ones that exist in the members collection with that groupID
It was missing data after all. A user document was missing. So the instance not found error was correct. I deleted the member document that had the offending Ref(Collection("User".....
and the query works again.
1 Like
This topic was automatically closed after 3 days. New replies are no longer allowed.