@generateUDFResolvers directive

Specifies that queries which would otherwise be resolved in FQL dynamically, be persisted as UDFs for the annotated Types, except when that type is involved in a relationship.

Schema location

This directive is valid for Type declarations within a GraphQL schema.

Arguments

None.

Description

When you annotate a GraphQL Type (in your schema) with the `@generateUDFResolvers` directive, the GraphQL API creates the following CRUD UDFs for the annotated Type, except when that Type is involved in a relationship: create<Type>, find<Type>ByID, update<Type>, delete<Type>, and list<Type>. These UDFs are used as the implementations for the corresponding GraphQL Queries and Mutations types added by the GraphQL API when you import your schema.

If you attempt to annotate an embedded Type with `@generateUDFResolvers`, the schema import fails.

Example

When the following GraphQL schema has been imported:

type User {
  name: String!
}

type Cat @generateUDFResolvers {
  name: String!
}

The database contains the following UDFs:

Map(Paginate(Functions())\
{
  data: [
    {
      ref: Function("listCat"),
      ts: 1647645619770000,
      name: 'listCat',
      data: {
        // not shown
      },
      body: Query(Lambda(["size", "after", "before"], Let({"setToPageOver": Documents(Collection("Cat")), "page": Paginate(Var("setToPageOver"), {"cursor": If(Equals(Var("before"), null), If(Equals(Var("after"), null), null, {"after": Var("after")}), {"before": Var("before")}), "size": Var("size")})}, Map(Var("page"), Lambda("ref", Get(Var("ref")))))))
    },
    {
      ref: Function("updateCat"),
      ts: 1647645619770000,
      name: 'updateCat',
      data: {
        // not shown
      },
      body: Query(Lambda(["id", "data"], If(Exists(Ref(Collection("Cat"), Var("id"))), Update(Ref(Collection("Cat"), Var("id")), {"data": Var("data")}), null)))
    },
    {
      ref: Function("createCat"),
      ts: 1647645619770000,
      name: 'createCat',
      data: {
        // not shown
      },
      body: Query(Lambda(["data"], Create(Collection("Cat"), {"data": Var("data")})))
    },
    {
      ref: Function("deleteCat"),
      ts: 1647645619770000,
      name: 'deleteCat',
      data: {
        // not shown
      },
      body: Query(Lambda(["id"], If(Exists(Ref(Collection("Cat"), Var("id"))), Delete(Ref(Collection("Cat"), Var("id"))), null)))
    },
    {
      ref: Function("findCatByID"),
      ts: 1647645619770000,
      name: 'findCatByID',
      data: {
        // not shown
      },
      body: Query(Lambda(["id"], If(Exists(Ref(Collection("Cat"), Var("id"))), Get(Ref(Collection("Cat"), Var("id"))), null)))
    }
  ]
}

Note that no UDFs are generated for the User type because that type was not annotated.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!