Defining a Query that uses a custom resolver function and defining the resolver function via JavaScript Driver

I am trying to define a resolver function using the JavaScript driver. Prior to defining the function I am also uploading our Schema - which defines the query that uses the resolver function. Whenever I try to create the function via the driver - I get a " Function already exists." Error. Is it possible to define the query that uses the resolver and then update the function?

When you import a GraphQL schema that involves the @resolver directive, the GraphQL API creates “stub” functions for each named resolver. A stub function might look like this:

Get(Function("submit_order"))

{
  ref: Ref(Ref("functions"), "submit_order"),
  ts: 1626390962655000,
  name: "submit_order",
  body: Query(
    Lambda(
      "_",
      Abort(
        "Function submit_order was not implemented yet. Please access your database and provide an implementation for the submit_order function."
      )
    )
  ),
  data: {
    gql: {
      ts: Time("2021-07-15T23:16:02.540934Z"),
      meta: {
        location: "Mutation",
        field: {
          name: "submitOrder",
          directives: [
            {
              name: "resolver",
              args: {
                name: "submit_order",
                paginated: false
              }
            }
          ],
          type: {
            NotNull: {
              Named: "Order"
            }
          },
          arguments: [
            {
              name: "customerId",
              type: {
                NotNull: {
                  Named: "ID"
                }
              }
            },
            {
              name: "products",
              type: {
                List: {
                  Named: "SubmitOrderProductInput"
                }
              }
            }
          ]
        }
      }
    }
  }
}

Aside from the GraphQL metadata, the body of the function uses Abort to cause any transaction that calls the function to fail; you haven’t provided an implementation yet.

So instead of creating a resolver function, you just need to Update the existing resolver with your own query expression in the body field. Note that the expression must use Query to defer execution until the function is called.

1 Like