Trying to get "object filtering" to work with apolo-server and vuex-orm-graphql.
Stack:
- Backend: nodejs, apollo-server
- Frontend: vue/vuex-orm + vuex-orm-graphql-plugin. The app implements
.fetch()
according to the "filter object" as described in the docs:
Comment.fetch({ postId: '15', deleted: false });
I can't get the client to send the query because I don't know how to define the query schema for the "filter object" case.
Tried several approaches, such as:
input FilterObject {
postId: String
deleted: Boolean
}
type query {
comments(filter: FilterObject)
}
The graphql query request isn't sent, erroring:
"Cannot query field \"nodes\" on type \"Comments\"."
If I modify a bit the schema I can get the query to send, however it errors about the filter
field type being wrong.
How does the schema need to be defined for the filter functionality to work?
Update:
I'm not sure it's the best way to achieve the goal, but I found using the 'cursor' concept solves the problem.
I defined a 'filter' input type which contains the filter-by fields.
Next, for the query output there's a new cursor type which contains the 'nodes' field. Note that the nodes field is an array of the queried type.
So it ends up being something like this:
As pointed out, I found and confirmed tested this works with vuex-orm and the associated graphql plugin.
Hopefully it helps!