Just wanted to know it is possible in v10 to write UDF functions using new syntax where we use to write FQL now. new syntax seems to be like javascript so will there be new easier syntax to query in FQL as well.
Any example would be helpful.
Hi @Ankit_Arora
Yes! You can write UDFs with v10. Here are some examples - Write custom logic with user-defined functions - Fauna Documentation
Also note the link inside that page about inter-operability and migration between v4 and v10 UDFs.
@ldavuluri ok Thanks. I have created a function in v10 that returns the output like this for below function
(docid,pid) => relateddocs.create({ docID: doc.byId(id), pID: process.byId(id)})
call to function from shell
relateddocs.create({ docID: doc.byId(“368684464373498060”), pID: process.byId(“368667705804325068”)});
Output
{
id: “369580593941315793”,
coll: relatedocs,
ts: Time(“2023-07-07T08:26:10.315Z”),
docID: document.byId(“368684464373498060”),
pID: processrequest.byId(“368667705804325068”)
}
I want to run same function via GraphQL mutation so I have created one
type processrequestdocuments {
docID: String
pID: String
}
createProcessDocRelationById(docid:String!,pid:String!): relateddocs @resolver(name: “createProcessDocRelationById”)
as function is running fine inside shell but when running mutation via GraphQL panel it gives following error.
“message”: “Cannot return null for non-nullable type (line 6, column 5):\n docID\n ^”,
“path”: [
“updateProcessRequestDocumentDataById1”,
“docID”
]
wanted to know why graphql is giving error.
or I need to define type like this for relationship
type processrequestdocuments {
docID: Document!
pID: Process!
}
or Do I need to change to function definition so I can return docID in GraphQL.
Thanks
Hi @Ankit_Arora. We’re sorry for the late reply.
Unfortunately, using v10 UDFs for custom resolvers will not work in many required cases. You may find some workarounds, but I recommend continuing to use v4 for your custom GraphQL resolvers.
Please also note that we are deprecating Fauna’s hosted GraphQL API. If you are putting development time into FQL v10, I would also recommend migrating to pure FQL v10, or plan to move to a different platform to host your GraphQL API (or host your own!). For example, Grafbase has a guide for setting up a server with Fauna, and they have built-in support for Fauna on their roadmap. You can of course use Fauna with any GraphQL server provided the resolvers to translate between the database.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.