As the title says, are there any benefits of using one over the other? Is it good practice to use only one type or is using both at the same time standard practice?
TL;DR - prefer UDFs.
In general, I recommend a “UDF-only” approach where all of your business logic is encapsulated in UDFs and your client-side code doesn’t use any FQL except for
This encapsulation has several benefits:
- your server doesn’t have to “trust” that your client is doing the right thing
- you can make changes to your business logic without modifying/redeploying clients
- you can consume your UDFs across multiple platforms/drivers, including as GraphQL resolvers
- you can do ABAC inside your UDFs
- you can compose UDFs from other UDFs
I’ll always leave room for use cases I haven’t considered/built with, but I have not yet found a situation where I felt that putting the FQL calls in the client code instead of in a UDF was the right approach.
Rob puts his money where his mouth is with extensive use of UDFs, live on Twitch!
to UDF’s everywhere.
To clarify, I prefer defining UDF’s in code and using that code in a bootstrapping script, which is commited to source control. Bootstrap code is separate from client code, where the client is effectively limited to uses of
I’d echo @ptpaterson 's suggestion of defining your UDFs separately from the consuming client code.
Two suggested approaches are to use our plugin for the Serverless Framework or our Fauna Schema Migrate tool, as both allow you to define each UDF in a separate file. If there’s another IaC tool you’d like to see support for - let us know!