Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.7.0 to 4.7.1 causes InvalidValue error when importing code #666

Open
carlpeaslee opened this issue Oct 31, 2022 · 5 comments
Open

4.7.0 to 4.7.1 causes InvalidValue error when importing code #666

carlpeaslee opened this issue Oct 31, 2022 · 5 comments

Comments

@carlpeaslee
Copy link

carlpeaslee commented Oct 31, 2022

I get the following error after upgrading from 4.7.0 to 4.7.1. The actual occurs when a test imports code that defines FQL that includes variables which reference other FQL. In this case claim_links_id_unique.ref = Index('claim_links_id_unique').

This code runs fine (and actually isn't even executed by the test that fails since it's defining a UDF). My guess is that faunadb is doing some kind of pre-run static analysis and for whatever reason, because of the order of imports, claim_links_id_unique.ref is undefined at the time faunadb does its analysis?

    InvalidValue: Expected value, but found 'undefined'. Argument 0 for Match is required.

      36 |                     Select(
      37 |                         ['data', 0],
    > 38 |                         Paginate(Match(claim_links_id_unique.ref, Var('claim_link_id')))
         |                                  ^
      39 |                     )
      40 |                 )
      41 |             ),

      at arity (../../node_modules/faunadb/src/query.js:2976:15)
      at Function.Object.<anonymous>.arity.min (../../node_modules/faunadb/src/query.js:2991:3)
      at Match (../../node_modules/faunadb/src/query.js:1084:9)
      at Object.<anonymous> (../../pkgs/db_management/functions/claim_links/get_user_claim_link.ts:38:34)
      at Object.<anonymous> (../../pkgs/db_management/functions/claim_links/get_claim_link.ts:8:1)

Also apologies, I didn't see a template for filing issues so let me know if there is additional information you'd like.

cc @thomas-franceschi

@github-actions
Copy link

Internal ticket number is FE-2847

@henryfauna
Copy link
Contributor

Hi @carlpeaslee, thanks for bringing this up! I'll take a look and get back to you.

@henryfauna
Copy link
Contributor

@carlpeaslee Are you able to share code?

@mwilde345
Copy link
Member

@carlpeaslee this patch was motivated by the decision to validate that Client query arguments match existing typescript types. This just changes where the query gets denied, in the driver itself instead of as a 400 response from the database.

In your case it's exposing the fact that your ExprArg value (claim_links_id_unique.ref) is undefined at the moment your query is submitted to the driver. It doesn't make it to faunadb. Also this javascript driver doesn't do any static analysis of your query. The FQL query function is not "lazy loaded", it's simply executed immediately as it's evaluated in your file during runtime. So it's up to you to ensure that claim_links_id_unique exists before you define this query that uses its ref.

I'm not sure exactly how this would look without knowing more of your code and test framework. But it's a matter of waiting for one fauna query to finish before defining another query that depends on the first query's completion.

For now we want to leave this change in as a patch, because it matches existing typescript definitions. Depending on your and other's feedback we would consider making this a major version change.

@carlpeaslee
Copy link
Author

thanks for the helpful responses. I will try to get back to you all soon with more code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants