Skip to content

Commit

Permalink
Document behavior of unions containing unions
Browse files Browse the repository at this point in the history
Fixes #131
  • Loading branch information
captbaritone committed Mar 23, 2024
1 parent 5899592 commit 6f80cd0
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tests/fixtures/unions/UnionAsMemberOfItself.invalid.ts
@@ -0,0 +1,22 @@
/** @gqlType */
export default class SomeType {
/** @gqlField */
me: Actor;
}

/** @gqlType */
class User {
__typename = "User";
/** @gqlField */
name: string;
}

/** @gqlType */
class Entity {
__typename = "Entity";
/** @gqlField */
description: string;
}

/** @gqlUnion */
type Actor = User | Entity | Actor;
@@ -0,0 +1,33 @@
-----------------
INPUT
-----------------
/** @gqlType */
export default class SomeType {
/** @gqlField */
me: Actor;
}

/** @gqlType */
class User {
__typename = "User";
/** @gqlField */
name: string;
}

/** @gqlType */
class Entity {
__typename = "Entity";
/** @gqlField */
description: string;
}

/** @gqlUnion */
type Actor = User | Entity | Actor;

-----------------
OUTPUT
-----------------
src/tests/fixtures/unions/UnionAsMemberOfItself.invalid.ts:22:30 - error: Union type Actor can only include Object types, it cannot include Actor.

22 type Actor = User | Entity | Actor;
~~~~~
32 changes: 32 additions & 0 deletions src/tests/fixtures/unions/UnionAsMemberOfOtherUnion.invalid.ts
@@ -0,0 +1,32 @@
/** @gqlType */
export default class SomeType {
/** @gqlField */
me: Actor;
}

/** @gqlType */
class User {
__typename = "User";
/** @gqlField */
name: string;
}

/** @gqlType */
class Entity {
__typename = "Entity";
/** @gqlField */
description: string;
}

/** @gqlType */
class Admin {
__typename = "Admin";
/** @gqlField */
description: string;
}

/** @gqlUnion */
type Foo = User | Entity;

/** @gqlUnion */
type Actor = Admin | Foo;
@@ -0,0 +1,43 @@
-----------------
INPUT
-----------------
/** @gqlType */
export default class SomeType {
/** @gqlField */
me: Actor;
}

/** @gqlType */
class User {
__typename = "User";
/** @gqlField */
name: string;
}

/** @gqlType */
class Entity {
__typename = "Entity";
/** @gqlField */
description: string;
}

/** @gqlType */
class Admin {
__typename = "Admin";
/** @gqlField */
description: string;
}

/** @gqlUnion */
type Foo = User | Entity;

/** @gqlUnion */
type Actor = Admin | Foo;

-----------------
OUTPUT
-----------------
src/tests/fixtures/unions/UnionAsMemberOfOtherUnion.invalid.ts:32:22 - error: Union type Actor can only include Object types, it cannot include Foo.

32 type Actor = Admin | Foo;
~~~

0 comments on commit 6f80cd0

Please sign in to comment.