Skip to content

Instantly share code, notes, and snippets.

@kevinmichaelchen
Last active October 27, 2025 16:15
Show Gist options
  • Select an option

  • Save kevinmichaelchen/4f48dd7da6e453d6d73adfe49750340b to your computer and use it in GitHub Desktop.

Select an option

Save kevinmichaelchen/4f48dd7da6e453d6d73adfe49750340b to your computer and use it in GitHub Desktop.
GraphQL Codegen + Temporal Zod Demo - Demonstrating how to use GraphQL Codegen to generate Zod schemas with Temporal type support in Deno

GraphQL Codegen + Temporal Zod Demo

A demonstration of using GraphQL Codegen to generate Zod schemas with Temporal type support using Deno and TypeScript.

Running the Code

# Install dev dependencies so we can run codegen
deno install

# Run GraphQL Codegen
deno task codegen

Then run the demo:

deno test
schema: schema.graphql
generates:
src/generated/zod.ts:
plugins:
- '@use-pico/graphql-codegen-zod'
config:
scalars:
Instant: 'zInstant'
imports:
- "import { zInstant } from \"temporal-zod\";"
{
"tasks": {
"codegen": "deno run -A npm:@graphql-codegen/cli/graphql-codegen"
},
"imports": {
"graphql": "npm:graphql@16.11.0",
"temporal-polyfill": "npm:temporal-polyfill@0.3.0",
"temporal-zod": "npm:temporal-zod@0.5.0",
"zod": "npm:zod@4.1.12",
"@use-pico/graphql-codegen-zod": "npm:@use-pico/graphql-codegen-zod@4.0.62",
"@graphql-codegen/cli": "npm:@graphql-codegen/cli@6.0.1"
}
}
import { describe, it } from "jsr:@std/testing/bdd";
import { expect } from "jsr:@std/expect";
import { Temporal } from "temporal-polyfill";
import { z } from "zod";
import { EventSchema } from "./src/generated/zod.ts";
type Event = z.infer<typeof EventSchema>;
describe("EventSchema", () => {
it("should parse event with Temporal.Instant", () => {
const parsed: Event = EventSchema.parse({
name: "System Boot",
timestamp: Temporal.Now.instant(),
});
expect(parsed.name).toBe("System Boot");
expect(parsed.timestamp).toBeInstanceOf(Temporal.Instant);
});
it("should parse event with ISO string timestamp", () => {
const parsed: Event = EventSchema.parse({
name: "User Login",
timestamp: "2025-10-24T15:30:00Z",
});
expect(parsed.name).toBe("User Login");
expect(parsed.timestamp).toBeInstanceOf(Temporal.Instant);
expect(parsed.timestamp.toString()).toBe("2025-10-24T15:30:00Z");
});
});
scalar Instant
type Event {
name: String!
timestamp: Instant!
}
type Query {
events: [Event!]!
}
@kevinmichaelchen
Copy link
Author

kevinmichaelchen commented Oct 24, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment