Skip to content

Instantly share code, notes, and snippets.

@randallb
Created August 8, 2022 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randallb/f091ff9cdd7f63af53f3af45faff6bf9 to your computer and use it in GitHub Desktop.
Save randallb/f091ff9cdd7f63af53f3af45faff6bf9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env deno run -q --no-check --cached-only
import SchemaBuilder from "https://esm.sh/@pothos/core@3.13.0";
import { graphql } from "https://esm.sh/graphql@16.5.0/";
const builder = new SchemaBuilder({});
type Meters = number;
type GiraffeShape = {
name: string;
age: number;
height: Meters;
}
const Giraffe = builder.objectRef<GiraffeShape>('Giraffe');
builder.objectType(Giraffe, {
description: 'Long necks, cool patterns, taller than you.',
fields: (t) => ({
name: t.exposeString('name'),
age: t.exposeInt('age'),
height: t.exposeFloat('height'),
}),
});
builder.queryType({
fields: (t) => ({
giraffe: t.field({
type: Giraffe,
resolve: () => ({
name: 'Giraffe',
age: 1,
height: 2,
}),
}),
}),
});
const schema = builder.toSchema({});
if (import.meta.main) {
const source = Deno.args[0] ?? `
query {
giraffe {
name
age
height
}
}
`;
const output = await graphql({
schema,
source,
});
console.log(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment