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