From d295796667041bff582904b6d6f11a21c4ab5358 Mon Sep 17 00:00:00 2001 From: Omar Date: Sun, 19 Nov 2023 13:45:45 -0800 Subject: [PATCH] update deps & support 'graphiql' endpoint --- .github/workflows/{ci.yml => deploy.yml} | 6 ++--- README.md | 4 ++- bun.lockb | Bin 2022 -> 2023 bytes package.json | 6 ++--- src/graphql/graphiql.html.ts | 33 +++++++---------------- src/graphql/schema.ts | 24 ++++++++++++----- src/index.ts | 20 ++++++++------ tsconfig.json | 5 ++-- 8 files changed, 51 insertions(+), 47 deletions(-) rename .github/workflows/{ci.yml => deploy.yml} (94%) diff --git a/.github/workflows/ci.yml b/.github/workflows/deploy.yml similarity index 94% rename from .github/workflows/ci.yml rename to .github/workflows/deploy.yml index ebd5ede..444d6af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: CI +name: Deploy on: workflow_dispatch: @@ -21,11 +21,11 @@ env: jobs: deploy: name: "Deploy" - timeout-minutes: 3.69 + timeout-minutes: 2 runs-on: ["ubuntu-latest"] steps: - name: "Checkout" - uses: actions/checkout@v3 + uses: actions/checkout@v4.1.1 - name: "Setup Bun" uses: oven-sh/setup-bun@v1 diff --git a/README.md b/README.md index 0ac386d..1228448 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,9 @@ or get the `SDL` [`https://introspect.lagon.dev/sdl/https://spacex-production.up.railway.app`](https://introspect.lagon.dev/sdl/https://spacex-production.up.railway.app) -or play around with it in a live playground [https://introspect.lagon.dev/playground/https://spacex-production.up.railway.app](https://introspect.lagon.dev/playground/https://spacex-production.up.railway.app) +or play around with it in a live playground + +[`https://introspect.lagon.dev/playground/https://spacex-production.up.railway.app`](https://introspect.lagon.dev/playground/https://spacex-production.up.railway.app) By default API will return schema as `JSON` diff --git a/bun.lockb b/bun.lockb index d4f29f606e91e5ac6fc160323ae360d7f4e54203..3bdda0479546010a4acfe5d2f212d7eab36e4889 100755 GIT binary patch delta 446 zcmaFH|D1ns+A>XRLSJSHHI3CwF?#*Zccml>EihadXwyO!)lRd}pXnbInY(+z%hG zm@LaPWz{=Ac`cJf{fs`bbrav@D9IeOj}dQ-+_&Gv(Yw0|+N z#oagJx+|j&@+Kz>)JT@e51IWpKVV+WXkn;lpl4{zAPkh@0tU-`)dn5y*3={p#yC?w zBRwMqhV-Juf{el(25Fa~U&%@bWSJP_49)Z`ChumQ%IH5ikgbH#V)8LIcV?jC$pY-A STo42GO46$)2eMBEc>(}W)|wLl delta 530 zcmaFP|BQcvo}zkZ|B4T4{soUecf=L!f8DeyQgXSU#P85=iCK~P{4q_Z1$VQSkkl+~l=P67^@7HZ3-Zd|`AXg0*#Rz~?J< zt)VqnJimN;63P>GL^b%B+LOtDE8ZDSG!nE3n6OVo{&mbR>yNv3@tAutsPFr^PX_2F zMuva<|A4M#200K4So|3(n%3|uW;cq>KH=d!r?cvB^qWOb_iuLDv8m)u)WPZrf;U*@ z3MC{lrdIz~W-QYJ-k;Yibe)JW|q&5(_d4 za~Pyuihd<49gt;W1leOgc{l4+M!(5{Y$c55laH~vGXrCAvH-g&C)hx}lJu&{f$Y - - - + + + - +
Loading...
diff --git a/src/graphql/schema.ts b/src/graphql/schema.ts index 9cd41f5..0b8efda 100644 --- a/src/graphql/schema.ts +++ b/src/graphql/schema.ts @@ -1,6 +1,10 @@ -import type { Json } from '#/types' -import { buildClientSchema, printSchema, getIntrospectionQuery } from 'graphql' -import type { IntrospectionOptions } from 'graphql' +import { + printSchema, + buildClientSchema, + getIntrospectionQuery, + type IntrospectionOptions, +} from 'graphql' +import type { Json } from '#/types.ts' export function jsonSchemaToSDL(jsonString: string) { const json = JSON.parse(jsonString) @@ -8,11 +12,17 @@ export function jsonSchemaToSDL(jsonString: string) { return printSchema(schema) } -export async function fetchJsonSchema({ url, minimal = true }: { url: string; minimal?: boolean }): Promise { +export async function fetchJsonSchema({ + url, + minimal = true, +}: { + url: string + minimal?: boolean +}): Promise { const introspectionOptions = { descriptions: !minimal, directiveIsRepeatable: !minimal, - schemaDescription: !minimal + schemaDescription: !minimal, } satisfies IntrospectionOptions try { const response = await fetch(url, { @@ -20,8 +30,8 @@ export async function fetchJsonSchema({ url, minimal = true }: { url: string; mi headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ query: getIntrospectionQuery(introspectionOptions), - variable: {} - }) + variable: {}, + }), }) if (!response.ok) throw new Error(`Failed to fetch from ${url}: ${response.statusText}`) diff --git a/src/index.ts b/src/index.ts index 55afe4e..959187e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ -import { fetchJsonSchema, jsonSchemaToSDL } from '#/graphql/schema' -import { isURL, formatMessages, LANDING_MESSAGE } from '#/utilities' +import { fetchJsonSchema, jsonSchemaToSDL } from '#/graphql/schema.ts' +import { isURL, formatMessages, LANDING_MESSAGE } from '#/utilities.ts' /** * Route Options @@ -27,11 +27,11 @@ export async function handler(request: Request): Promise { ) } - if (requestedFormat === 'playground') { - const { htmlPage } = await import('#/graphql/graphiql.html') + if (['playground', 'graphiql'].includes(requestedFormat)) { + const { htmlPage } = await import('#/graphql/graphiql.html.ts') return new Response(htmlPage({ endpoint: introspectionURL }), { status: 200, - headers: { 'Content-Type': 'text/html' } + headers: { 'Content-Type': 'text/html' }, }) } @@ -42,20 +42,24 @@ export async function handler(request: Request): Promise { return new Response(sdlSchema, { status: sdlSchema.startsWith('Encountered an error') ? 400 : 200, - headers: { 'Content-Type': 'text/plain' } + headers: { 'Content-Type': 'text/plain' }, }) } return new Response(JSON.stringify(jsonSchema), { status: 200, - headers: { 'Content-Type': 'application/json' } + headers: { 'Content-Type': 'application/json' }, }) } catch (error) { const message = error instanceof Error ? error.message : `Encountered an error: ${error}` console.error(message) return new Response( - formatMessages(message, 'The introspection URL should be the URL of a GraphQL endpoint.', LANDING_MESSAGE), + formatMessages( + message, + 'The introspection URL should be the URL of a GraphQL endpoint.', + LANDING_MESSAGE + ), { status: 500, headers: { 'Content-Type': 'text/plain' } } ) } diff --git a/tsconfig.json b/tsconfig.json index 2a830f9..071ded8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,17 +2,18 @@ "compilerOptions": { "module": "ESNext", "target": "ESNext", + "noEmit": true, "sourceMap": false, "skipLibCheck": true, "resolveJsonModule": true, "verbatimModuleSyntax": true, - "moduleResolution": "bundler", + "moduleResolution": "Bundler", "noUncheckedIndexedAccess": true, "allowImportingTsExtensions": true, "allowSyntheticDefaultImports": true, "lib": ["ESNext", "DOM", "DOM.Iterable"], "noPropertyAccessFromIndexSignature": true, - "types": ["node", "bun-types"], + "types": ["bun-types"], "paths": { "#/*": ["./src/*"] }