edgedb / edgedb-js

The official TypeScript/JS client library and query builder for EdgeDB
https://edgedb.com
Apache License 2.0
514 stars 65 forks source link

Code from `@edgedb/generate` missing a module when the auth extension is enabled. #1103

Closed MiroslavPetrik closed 2 months ago

MiroslavPetrik commented 2 months ago

Error The npx @edgedb/generate edgeql-js --out ./src/edgeql-js (latest version 0.5.6) generates code which is not able to compile. With the previous version (0.4.1) it worked.

./src/edgeql-js/modules/ext/auth.ts:7:34
Type error: Cannot find module '../__default' or its corresponding type declarations.

   5 | import type * as _std from "../std";
   6 | import type * as _default from "../default";
>  7 | import type * as ___default from "../__default";
     |                                  ^
   8 | import type * as _cfg from "../cfg";
   9 | export type $FlowType = {
  10 |   "PKCE": $.$expr_Literal<$FlowType>;

Schema

Your application schema.

using extension auth;

module default {
  global identity := (select global ext::auth::ClientTokenIdentity);

  global current_user := (
    assert_single((
      select User {*}
      filter .identity =
        global ext::auth::ClientTokenIdentity
    ))
  );

  type User {
      required identity: ext::auth::Identity {
        constraint exclusive;
      };
      required name: str;
  }
}

Error or desired behavior

The generated code should compile. I have a repository (https://github.com/MiroslavPetrik/net3-starter/tree/bump-generate) where this error can be reproduced (npm install and npm run build). Also the generated code works on the main branch with the same schema.

Versions (please complete the following information):

scotttrinh commented 2 months ago

This is actually a small bug in the introspection: if you remove the {*} shape from your global it will work as expected. Globals do not need shapes in their definition, you would put the shape on the select when using the global, when needed.

scotttrinh commented 2 months ago

FWIW, this has been addressed on the server side, I believe, and should be fixed in an upcoming release.

MiroslavPetrik commented 2 months ago

Thank you @scotttrinh it worked.