Is there a way to not have to make separate find and update operations resulting in extra roundtrip? I mean without using fql and just going by graphql api?
Alternatively can UDF be defined that uses existing autogenerated API to bridge query and update operations, eliminating the round trip?
I posted a question here too: faunadb - How to eliminate the round trip for find and update sequence relying on graphql generated api - Stack Overflow
GraphQL does let you make multiple queries in a single request.
{
thing1: findThingByID(id: "1234") { _id, _ts, field }
thing2: findThingByID(id: "5555") { _id, _ts, field }
}
That’s not a Fauna thing, rather it is part of how GraphQL works. https://graphql.org/learn/queries/#aliases
These are run at the same time, though. If you need to use the response from one request in the body of the next request then GraphQL does not have a mechanism for this. You can, however, create a UDF and call it with a customer resolver.
# GraphQL Schema
type Query {
myAdvancedQuery(thing1: ID, thing2: ID): [SomeResultType] @resolver
}
// FQL
CreateFunction({
name: "myAdvancedQuery",
role: Role("myAdvancedQueryFnRole") // https://docs.fauna.com/fauna/current/security/abac
body: Query(
Lambda(
["thing1", "thing2"],
Let(
{
step1: /* Do something with thing 1 */
step2: /* Do something with thing 2 */
step3: /* Do something with the results of steps 1 and 2 */
},
/* create and return the payload that GraphQL expects */
)
)
)
})
Can you just pass the variables into some function that was generated for gql mutation? There must be fql behind gql api that you could use within custom resolver.
The default behavior compiles your graphql queries to the appropriate FQL for the task. For example, if you have a type Thing
Fauna will generate the mutation createThing
, which will compile directly to a Create
function and not call any UDF.
However, if you can opt in to more control by using the @generateUDFResolvers
directive. It specifies that queries which would otherwise be resolved in FQL dynamically, be persisted as UDFs for the annotated Types.
So something along the lines of find those functions to invoke them as lambda variables and body (body is mutate.)
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.