From 735c30930137ce2a28197d9ad966f4ca8e6822e1 Mon Sep 17 00:00:00 2001 From: Vicary A Date: Wed, 26 Oct 2022 12:57:27 +0800 Subject: [PATCH] chore: import maps and example logging --- .../graphql/Subscription/countdown.ts | 11 ++++++++--- import_map.json | 5 +++-- schema.ts | 19 ++++++++----------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/examples/graphql-yoga/graphql/Subscription/countdown.ts b/examples/graphql-yoga/graphql/Subscription/countdown.ts index 69a9b58..d14b14e 100644 --- a/examples/graphql-yoga/graphql/Subscription/countdown.ts +++ b/examples/graphql-yoga/graphql/Subscription/countdown.ts @@ -8,8 +8,13 @@ export const schema = /* GraphQL */ ` export const resolver: IFieldResolver = async function* (_, { from }) { - for (let i = from; i >= 0; i--) { - await new Promise((resolve) => setTimeout(resolve, 1000)); - yield { countdown: i }; + try { + while (from > 0) { + await new Promise((resolve) => setTimeout(resolve, 1000)); + yield { countdown: from }; + from--; + } + } finally { + console.info(`Countdown finished${from > 0 ? ` at ${from}` : ""}.`); } }; diff --git a/import_map.json b/import_map.json index a0596e1..0799edc 100644 --- a/import_map.json +++ b/import_map.json @@ -8,7 +8,8 @@ "@preact/signals": "https://esm.sh/*@preact/signals@1.0.3", "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1", - "@graphql-yoga/common": "https://cdn.skypack.dev/@graphql-yoga/common?dts", - "@graphql-tools/utils": "https://cdn.skypack.dev/@graphql-tools/utils?dts" + "@graphql-tools/schema": "https://cdn.skypack.dev/@graphql-tools/schema?dts", + "@graphql-tools/utils": "https://cdn.skypack.dev/@graphql-tools/utils?dts", + "@graphql-yoga/common": "https://cdn.skypack.dev/@graphql-yoga/common?dts" } } diff --git a/schema.ts b/schema.ts index 3283e1c..9edde25 100644 --- a/schema.ts +++ b/schema.ts @@ -1,21 +1,18 @@ // deno-lint-ignore-file no-explicit-any -import type { - IExecutableSchemaDefinition, -} from "https://cdn.skypack.dev/@graphql-tools/schema?dts"; -import { - makeExecutableSchema, -} from "https://cdn.skypack.dev/@graphql-tools/schema?dts"; -import type { - IFieldResolver, - IResolvers, -} from "https://cdn.skypack.dev/@graphql-tools/utils?dts"; +import type { IExecutableSchemaDefinition } from "@graphql-tools/schema"; +import { makeExecutableSchema } from "@graphql-tools/schema"; +import type { IFieldResolver, IResolvers } from "@graphql-tools/utils"; +import type { GraphQLScalarType } from "https://esm.sh/graphql@16.6.0"; export type Callable = (...args: any[]) => any; export type GraphQLModule = { schema?: string; - resolver?: IResolvers | IFieldResolver; + resolver?: + | GraphQLScalarType + | IResolvers + | IFieldResolver; }; export type Manifest = {