Skip to content

Commit d295796

Browse files
committed
update deps & support 'graphiql' endpoint
1 parent 98d165c commit d295796

File tree

8 files changed

+51
-47
lines changed

8 files changed

+51
-47
lines changed

.github/workflows/ci.yml renamed to .github/workflows/deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Deploy
22

33
on:
44
workflow_dispatch:
@@ -21,11 +21,11 @@ env:
2121
jobs:
2222
deploy:
2323
name: "Deploy"
24-
timeout-minutes: 3.69
24+
timeout-minutes: 2
2525
runs-on: ["ubuntu-latest"]
2626
steps:
2727
- name: "Checkout"
28-
uses: actions/checkout@v3
28+
uses: actions/checkout@v4.1.1
2929

3030
- name: "Setup Bun"
3131
uses: oven-sh/setup-bun@v1

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ or get the `SDL`
4646

4747
[`https://introspect.lagon.dev/sdl/https://spacex-production.up.railway.app`](https://introspect.lagon.dev/sdl/https://spacex-production.up.railway.app)
4848

49-
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)
49+
or play around with it in a live playground
50+
51+
[`https://introspect.lagon.dev/playground/https://spacex-production.up.railway.app`](https://introspect.lagon.dev/playground/https://spacex-production.up.railway.app)
5052

5153
By default API will return schema as `JSON`
5254

bun.lockb

1 Byte
Binary file not shown.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
"deploy": "lagon deploy --production"
1313
},
1414
"dependencies": {
15-
"graphql": "^16.7.1"
15+
"graphql": "^16.8.1"
1616
},
1717
"devDependencies": {
18-
"bun-types": "^0.7.1",
19-
"typescript": "^5.1.6"
18+
"bun-types": "^1.0.13",
19+
"typescript": "^5.2.2"
2020
},
2121
"license": "GPL-3.0-or-later",
2222
"keywords": [

src/graphql/graphiql.html.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,35 @@ export function htmlPage({ endpoint }: { endpoint: string }) {
1919
width: 100%;
2020
overflow: hidden;
2121
}
22-
2322
#graphiql {
2423
height: 100vh;
2524
}
2625
</style>
27-
<script
28-
crossorigin
29-
src="https://unpkg.com/react/umd/react.development.js"
30-
></script>
31-
<script
32-
crossorigin
33-
src="https://unpkg.com/react-dom/umd/react-dom.development.js"
34-
></script>
35-
<script
36-
src="https://unpkg.com/graphiql/graphiql.min.js"
37-
type="application/javascript"
38-
></script>
26+
<script crossorigin src="https://unpkg.com/react/umd/react.development.js"></script>
27+
<script crossorigin src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>
28+
<script src="https://unpkg.com/graphiql/graphiql.min.js" type="application/javascript"></script>
3929
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
4030
<script
4131
src="https://unpkg.com/@graphiql/plugin-explorer/dist/index.umd.js"
4232
crossorigin
4333
></script>
44-
<link
45-
rel="stylesheet"
46-
href="https://unpkg.com/@graphiql/plugin-explorer/dist/style.css"
47-
/>
34+
<link rel="stylesheet" href="https://unpkg.com/@graphiql/plugin-explorer/dist/style.css" />
4835
</head>
4936
<body>
5037
<div id="graphiql">Loading...</div>
5138
<script>
52-
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
39+
const root = ReactDOM.createRoot(document.getElementById('graphiql'))
5340
const fetcher = GraphiQL.createFetcher({
54-
url: "${endpoint}",
55-
});
56-
const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin();
41+
url: '${endpoint}',
42+
})
43+
const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin()
5744
root.render(
5845
React.createElement(GraphiQL, {
5946
fetcher,
6047
defaultEditorToolsVisibility: true,
6148
plugins: [explorerPlugin],
62-
}),
63-
);
49+
})
50+
)
6451
</script>
6552
</body>
6653
</html>

src/graphql/schema.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
import type { Json } from '#/types'
2-
import { buildClientSchema, printSchema, getIntrospectionQuery } from 'graphql'
3-
import type { IntrospectionOptions } from 'graphql'
1+
import {
2+
printSchema,
3+
buildClientSchema,
4+
getIntrospectionQuery,
5+
type IntrospectionOptions,
6+
} from 'graphql'
7+
import type { Json } from '#/types.ts'
48

59
export function jsonSchemaToSDL(jsonString: string) {
610
const json = JSON.parse(jsonString)
711
const schema = buildClientSchema(json.data)
812
return printSchema(schema)
913
}
1014

11-
export async function fetchJsonSchema({ url, minimal = true }: { url: string; minimal?: boolean }): Promise<Json> {
15+
export async function fetchJsonSchema({
16+
url,
17+
minimal = true,
18+
}: {
19+
url: string
20+
minimal?: boolean
21+
}): Promise<Json> {
1222
const introspectionOptions = {
1323
descriptions: !minimal,
1424
directiveIsRepeatable: !minimal,
15-
schemaDescription: !minimal
25+
schemaDescription: !minimal,
1626
} satisfies IntrospectionOptions
1727
try {
1828
const response = await fetch(url, {
1929
method: 'POST',
2030
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
2131
body: JSON.stringify({
2232
query: getIntrospectionQuery(introspectionOptions),
23-
variable: {}
24-
})
33+
variable: {},
34+
}),
2535
})
2636

2737
if (!response.ok) throw new Error(`Failed to fetch from ${url}: ${response.statusText}`)

src/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { fetchJsonSchema, jsonSchemaToSDL } from '#/graphql/schema'
2-
import { isURL, formatMessages, LANDING_MESSAGE } from '#/utilities'
1+
import { fetchJsonSchema, jsonSchemaToSDL } from '#/graphql/schema.ts'
2+
import { isURL, formatMessages, LANDING_MESSAGE } from '#/utilities.ts'
33

44
/**
55
* Route Options
@@ -27,11 +27,11 @@ export async function handler(request: Request): Promise<Response> {
2727
)
2828
}
2929

30-
if (requestedFormat === 'playground') {
31-
const { htmlPage } = await import('#/graphql/graphiql.html')
30+
if (['playground', 'graphiql'].includes(requestedFormat)) {
31+
const { htmlPage } = await import('#/graphql/graphiql.html.ts')
3232
return new Response(htmlPage({ endpoint: introspectionURL }), {
3333
status: 200,
34-
headers: { 'Content-Type': 'text/html' }
34+
headers: { 'Content-Type': 'text/html' },
3535
})
3636
}
3737

@@ -42,20 +42,24 @@ export async function handler(request: Request): Promise<Response> {
4242

4343
return new Response(sdlSchema, {
4444
status: sdlSchema.startsWith('Encountered an error') ? 400 : 200,
45-
headers: { 'Content-Type': 'text/plain' }
45+
headers: { 'Content-Type': 'text/plain' },
4646
})
4747
}
4848

4949
return new Response(JSON.stringify(jsonSchema), {
5050
status: 200,
51-
headers: { 'Content-Type': 'application/json' }
51+
headers: { 'Content-Type': 'application/json' },
5252
})
5353
} catch (error) {
5454
const message = error instanceof Error ? error.message : `Encountered an error: ${error}`
5555
console.error(message)
5656

5757
return new Response(
58-
formatMessages(message, 'The introspection URL should be the URL of a GraphQL endpoint.', LANDING_MESSAGE),
58+
formatMessages(
59+
message,
60+
'The introspection URL should be the URL of a GraphQL endpoint.',
61+
LANDING_MESSAGE
62+
),
5963
{ status: 500, headers: { 'Content-Type': 'text/plain' } }
6064
)
6165
}

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
"compilerOptions": {
33
"module": "ESNext",
44
"target": "ESNext",
5+
"noEmit": true,
56
"sourceMap": false,
67
"skipLibCheck": true,
78
"resolveJsonModule": true,
89
"verbatimModuleSyntax": true,
9-
"moduleResolution": "bundler",
10+
"moduleResolution": "Bundler",
1011
"noUncheckedIndexedAccess": true,
1112
"allowImportingTsExtensions": true,
1213
"allowSyntheticDefaultImports": true,
1314
"lib": ["ESNext", "DOM", "DOM.Iterable"],
1415
"noPropertyAccessFromIndexSignature": true,
15-
"types": ["node", "bun-types"],
16+
"types": ["bun-types"],
1617
"paths": {
1718
"#/*": ["./src/*"]
1819
}

0 commit comments

Comments
 (0)