Skip to content

Commit

Permalink
feat: make graphql work
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed May 18, 2024
1 parent c2bdd27 commit 31fa760
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 41 deletions.
3 changes: 2 additions & 1 deletion apps/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ node_modules
.output
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/dist
/dist
$houdini
9 changes: 9 additions & 0 deletions apps/frontend/.graphqlrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
projects:
default:
schema:
- ./schema.graphql
- ./$houdini/graphql/schema.graphql
documents:
- "**/*.gql"
- "**/*.svelte"
- ./$houdini/graphql/documents.gql
13 changes: 13 additions & 0 deletions apps/frontend/houdini.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <references types="houdini-svelte">

/** @type {import('houdini').ConfigFile} */
const config = {
watchSchema: {
url: "http://localhost:4000/graphql",
},
plugins: {
"houdini-svelte": {},
},
}

export default config
4 changes: 3 additions & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.3",
"vitest": "^1.2.0"
"vitest": "^1.2.0",
"houdini": "^1.2.47",
"houdini-svelte": "^1.2.47"
},
"type": "module",
"dependencies": {
Expand Down
10 changes: 10 additions & 0 deletions apps/frontend/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Query {
table(id: ID!): Table
tables: [Table]
}

type Table {
id: ID!
name: String!
recordsCount: Int!
}
15 changes: 15 additions & 0 deletions apps/frontend/src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HoudiniClient } from "$houdini"

export default new HoudiniClient({
url: "http://localhost:4000/graphql",

// uncomment this to configure the network call (for things like authentication)
// for more information, please visit here: https://www.houdinigraphql.com/guides/authentication
// fetchParams({ session }) {
// return {
// headers: {
// Authentication: `Bearer ${session.token}`,
// }
// }
// }
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index.js"
import * as Sheet from "$lib/components/ui/sheet/index.js"
import { Button } from "$lib/components/ui/button/index.js"
import { DatabaseIcon, HomeIcon, Package2 } from "lucide-svelte"
import { DatabaseIcon, Package2 } from "lucide-svelte"
import CreateTableButton from "../create-table/create-table-button.svelte"
import * as Breadcrumb from "$lib/components/ui/breadcrumb/index.js"
import { getTable } from "$lib/store/table.store"
Expand Down
7 changes: 7 additions & 0 deletions apps/frontend/src/routes/(authed)/+layout.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query Tables {
tables {
id
name
recordsCount
}
}
4 changes: 4 additions & 0 deletions apps/frontend/src/routes/(authed)/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TablesStore } from "$houdini"
import { trpc } from "$lib/trpc/client"
import { createTableCommand } from "@undb/commands"
import { createSchemaDTO } from "@undb/table"
Expand All @@ -12,6 +13,8 @@ export const load: LayoutLoad = async (event) => {
const tables = await trpc.table.list.query()
event.depends("undb:tables")

const s = await new TablesStore().fetch({ event })

const createTableForm = await superValidate(
zod(
// @ts-ignore
Expand All @@ -25,6 +28,7 @@ export const load: LayoutLoad = async (event) => {

return {
tables,
s,
createTableForm,
}
}
28 changes: 16 additions & 12 deletions apps/frontend/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import adapter from '@sveltejs/adapter-static';

import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import adapter from "@sveltejs/adapter-static"
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [vitePreprocess({})],
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),

kit: {
adapter: adapter({
pages: 'dist',
fallback: 'index.html'
})
}
};
kit: {
adapter: adapter({
pages: "dist",
fallback: "index.html",
}),
alias: {
$houdini: "./$houdini",
},
},
}

export default config;
export default config
27 changes: 14 additions & 13 deletions apps/frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": false,
"strict": true,
"noFallthroughCasesInSwitch": true,
"noEmit": true,
"moduleResolution": "bundler",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": false,
"strict": true,
"noFallthroughCasesInSwitch": true,
"noEmit": true,
"moduleResolution": "bundler",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"rootDirs": [".", "./.svelte-kit/types", "./$houdini/types", "./$houdini"]
}
}
2 changes: 2 additions & 0 deletions apps/frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { sveltekit } from "@sveltejs/kit/vite"
import houdini from "houdini/vite"
import { visualizer } from "rollup-plugin-visualizer"
import { defineConfig } from "vitest/config"

export default defineConfig({
plugins: [
houdini(),
sveltekit(),
visualizer({
emitFile: true,
Expand Down
Binary file modified bun.lockb
Binary file not shown.
10 changes: 7 additions & 3 deletions packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
"types": "src/index.d.ts",
"type": "module",
"devDependencies": {
"@undb/di": "workspace:*",
"@undb/cqrs": "workspace:*",
"@undb/queries": "workspace:*",
"@types/bun": "latest"
},
"peerDependencies": {
"@undb/di": "workspace:*",
"@undb/cqrs": "workspace:*",
"@undb/queries": "workspace:*",
"@elysiajs/graphql-yoga": "^1.0.3",
"typescript": "^5.0.0"
},
"dependencies": {
"graphql": "^16.8.1",
"graphql-yoga": "^5.3.1"
}
}
13 changes: 3 additions & 10 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { yoga } from "@elysiajs/graphql-yoga"
import { QueryBus } from "@undb/cqrs"
import { container, inject, singleton } from "@undb/di"
import { GetTableQuery, GetTablesQuery } from "@undb/queries"
import { createSchema } from "graphql-yoga"

@singleton()
export class Graphql {
Expand All @@ -11,8 +10,8 @@ export class Graphql {
public readonly queryBus: QueryBus,
) {}

createSchema() {
return createSchema({
public get yoga() {
return yoga({
typeDefs: `
type Table {
id: ID!
Expand All @@ -37,17 +36,11 @@ export class Graphql {
},
},
Table: {
recordsCount: () => 100,
recordsCount: (table) => 100,
},
},
})
}

public get yoga() {
return yoga({
schema: this.createSchema(),
})
}
}

export const graphql = () => container.resolve(Graphql)

0 comments on commit 31fa760

Please sign in to comment.