Skip to content

Commit a84e896

Browse files
committed
feat: stringify
1 parent bb4eb70 commit a84e896

File tree

10 files changed

+98
-14175
lines changed

10 files changed

+98
-14175
lines changed

Diff for: example/pages/schema/[...type].tsx

+41-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { schemaParser } from "../../../lib/index.js";
22
import { cwd } from "node:process";
33
import Link from "next/link";
4+
import { TypeNameMetaFieldDef } from "graphql";
45

56
// Initialize the schema parser reading from disk
67
const t = new schemaParser(`${cwd()}/schema/schema.graphql`);
@@ -30,13 +31,48 @@ export default function Type({ typeInfo }) {
3031
);
3132
};
3233

34+
const fields = () => {
35+
// const fields: object = Object.keys(typeInfo?.fields);
36+
37+
// Object.entries(typeInfo?.fields).forEach((entry) => {
38+
// const [key, value] = entry;
39+
// console.log(value.name, value.description);
40+
// });
41+
42+
let rows = [];
43+
44+
Object.values(typeInfo?.fields).forEach((o) =>
45+
rows.push(
46+
<tr key={o.name}>
47+
<td>{o.name}</td>
48+
<td>{o.description}</td>
49+
</tr>
50+
)
51+
);
52+
53+
return (
54+
<>
55+
<table className="gap-16 table-auto">
56+
<thead>
57+
<tr>
58+
<th>Name</th>
59+
<th>Description</th>
60+
</tr>
61+
</thead>
62+
<tbody>{rows}</tbody>
63+
</table>
64+
</>
65+
);
66+
};
67+
3368
return (
3469
<>
35-
<div className="container grid h-screen grid-cols-2 p-16 text-gray-900">
36-
<div className="w-1/4">{sidebar()}</div>
37-
<div>
70+
<div className="container grid h-screen grid-flow-col col-auto p-16 text-gray-900 bg-white">
71+
<div className="">{sidebar()}</div>
72+
<div className="">
3873
<div className="text-3xl font-bold text-center">{typeInfo?.name}</div>
3974
<div className="my-8 text-justify">{typeInfo?.description}</div>
75+
<div>{fields()}</div>
4076
</div>
4177
</div>
4278
</>
@@ -46,9 +82,10 @@ export default function Type({ typeInfo }) {
4682
export async function getStaticProps(context) {
4783
const { type } = context.params;
4884
const sidebar = t.getSidebar("schema");
85+
//FIXME: the magic number sucks
4986
const typeName = t.getTypename(type[1]);
5087

51-
console.log(typeName);
88+
// console.log(typeName);
5289

5390
return {
5491
props: {

Diff for: package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"prettier": "^2.8.3",
5959
"prettier-plugin-packagejson": "^2.4.2",
6060
"rimraf": "^5.0.0",
61+
"safe-stable-stringify": "^2.4.3",
6162
"stringify-object": "^5.0.0",
6263
"ts-node": "^10.9.1",
6364
"typescript": "^4.9.0"

Diff for: schema/schema.graphql

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type Author {
33
"The internal identifier of the author."
44
id: ID! # the ! means that every author object _must_ have an id
55
"The first name of the author. It might not be the legal name. It's just a name mate...."
6-
firstName: String @deprecated(reason:"this is bad")
6+
firstName: String @deprecated(reason: "this is bad")
77
"The last name of the author. It might be everything as we do not run Know Your Author."
88
lastName: String
99
"""
@@ -13,7 +13,7 @@ type Author {
1313
}
1414

1515
"A blog post or something else like carbonara recipe."
16-
type Post {
16+
type Post implements Stuff {
1717
"The internal identifier we love to leak outside."
1818
id: ID!
1919
"The title of the post. There's no limit to the title, so possible the whole post content can be in the title."
@@ -29,6 +29,8 @@ type Post {
2929
type Query {
3030
"Fetch all posts without any arguments. Default order is funky."
3131
posts: [Post]
32+
"Search everything"
33+
search: [Result]
3234
}
3335

3436
# this schema allows the following mutation:
@@ -44,3 +46,12 @@ schema {
4446
query: Query
4547
mutation: Mutation
4648
}
49+
50+
"A result"
51+
union Result = Author | Post
52+
53+
"A superset of everything"
54+
interface Stuff {
55+
"The identifier of anything"
56+
id: ID!
57+
}

0 commit comments

Comments
 (0)