fauna / fauna-js

Javascript driver for Fauna v10 (current)
https://fauna.com
Other
37 stars 7 forks source link

Nested data key throws #294

Closed panoply closed 1 month ago

panoply commented 1 month ago

It seems rather absurd that nested keys using data property will throw.

Take the following:

const update = {
   "name": "foo",
   "age": 30,
   "info": [
      {
          "sport": "boxing",
          "data": [
              {
                  "foo": "a"
              }
          ]
      }
   ]
}

client.query(fql`Example.byId('12345678090')?.update(${update})`)

Throws:

TypeError: Passing function as a QueryArgument is not supported

This is because of the data property, which deeply nested within the structure, am I missing something here?

ptpaterson commented 1 month ago

Hi @panoply Agreed there should be no issue with the query you shared. We cannot reproduce the error, though. Can you provide a minimal gist that reproduces it? What leads you to believe there is an issue with the nested data field? Here is me executing the same query

image

The error indicates that you are trying to pass a function as an argument, and the update variable you show is clearly a plain old object.

panoply commented 1 month ago

I am scratching my head here because the only difference with code sample and data is that its a getter reference.

ptpaterson commented 1 month ago

Can you provide an example of what you mean? You cannot provide any object with functions as properties. If you are using a class instance as an argument, consider adding a "toObject" method that converts the class into a plain old object.

ptpaterson commented 1 month ago

I'm going to close this issue, but please feel free to follow up if you continue to have problems or find anything else.