-
Notifications
You must be signed in to change notification settings - Fork 8
feat(typesync): initial TypeSync implementation #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e6f9da
feat(typesync): TypeSync implementation
cmwhited d2b8676
chore(deps): fix issues with out-of-date pnpm-lock.yaml
cmwhited c7ef174
chore(deps): linter issues
cmwhited 54603d8
chore(deps): test issues. use consistent version of react
cmwhited d06d56f
Merge branch 'main' of github.com:graphprotocol/hypergraph into chris…
cmwhited 2309baa
feat(typesync): PR updates. rebase on main. move to root .gitignore
cmwhited File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"recommendations": ["biomejs.biome"] | ||
"recommendations": ["biomejs.biome", "effectful-tech.effect-vscode"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
coverage/ | ||
*.tsbuildinfo | ||
node_modules/ | ||
yarn-error.log | ||
.ultra.cache.json | ||
.DS_Store | ||
tmp/ | ||
build/ | ||
dist/ | ||
.direnv/ | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
*.db* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024-present <PLACEHOLDER> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# @graphprotocol/typesync | ||
|
||
CLI toolchain to view existing types, select, pick, extend to create schemas and generate a @graphprotocol/hypergraph schema. | ||
|
||
The `@graphprotocol/typesync` cli works by spinning up a [hono](https://hono.dev/) nodejs server that exposes a built vitejs react app. This app will let users see their created app schemas as well as search existing types to create new app schemas. | ||
Once the user has a schema built in the app, they can then run codegen, which will send a message to the server to codegen the built schema using the `@graphprotocol/hypergraph` framework. | ||
|
||
## Running Code | ||
|
||
This template leverages [tsx](https://tsx.is) to allow execution of TypeScript files via NodeJS as if they were written in plain JavaScript. | ||
|
||
To execute a file with `tsx`: | ||
|
||
```sh | ||
pnpm run dev | ||
``` | ||
|
||
## Operations | ||
|
||
**Building** | ||
|
||
To build the package: | ||
|
||
```sh | ||
pnpm build | ||
``` | ||
|
||
**Testing** | ||
|
||
To test the package: | ||
|
||
```sh | ||
pnpm test | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html | ||
lang="en" | ||
class="h-full min-h-screen w-full p-0 m-0 dark:bg-slate-950 dark:text-white bg-white text-gray-950 font-mono" | ||
> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link | ||
rel="icon" | ||
type="image/png" | ||
sizes="64x64" | ||
href="https://storage.thegraph.com/favicons/64x64.png" | ||
/> | ||
<link | ||
rel="icon" | ||
type="image/png" | ||
sizes="256x256" | ||
href="https://storage.thegraph.com/favicons/256x256.png" | ||
/> | ||
<title>Graph Protocol | TypeSync</title> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
</head> | ||
<body class="h-full w-full"> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
120 changes: 120 additions & 0 deletions
120
apps/typesync/client/src/Components/App/SchemaBuilder/SchemaBrowser.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
'use client'; | ||
|
||
import { Disclosure, DisclosureButton, DisclosurePanel, Input } from '@headlessui/react'; | ||
import { ChevronDownIcon, PlusIcon } from '@heroicons/react/20/solid'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Array as EffectArray, Order, pipe } from 'effect'; | ||
import { useState } from 'react'; | ||
|
||
import type { SchemaBrowserTypesQuery } from '../../../generated/graphql'; | ||
import { schemaBrowserQueryOptions } from '../../../hooks/useSchemaBrowserQuery'; | ||
import { Loading } from '../../Loading'; | ||
|
||
export type SchemaBrowserType = NonNullable<SchemaBrowserTypesQuery['space']>['types'][number]; | ||
type ExtendedSchemaBrowserType = SchemaBrowserType & { slug: string }; | ||
|
||
const SchemaTypeOrder = Order.mapInput(Order.string, (type: SchemaBrowserType) => type.name || type.id); | ||
|
||
export type SchemaBrowserProps = Readonly<{ | ||
typeSelected(type: SchemaBrowserType): void; | ||
}>; | ||
export function SchemaBrowser(props: SchemaBrowserProps) { | ||
const [typeSearch, setTypeSearch] = useState(''); | ||
|
||
const { data: types, isLoading } = useQuery({ | ||
...schemaBrowserQueryOptions, | ||
select(data) { | ||
const types = data.space?.types ?? []; | ||
const mappedAndSorted = pipe( | ||
types, | ||
EffectArray.map((type) => { | ||
const slugifiedProps = EffectArray.reduce(type.properties, '', (slug, curr) => `${slug}${curr.name || ''}`); | ||
const slug = `${type.name || ''}${slugifiedProps}`.toLowerCase(); | ||
return { | ||
...type, | ||
slug, | ||
} as const satisfies ExtendedSchemaBrowserType; | ||
}), | ||
EffectArray.sort(SchemaTypeOrder), | ||
); | ||
if (!typeSearch) { | ||
return mappedAndSorted; | ||
} | ||
return pipe( | ||
mappedAndSorted, | ||
EffectArray.filter((type) => type.slug.includes(typeSearch.toLowerCase())), | ||
); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="flex flex-col gap-y-6"> | ||
<h3 className="text-sm/6 font-semibold text-gray-900 dark:text-white flex items-center gap-x-3"> | ||
Schema Browser | ||
{isLoading ? <Loading /> : null} | ||
</h3> | ||
<div className="bg-gray-100 dark:bg-slate-900 rounded-lg flex flex-col gap-y-3 pt-2"> | ||
<div className="px-3 mt-2"> | ||
<Input | ||
id="SchemaBrowserSearch" | ||
name="SchemaBrowserSearch" | ||
value={typeSearch} | ||
onChange={(e) => setTypeSearch(e.target.value || '')} | ||
type="search" | ||
placeholder="Search types..." | ||
className="block min-w-0 grow py-1.5 pl-2 pr-3 rounded-md bg-white dark:bg-slate-700 data-[state=invalid]:pr-10 text-base text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-gray-500 focus:outline sm:text-sm/6 focus-visible:outline-none w-full" | ||
/> | ||
</div> | ||
<ul className="px-4 divide-y divide-gray-100 dark:divide-gray-700 overflow-y-auto h-fit max-h-[500px] 2xl:max-h-[750px]"> | ||
{(types ?? []).map((_type) => ( | ||
<Disclosure as="li" key={_type.id} className="py-3 flex flex-col gap-y-2"> | ||
<div className="flex items-center justify-between gap-x-6"> | ||
<DisclosureButton | ||
as="div" | ||
disabled={_type.properties.length === 0} | ||
data-interactive={_type.properties.length > 0 ? 'clickable' : undefined} | ||
className="min-w-0 data-[interactive=clickable]:cursor-pointer" | ||
> | ||
<div className="flex items-center gap-x-2"> | ||
{_type.properties.length > 0 ? <ChevronDownIcon className="size-4" aria-hidden="true" /> : null} | ||
<p className="text-sm/6 font-semibold text-gray-900 dark:text-white">{_type.name || _type.id}</p> | ||
<p className="text-xs font-light text-gray-600 dark:text-gray-300 bg-gray-50 dark:bg-slate-600 ring-gray-500/10 rounded-md px-1.5 py-0.5 whitespace-nowrap ring-1 ring-inset"> | ||
{_type.id} | ||
</p> | ||
</div> | ||
</DisclosureButton> | ||
<div className="flex flex-none items-center justify-end"> | ||
<button | ||
type="button" | ||
className="rounded-md bg-white dark:bg-black p-2 cursor-pointer text-sm font-semibold text-gray-900 dark:text-white shadow-xs ring-1 ring-gray-300 dark:ring-black/15 ring-inset hover:bg-gray-50 dark:hover:bg-slate-950 inline-flex flex-col items-center justify-center" | ||
onClick={() => props.typeSelected(_type)} | ||
> | ||
<PlusIcon className="size-4" aria-hidden="true" /> | ||
</button> | ||
</div> | ||
</div> | ||
<DisclosurePanel | ||
as="div" | ||
transition | ||
className="w-full transition duration-200 ease-in-out py-1.5 flex flex-col gap-y-1" | ||
> | ||
<ul className="w-full pl-6 pr-3 divide-y divide-gray-300 dark:divide-gray-800"> | ||
{_type.properties.map((prop) => ( | ||
<li key={prop.id} className="w-full text-xs py-1.5 flex items-center gap-x-2 list-disc"> | ||
{prop.name || prop.id} | ||
{prop.valueType?.name != null ? ( | ||
<p className="text-xs font-light text-gray-600 dark:text-gray-300 bg-gray-50 dark:bg-slate-700 ring-gray-500/10 dark:ring-gray-700/10 rounded-md px-1.5 py-0.5 whitespace-nowrap ring-1 ring-inset"> | ||
{prop.valueType.name} | ||
</p> | ||
) : null} | ||
</li> | ||
))} | ||
</ul> | ||
</DisclosurePanel> | ||
</Disclosure> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit pick: @fubhy cleaned up the repo once and moved all gitignore entries to the root gitignore. Can you do the same with this one? (not sure if there is even anything here we are not already covering in the root gitignore)