Skip to content

Commit 1f66f33

Browse files
committed
add graphql client
1 parent ebc0f3a commit 1f66f33

File tree

13 files changed

+467834
-148
lines changed

13 files changed

+467834
-148
lines changed

package-lock.json

Lines changed: 1599 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,10 @@
103103
},
104104
"volta": {
105105
"node": "22.9.0"
106+
},
107+
"dependencies": {
108+
"@graphiql/toolkit": "^0.11.1",
109+
"graphiql": "^3.8.3",
110+
"json-schema-to-typescript": "^15.0.3"
106111
}
107112
}

src/components/GraphiQLClient.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createGraphiQLFetcher } from "@graphiql/toolkit";
2+
import GraphiQL from "graphiql";
3+
import "graphiql/graphiql.css";
4+
import { useState } from "react";
5+
6+
const fetcher = createGraphiQLFetcher({
7+
url: "https://api.cloudflare.com/client/v4/graphql",
8+
});
9+
10+
export function GraphiQLClient({ schema }: { schema: any }) {
11+
const [authToken, setAuthToken] = useState("");
12+
return (
13+
<div className="flex h-screen flex-col">
14+
<div className="flex items-center gap-4 bg-gray-100 p-4">
15+
<label
16+
htmlFor="password"
17+
className="text-sm/6 font-medium text-gray-900"
18+
>
19+
Auth Token:
20+
</label>
21+
<div className="mt-2">
22+
<input
23+
id="password"
24+
name="password"
25+
type="password"
26+
onChange={(e) => setAuthToken(e.target.value)}
27+
className="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-orange-500 sm:text-sm/6"
28+
/>
29+
</div>
30+
</div>
31+
<div className="flex-1">
32+
<GraphiQL
33+
fetcher={fetcher}
34+
schema={schema}
35+
headers={JSON.stringify({
36+
authorization: `Bearer ${authToken}`,
37+
})}
38+
/>
39+
</div>
40+
</div>
41+
);
42+
}

src/components/models/SchemaRow.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { node, root } = Astro.props;
1212
node.title ? (
1313
<span class="mr-2 font-bold">{node.title}</span>
1414
) : (
15-
<code class="mr-2 !pr-0 font-mono rounded-md bg-gray-100">
15+
<code class="mr-2 rounded-md bg-gray-100 !pr-0 font-mono">
1616
{node.subpath[node.subpath.length - 1]}
1717
</code>
1818
)
@@ -46,7 +46,7 @@ const { node, root } = Astro.props;
4646

4747
{
4848
node.children && (
49-
<ul class="!list-none m-0 p-0 ml-4">
49+
<ul class="m-0 ml-4 !list-none p-0">
5050
{node.children.map((node: SchemaNode) => (
5151
<Astro.self node={node} />
5252
))}

src/content/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
videosSchema,
1414
workersAiSchema,
1515
changelogsNextSchema,
16+
graphQLSchema,
1617
} from "~/schemas";
1718

1819
const partialSchema = z.object({
@@ -78,4 +79,8 @@ export const collections = {
7879
"changelogs-next": defineCollection({
7980
schema: changelogsNextSchema,
8081
}),
82+
"graphql-api": defineCollection({
83+
schema: graphQLSchema,
84+
type: "data",
85+
}),
8186
};

0 commit comments

Comments
 (0)