edgedb-js: EdgeQLSyntaxError: Unexpected keyword "IN" / mixing string type literals and type names is not supported

Code The code causing the error.

(async() => {
  let databaseQuery;

  switch((query.type as Record["type"])) {
    case "A":
    case "AAAA":
    case "CNAME":
    case "DNAME":
    case "NS":
    case "PTR": {
      databaseQuery = e.select(
        e.insert(e.PlainRecord, { ...query }),
        () => ({ ...e.PlainRecord["*"] })
      );
      break;
    }

    default: {
      break;
    }
  }

  try {
    response = await databaseQuery.run(client);
    return { detail: response };
  } catch(_) {
    return { detail: response };
  }
});

Schema

Your application schema.

module default {
  scalar type ClassType extending enum<"CH", "CS", "HS", "IN">;

  abstract type BaseRecord {
    required property class -> ClassType;
    required property created -> datetime {
      default := datetime_of_transaction();
      readonly := true;
    };
    required property name -> str;
    required property ttl -> float64;
    required property type -> RecordType;
    required property updated -> datetime {
      default := datetime_of_transaction();
    };
  }

  type PlainRecord extending BaseRecord {
    required property data -> str;
  }
}

Generated EdgeQL

SELECT (INSERT default::PlainRecord {
  name := "app.beachfront",
  type := default::RecordType.A,
  class := default::ClassType.IN,
  ttl := 300
}) {
  data,
  class,
  name,
  ttl,
  type,
  created,
  updated,
  id
}

Error or desired behavior

SS 2023-04-20 at 1 23 12 PM

Versions (please complete the following information):

  • OS: macOS Ventura
  • EdgeDB version (e.g. 2.0): 2.5+5f12a50
  • EdgeDB CLI version (e.g. 2.0): 2.3.1+5d93f42
  • edgedb-js version (e.g. 0.20.10😉: 1.1.0 (latest Deno version)
  • @edgedb/generate version (e.g. 0.0.7😉: 1.1.0 (latest Deno version)
  • Typescript version: 5.0.3
  • Deno version: 1.32.2 (release, aarch64-apple-darwin)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

@NetOpWibby Yeah, I noticed that and opened an issue to figure that out #599 . Hope to have a new release of the library out next week that incorporates this change and does the Deno release.

Just at query time I think. The schema I think is technically using the older enum syntax, but it’s still valid so it’s fine. (Syntax change details: https://github.com/edgedb/edgedb/issues/1833#issuecomment-700235349).

@scotttrinh I think this is a bug in querybuilder. In the edgeql codegen it looks like we’re not correctly quoting enum values that are also keywords, ie. the generated edgeql should be:

SELECT (INSERT default::PlainRecord {
  name := "app.beachfront",
  type := default::RecordType.A,
  class := default::ClassType.`IN`,
  ttl := 300
}) {
  data,
  class,
  name,
  ttl,
  type,
  created,
  updated,
  id
}