vasco3
August 5, 2020, 5:49pm
1
I’m trying to add an index GraphQL query
I created the Index (works well in FQL),
CreateIndex({
name: 'quotes_reversed',
source: Collection('Quote'),
values: [{ field: ['ref'], reverse: true }],
});
and then added in my GraphQL schema
quotesReversed: [Quote] @index(name: "quotes_reversed")
but when I try to UPDATE SCHEMA in Fauna’s console, it says:
“Error updating GraphQL schema.: Instance data is not valid”
I’m not sure if it’s my fault or is it a bug
You cannot specify values
for an Index used with @index
.
The error is not very helpful, but it is working as intended. Not a bug, but perhaps unfortunate that it cannot work.
There is a Topic for feedback on this, and also suggests a workaround of using a UDF with @resolver
.
Workaround
With the current implementation, you need to create a UDF along with the Index, as explained here . If you have implemented your own UDFs that you think could help other users with this, please share them as replies to this topic and/or make a gist and link to it from the awesome-faunadb list.
1 Like
vasco3
November 23, 2020, 11:20pm
3
I got the same question but now it is a search so it has to use a resolver but I don’t know what to put in the lambda params
Query( Lambda( ['size', 'after', 'before'],
where to I put the searchText
input from the graphql query?
customerByStartsWith(searchText: String!): [Customer!]
@resolver(name: "customerByStartsWith", paginated: true)
would it be
Query( Lambda( ['size', 'after', 'before', 'searchText'],
?
I can’t find documentation on which params other than size, after, before
does a paginated: true
use
Hey @vasco3 , check this out:
More of a How-To, than a best practice, but since Pagination with GraphQL resolvers is a bit confusing, here are some things on that:
Using Pagination Arguments in a UDF
Docs can be helpful, even if they get a bad reputation! They have a good example of how to use pagination arguments in a UDF .
I created a helper function that builds on that example:
const paginateWithOptions = (set, size, after, before) =>
q.If(
q.Equals(before, null),
q.If(
q.Equals(after, null),
q.P…
According to documentation here:
I know that a resolver-UDF for a graphql query signature like this:
pendingInvites: [Invite!] @resolver(paginated: true)
Should have a signature like this:
q.Lambda(
['size', 'after', 'before'],
...
)
But what if the graphql query is expecting parameters? For instance, what would the signature for a UDF function be in the case of this graphql query:
pendingInvites(active: Boolean!, user: ID!): [Invite!] @resolver(paginated: true)
Now it needs…