Getting an error when trying to perform simple query with a where condition and JS interpolation

Hi,

I’m trying to perform a simple query via the server program and getting an error.

Below is the function that performs the query:

async findUserByAuthId(auth_id: string): Promise<User | null> {
        const query = fql`User.all().where(.auth_id == "${ auth_id }")`; // this doesn't work
        // const query = fql`User.all().where(.auth_id == "gd4AYvoAkTa9NpYoUq5kBhsvL1q1")`; // this works
        const result = await this.faunaClient.query<User>(query);
        return result.data;
}

And this is the error I get:

What’s strange is that it looks like variable interpolation is causing the issue.

If I remove the interpolation and replace the variable with the value it holds (the commented line in the screenshot), then it works…

I printed the variable to make sure that it is holding the correct value and is not null or undefined.

Thanks in advance! :pray:

Try removing the quotes around "${ auth_id }" like this:

async findUserByAuthId(auth_id: string): Promise<User | null> {
        const query = fql`User.all().where(.auth_id == ${ auth_id })`; // this doesn't work
        // const query = fql`User.all().where(.auth_id == "gd4AYvoAkTa9NpYoUq5kBhsvL1q1")`; // this works
        const result = await this.faunaClient.query<User>(query);
        return result.data;
}
2 Likes

Thank you for the reply. It works when double quotes are removed!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.