I am trying to create an upsert function for UDFs in v4 as part of my graphql migration. I’ve run into what feels like a bug when trying to get the id
of a Function reference:
I can check for the existence of a Function
without issue, whether or not it exists:
q.Let(
{
functionRef: q.Function('fakeFunction'),
},
q.Exists(q.Var('functionRef'))
)
>> false
But when I try to get the id of a Function
(the ‘fakeFunction’ name) from the Function
ref, I get this error:
q.Let(
{
functionRef: q.Function('fakeFunction'),
},
q.Select('id', q.Var('functionRef'))
)
>> Error: [
{
"position": [
"in",
"from"
],
"code": "invalid ref",
"description": "Ref refers to undefined function 'fakeFunction'"
}
]
I’m able to get the id of the Function
if the function exists however.
q.Let(
{
functionRef: q.Function('existingFunction'),
},
q.Select('id', q.Var('functionRef'))
)
>> existingFunction
The same is true for other schema as well
This might be an artifact of us not allowing you to persist references to schema that don’t exist (at the time of creation anyway).
Some schema, for example Roles, require you to specify existing schema references in your Role definitions: like if you try to add permissions for a Collection that doesn’t exist, you’ll get an error.
Are you able to work around it? Here’s an older post where I do a similar upsert-function query: "Upsert" FQL example not working - #4 by ptpaterson
1 Like
I was able to work around it. I switched from passing a Function
ref to a string instead. I had started with a Function
ref because that’s what Update
takes as its first argument, and I was refactoring from that.
Okay, very good. The fact that this doesn’t work is a bit of a disconnect, given the general impression that “everything is document” in v4. I’ve created an internal ticket for this as a potential improvement for the record. That said, with workarounds available and efforts focused on v10, I can’t say that this will make the cut.
Thank you, as always, for your continued feedback!