Value not found at path - Graph Issues

I have the following:

Custom resolver function:

Query(
  Lambda(
    "data",
    Let(
      {
        cId: Select("cId", Var("data")),
        itemIds: Select("itemIds", Var("data"))
      },
      Update(Ref(Collection("collections"), Var("cId")), {
        data: {
          items: Map(
            Var("itemIds"),
            Lambda("id", Ref(Collection("cart_items"), Var("id")))
          )
        }
      })
    )
  )
)

Mutation schema:

input UpdateCollectionItemsInput {
  cId: ID!
  itemIds: [ID!]!
}

type Mutation {
  updateCollectionItems(data: UpdateCollectionItemsInput!): Collection @resolver(name: "update_collection_items")
}

And running the following in Graphql Playground:

mutation UpdateCollectionItems($data: UpdateCollectionItemsInput!) {
  collection: updateCollectionItems(data: $data) {
    _id
  }
}

With the following params:

{
  "data": {
    "cId": "289714644730249734",
    "itemIds": ["289715074820473350"]
  }
}

However, I keep getting the following error:

{
  "errors": [
    {
      "message": "Value not found at path [cId].",
      "extensions": {
        "code": "value not found"
      }
    }
  ]
}

The same code seems to work fine when I run it via Shell:

Call("update_collection_items", {
  cId: "289714644730249734",
  itemIds: ["289715074820473350"]
})

Ok, so I made a small change to the UDF and it seems to be working now. I changed "data" to ["data"],

Query(
  Lambda(
    ['data'],
    Let(
      ...
    )
  )
)

Not sure I fully understand. Can someone explain the difference between ['data'] and 'data' on the Lambda call?

You have to use an array of args with functions and GraphQL:

The UDF must accept an array of arguments

@ryanjduffy does that mean it is always best to use an an array argument in Lambda? For example, most of my mutations pass an object as argument (ie, data: {...}). Still not quiet sure I understand why ["data"] works in this example and "data" does not when selecting keys under data.

I think that if you want to be able to use a UDF as a GraphQL resolver, you should use arrays for the Lambda. From FQL, either works for a single argument.

1 Like