How to create three documents in different collections in one UDF call?

Sorry to have to ask the forum for help. My FQL skills were accelerating until I decided to switch to GraphQL last month. Here is my question. I have a standard “register” UDF that creates a new account for a new user. What I’d like to do is:

  1. Create a new “observers” document given the arguments to the UDF.
  2. Create a new “projectFolders” document with the ID of the observer created in step 1.
  3. Create a new “targetFolders” document with the ID of the observer created in step 1.

Here is the existing “register” UDF that performs Step 1:

Query(
  Lambda(
    ["username", "password", "email", "fullName", "website"],
    Create(Collection("observers"), {
      credentials: { password: Var("password") },
      data: {
        username: Var("username"),
        email: Var("email"),
        fullName: Var("fullName"),
        website: Var("website"),
        memberSince: Now(),
        activated: true
      }
    })
  )
)

Thanks very much for any help.
Brian

@oopfan Here’s come code I’ve written which creates a document, and places its ref into an existing document. But you can apply the same principle of storing the created document as a variable in a Let(),extracting it’s ref using Select(), and then placing that in a subsequent Create function call:

Lambda('propertyRef', 
  Let({
    ownerOnlyPropertyDetailDoc: Create(
      Collection("OwnerOnlyPropertyDetail"), {
        data: {
          aquisitionAmount: 111, 
        }   
    }),
    ownerOnlyDetailsRef: Select(['ref'], Var('ownerOnlyPropertyDetailDoc'))
  },
    Update(Var('propertyRef'), {
      data: {
        ownerOnlyDetails: Var('ownerOnlyDetailsRef')
      }
    })
  )
)
2 Likes

@wallslide Perfect, I can concatenate Lets. Thank you very much!
EDIT: Here is the solution:

Query(
  Lambda(
    ["username", "password", "email", "fullName", "website"],
    Let(
      {
        newObserver: Create(Collection("observers"), {
          credentials: { password: Var("password") },
          data: {
            username: Var("username"),
            email: Var("email"),
            fullName: Var("fullName"),
            website: Var("website"),
            memberSince: Now(),
            activated: true
          }
        }),
        newObserverRef: Select(["ref"], Var("newObserver")),
        newProjectFolder: Create(Collection("projectFolders"), {
          data: { folderName: "Uncategorized", owner: Var("newObserverRef") }
        }),
        newTargetFolder: Create(Collection("targetFolders"), {
          data: { folderName: "Uncategorized", owner: Var("newObserverRef") }
        })
      },
      {
        observer: Select(["id"], Var("newObserverRef")),
        projectFolder: Select(["ref", "id"], Var("newProjectFolder")),
        targetFolder: Select(["ref", "id"], Var("newTargetFolder"))
      }
    )
  )
)

@wallslide and @oopfan Appreciate your contributions to the Community. Thanks a mil.