Skip to content

Commit

Permalink
Opt-in to strict strings for __type__.name
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Sep 4, 2024
1 parent 476d8e2 commit 92f8e59
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions integration-tests/lts/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module "./dbschema/edgeql-js/typesystem" {
export interface SetTypesystemOptions {
future: {
polymorphismAsDiscriminatedUnions: true;
strictTypeNames: true;
};
}
}
Expand Down Expand Up @@ -1038,6 +1039,7 @@ SELECT __scope_0_defaultVillain {
nemesis: (nemesis) => {
const nameLen = e.len(nemesis.name);
return {
t: nemesis.__type__.name,
name: true,
nameLen,
nameLen2: nameLen,
Expand All @@ -1060,6 +1062,7 @@ SELECT __scope_0_defaultPerson {
WITH
__scope_1_defaultVillain := __scope_0_defaultPerson[IS default::Hero].villains
SELECT __scope_1_defaultVillain {
t := .__type__.name,
id,
name,
nemesis := (
Expand Down Expand Up @@ -1104,6 +1107,7 @@ SELECT __scope_0_defaultPerson {
id: string;
name: string;
nemesis: {
t: "default::Hero";
name: string;
nameLen: number;
nameLen2: number;
Expand Down Expand Up @@ -1417,6 +1421,7 @@ SELECT __scope_0_defaultPerson {
title: true,
rating: true,
filter_single: e.op(movie.title, "=", "The Avengers"),
__typename: movie.__type__.name,
}));
const characterShape = e.shape(e.Person, () => ({
name: true,
Expand All @@ -1439,6 +1444,7 @@ SELECT __scope_0_defaultPerson {
{
title: string;
rating: number | null;
__typename: "default::Movie";
} | null
>
>(true);
Expand Down
9 changes: 8 additions & 1 deletion packages/generate/src/syntax/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
PropertyShape,
TypeSet,
ScalarType,
TypesystemOptions,
} from "./typesystem";
// import {typeutil} from "./typeutil";
// import {cardutil} from "./cardinality";
Expand All @@ -42,7 +43,13 @@ type getChildOfObjectTypeSet<
> = TypeSet<
ChildKey extends "name"
? Root extends { [typenameSymbol]: string }
? ScalarType<"std::str", string, Root[typeof typenameSymbol]>
? ScalarType<
"std::str",
TypesystemOptions["future"]["strictTypeNames"] extends true
? Root[typeof typenameSymbol]
: string,
Root[typeof typenameSymbol]
>
: Root["__element__"]["__pointers__"][ChildKey]["target"]
: Root["__element__"]["__pointers__"][ChildKey]["target"],
cardutil.multiplyCardinalities<
Expand Down
8 changes: 8 additions & 0 deletions packages/generate/src/syntax/typesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export type TypesystemOptions = {
}
? true
: false;
/**
* Opt-in to strict __type__.name string literal unions.
*/
strictTypeNames: SetTypesystemOptions extends {
future: { strictTypeNames: true };
}
? true
: false;
};
};

Expand Down

0 comments on commit 92f8e59

Please sign in to comment.