I have a schema that looks like this:
type User {
userDishes: [UserDish]! @relation(name: “user_userDishes”)
…
}
type UserDish {
owner: User! @relation(name: “user_userDishes”)
dishId: String!
}
I want to be able to retrieve all userDishes with the same User relation.
I’ve set up this function:
When testing the function in the shell I get back an object with a data array, which contains the documents I need.
So far so good, everything seems to work at this point.
My problem is when I try to query this function in graphQL, I’ve added the query in my schema and also added the function as a resolver, but I just get back this error message when querying it:
“String or Number expected, Array provided.”
I am pretty much stuck here, as I cannot find anything related to this in the docs…
I think you will need to share the UDF body for us to help diagnose what is happening.
As an aside, a more GraphQL canonical way of running this query might not be to create a top level custom resolver, but to query the user and expand the query through the relationship.
If you have a Schema:
type User {
dishes: [UserDish] @relationship
}
type UserDish {
user: User! @relationship
title: String!
}
then you can query, without any customer resolvers, like this:
query {
findUserById(id: "292128025028329991") {
_id
dishes: {
data {
_id
title
}
}
}
}
Oh I think I see it. You are return the fauna Page from the UDF. This will only work if you set pagination to true and then also handle the extra arguments in the UDF.
Wrap the whole UDF body in
Select(
'data',
/* everything here */
)
@parkhomenko 's comment about wrapping arguments is also very important for GraphQL resolvers.
Hopefully that will resolve things. Or, at least solve that one issue.
But then you need to deal with the extra size and cursor arguments in the UDF. At that point, I strongly suggest going back to the already generated queries available, since the pagination is already built in.
query {
findUserById(id: "292128025028329991") {
_id
dishes(_size: 3): {
data {
_id
title
}
before
after
}
}
}
Thank you so much. I figured it out the day before yesterday though. You are right that I was returning the entire page in my function, and I was asking for an array in my resolver
So I changed my function to return an array instead like this: