Array, Set, or Page expected, Object provided on @resolver

Trying to create my first mutation with a custom resolver

This is my mutation definition:

type Mutation {
  verifyUser(account: ID!, verified: Boolean!): User
    @resolver(name: "verify_user", paginated: false)
}

This is the UDF body:

Query(
  Lambda(
    ["account", "verified"],
    Update(
      Select(["ref"], Get(Match(Index("unique_User_account"), Var("account")))),
      { data: { isVerified: Var("verified") } }
    )
  )
)

If I call it from the shell like this it works fine:

Call('verify_user', "testeador112", true)

{
  ref: Ref(Collection("User"), "295243696040837633"),
  ts: 1617871434700000,
  data: {
    account: "testeador112",
    isVerified: true,
    blockNum: 81649323
  }
}

But when I execute the mutation I’m getting this error:

mutation {
  verifyUser(account:"testeador112", verified:false) {
    account
    displayName
    isVerified
  }
}

{
  "errors": [
    {
      "message": "Array, Set, or Page expected, Object provided.",
      "extensions": {
        "code": "invalid argument"
      }
    }
  ]
}

Any idea where the problem is?

GraphQL API passes the parameters in an Array but your UDF is not considering the Array. Try this Call(Function('verify_user'), ["testeador112", true]) to reproduce the problem.

The error makes me think that your schema is actually

verifyUser(account: ID!, verified: Boolean!): [User] // <-- List type

Otherwise I find this super strange.

Regarding Call(Function('verify_user'), ["testeador112", true])

Both should work, because js driver and shell treat an array argument and variable argument list the same. Docs don’t make that super clear, but you can tell if you investigate the driver.

The thing to watch out for is that if Call only sees a single argument it doesn’t wrap in an array. This matters for GraphQL, because like Jay said, the GraphQL API always calls with arguments in an array – Even if there’s only one argument.

// these two calls are equivalent IF your UDF Lambda destructures an array (yours does)
Call(Function('my_udf'), "one", "two")
Call(Function('my_udf'), ["one", "two"])

// but these are NOT!
Call(Function('my_udf'), "one")
Call(Function('my_udf'), ["one"])  // GraphQL will call like this!

// So always write GraphQL custom resolver UDFs with array syntax
Query(Lambda(["one"], /* ... */ )) // Good for GraphQL resolver
Query(Lambda("one", /* ... */ )) // BAD for GraphQL resolver

In any case, your UDF has multiple parameters and they are used like an array in the UDF. :+1:

Tried calling

Call('verify_user', ["testeador112", true])

on the shell to reproduce the problem but I didn’t get any error:

Call('verify_user', ["testeador112", true])

{
  ref: Ref(Collection("User"), "295243696040837633"),
  ts: 1618321024745000,
  data: {
    account: "testeador112",
    isVerified: true,
    blockNum: 81649323,
    displayName: "TheTester"
  }
}

>> Time elapsed: 248ms

Understood but in my example I am destructuring in the lambda function so it should work:

Query(
  Lambda(
    ["account", "verified"],
    Update(
      Select(["ref"], Get(Match(Index("unique_User_account"), Var("account")))),
      { data: { isVerified: Var("verified") } }
    )
  )
)

Agreed. I said as much. That’s why I was suspicious that your schema is different.

The error suggests that the expected output type of the resolver is a List Type. Can you share the relevant part of the generated schema (from Playground, not what you uploaded)?

Oh you are right! From playground this is what verifyUser looks like:

verifyUser(account: ID!, verified: Boolean!): [User]

However this is what I have in my schema definition:

type Mutation {
  verifyUser(account: ID!, verified: Boolean!): User
    @resolver(name: "verify_user", paginated: false)
  updateUser(input: MyUserInput!): User
    @resolver(name: "update_user", paginated: false)
}

You can see there’s another mutation there using a custom input type. That one is correct in the playground and it’s returning a User not a [User]

updateUser(input: MyUserInput!): User

Is this a bug or am I doing something wrong?

I am glad that solves the riddle at least! :slight_smile:

Try to update the schema again? If that doesn’t work than could be a super surprising bug. But I mean, make sure first. That is make sure you didn’t just change your schema and forget to update it!

If update schema completes successfully, but there is still a discrepancy between the uploaded definition and the resulting generated schema, then maybe try to replicate it? That really would be a scary bug.

If update schema doesn’t work, then you might be able to update the data.gql field on the database (I think it’s database level for top level Mutation and Query types).

Updating the schema was successful but didn’t fix it.

Creating a blank db and uploading the schema creates the correct return type in the playground:

verifyUser(account: ID!, verified: Boolean!): User

Do you want me to run any other tests?

I created a separate post to detail the bug that I think is at fault.

You can confirm by checking the meta data

Get(Function('verify_user'))