Skip to content

Commit 8b7b281

Browse files
authored
Fix explanation of writing circular input object types (#45)
1 parent c80239f commit 8b7b281

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

packages/schema/src/output.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,10 @@ export type GWithContext<Context> = {
690690
* object in the type because of TypeScript's limits with circularity.
691691
*
692692
* ```ts
693-
* type SomethingInputType = g.InputObjectType<{
694-
* something: g.Arg<SomethingInputType>;
693+
* import { GInputObjectType } from "@graphql-ts/schema";
694+
*
695+
* type SomethingInputType = GInputObjectType<{
696+
* something: g<typeof g.arg<SomethingInputType>>;
695697
* }>;
696698
* const Something: SomethingInputType = g.inputObject({
697699
* name: "Something",
@@ -706,12 +708,14 @@ export type GWithContext<Context> = {
706708
* non-circular fields as types again.
707709
*
708710
* ```ts
711+
* import { GInputObjectType } from "@graphql-ts/schema";
712+
*
709713
* const nonCircularFields = {
710714
* thing: g.arg({ type: g.String }),
711715
* };
712-
* type SomethingInputType = g.InputObjectType<
716+
* type SomethingInputType = GInputObjectType<
713717
* typeof nonCircularFields & {
714-
* something: g.Arg<SomethingInputType>;
718+
* something: g<typeof g.arg<SomethingInputType>>;
715719
* }
716720
* >;
717721
* const Something: SomethingInputType = g.inputObject({

test-project/index.test-d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,3 +2152,33 @@ const someInputFields = {
21522152
}),
21532153
});
21542154
}
2155+
2156+
{
2157+
const nonCircularFields = {
2158+
thing: g.arg({ type: g.String }),
2159+
};
2160+
type SomethingInputType = GInputObjectType<
2161+
typeof nonCircularFields & {
2162+
something: g<typeof g.arg<SomethingInputType>>;
2163+
}
2164+
>;
2165+
const Something: SomethingInputType = g.inputObject({
2166+
name: "Something",
2167+
fields: () => ({
2168+
...nonCircularFields,
2169+
something: g.arg({ type: Something }),
2170+
}),
2171+
});
2172+
}
2173+
2174+
{
2175+
type SomethingInputType = GInputObjectType<{
2176+
something: g<typeof g.arg<SomethingInputType>>;
2177+
}>;
2178+
const Something: SomethingInputType = g.inputObject({
2179+
name: "Something",
2180+
fields: () => ({
2181+
something: g.arg({ type: Something }),
2182+
}),
2183+
});
2184+
}

0 commit comments

Comments
 (0)