generated from JoshuaKGoldberg/create-typescript-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from puzzmo-com/fixes
Type narrowing improvements and graphql parent type support
- Loading branch information
Showing
9 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { expect, it } from "vitest" | ||
|
||
import { getDTSFilesForRun, graphql, prisma } from "../testRunner.js" | ||
|
||
it("Uses GraphQL objects when prisma objects are not available for resolver parents", () => { | ||
const prismaSchema = prisma` | ||
model Game { | ||
id Int @id @default(autoincrement()) | ||
} | ||
` | ||
|
||
const sdl = graphql` | ||
type Game { | ||
id: Int! | ||
} | ||
type Puzzle { | ||
id: Int! | ||
} | ||
` | ||
|
||
const gamesService = ` | ||
import { db } from "src/lib/db"; | ||
export const Puzzle = { | ||
id: "", | ||
}; | ||
` | ||
|
||
const { vfsMap } = getDTSFilesForRun({ sdl, gamesService, prismaSchema }) | ||
const dts = vfsMap.get("/types/games.d.ts")! | ||
expect(dts.trim()).toMatchInlineSnapshot(` | ||
"import type { Puzzle as SPuzzle } from \\"./shared-return-types\\"; | ||
export interface PuzzleTypeResolvers { | ||
/** SDL: id: Int! */ | ||
id: number; | ||
} | ||
type PuzzleAsParent = SPuzzle & { id: () => number };" | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expect, it } from "vitest" | ||
|
||
import { getDTSFilesForRun, graphql, prisma } from "../testRunner.js" | ||
|
||
it("The retunr type can be a graphql interface", () => { | ||
const prismaSchema = prisma` | ||
model Game { | ||
id Int @id @default(autoincrement()) | ||
} | ||
` | ||
|
||
const sdl = graphql` | ||
type Game { | ||
id: Int! | ||
puzzle: Node! | ||
} | ||
interface Node { | ||
id: ID! | ||
} | ||
` | ||
|
||
const gamesService = ` | ||
import { db } from "src/lib/db"; | ||
export const Game = { | ||
puzzle: () => {} | ||
}; | ||
` | ||
|
||
const { vfsMap } = getDTSFilesForRun({ sdl, gamesService, prismaSchema }) | ||
const dts = vfsMap.get("/types/games.d.ts")! | ||
expect(dts.trim()).toMatchInlineSnapshot(` | ||
"import type { Game as PGame } from \\"@prisma/client\\"; | ||
import type { GraphQLResolveInfo } from \\"graphql\\"; | ||
import type { RedwoodGraphQLContext } from \\"@redwoodjs/graphql-server/dist/types\\"; | ||
import type { Node as RTNode } from \\"./shared-return-types\\"; | ||
import type { Node } from \\"./shared-schema-types\\"; | ||
export interface GameTypeResolvers { | ||
/** SDL: puzzle: Node! */ | ||
puzzle: ( | ||
args?: undefined, | ||
obj?: { | ||
root: GameAsParent; | ||
context: RedwoodGraphQLContext; | ||
info: GraphQLResolveInfo; | ||
} | ||
) => RTNode; | ||
} | ||
type GameAsParent = PGame & { puzzle: () => RTNode };" | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters