From ad2b955bd27585eef7c91dec48ecc1cea15d3363 Mon Sep 17 00:00:00 2001 From: Mish Ushakov Date: Fri, 2 Jun 2023 17:07:32 +0200 Subject: [PATCH] async tsimport > sync tsimport --- package-lock.json | 4 ++-- src/index.ts | 2 ++ src/plugin.ts | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 147204a..8530cfb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@garph/gqty", - "version": "0.4.2", + "version": "0.4.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@garph/gqty", - "version": "0.4.2", + "version": "0.4.3", "license": "MIT", "dependencies": { "@gqty/react": "^3.0.0-alpha-4ad34526.0", diff --git a/src/index.ts b/src/index.ts index 18618b9..2a90b69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ type ClientOptions = { headers?: HeadersInit defaults?: ReactClientDefaults cacheOptions?: CacheOptions + fetch?: typeof globalThis.fetch } // TODO @@ -33,6 +34,7 @@ function createQueryFetcher (options: ClientOptions): QueryFetcher { { query, variables, operationName }, fetchOptions ) { + const fetch = options.fetch ?? globalThis.fetch const response = await fetch(options.url, { method: "POST", headers: { diff --git a/src/plugin.ts b/src/plugin.ts index 3d9b5d1..30f546d 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,4 +1,4 @@ -import { importTSmodule } from '@mishushakov/ts-load' +import { importTSmoduleSync } from '@mishushakov/ts-load' import { resolve } from 'path' import serialize from 'babel-literal-to-ast' import { createGeneratedSchema, createScalarsEnumsHash } from './utils' @@ -12,11 +12,11 @@ export default function GarphGQtyPlugin(_, { clientConfig }) { path.node.specifiers = [] } }, - async CallExpression(path, state) { + CallExpression(path, state) { if (state.file.opts.filename !== resolve(clientConfig)) return if (path.node.callee.name !== 'createClient') return - const module = await importTSmodule(state.file.opts.filename) + const module = importTSmoduleSync(state.file.opts.filename) const schema = module.compiledSchema const generatedSchema = createGeneratedSchema(schema) const scalarsEnumsHash = createScalarsEnumsHash(schema)