From 427cab28a7aabb3b67e91f3f308404c646751f50 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Sat, 18 May 2024 22:09:53 +0800 Subject: [PATCH] feat: graphql --- .graphqlrc.yaml | 9 ++++++ apps/frontend/.graphqlrc.yaml | 9 ------ apps/frontend/schema.graphql | 27 +++++++++++++++++ .../routes/(authed)/t/[tableId]/+layout.gql | 16 ++++++++++ .../routes/(authed)/t/[tableId]/+layout.ts | 2 ++ packages/graphql/src/index.ts | 29 +++++++++++++++++++ 6 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 .graphqlrc.yaml delete mode 100644 apps/frontend/.graphqlrc.yaml create mode 100644 apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql diff --git a/.graphqlrc.yaml b/.graphqlrc.yaml new file mode 100644 index 000000000..3f3a6eacf --- /dev/null +++ b/.graphqlrc.yaml @@ -0,0 +1,9 @@ +projects: + default: + schema: + - ./apps/frontend/schema.graphql + - ./apps/frontend/$houdini/graphql/schema.graphql + documents: + - "**/*.gql" + - "**/*.svelte" + - ./apps.frontend/$houdini/graphql/documents.gql diff --git a/apps/frontend/.graphqlrc.yaml b/apps/frontend/.graphqlrc.yaml deleted file mode 100644 index 3e18a301a..000000000 --- a/apps/frontend/.graphqlrc.yaml +++ /dev/null @@ -1,9 +0,0 @@ -projects: - default: - schema: - - ./schema.graphql - - ./$houdini/graphql/schema.graphql - documents: - - "**/*.gql" - - "**/*.svelte" - - ./$houdini/graphql/documents.gql diff --git a/apps/frontend/schema.graphql b/apps/frontend/schema.graphql index 80199df82..d7e5cf5ad 100644 --- a/apps/frontend/schema.graphql +++ b/apps/frontend/schema.graphql @@ -1,3 +1,18 @@ +type Field { + id: ID! + name: String! + type: FieldType! +} + +enum FieldType { + autoIncrement + createdAt + id + number + string + updatedAt +} + type Query { table(id: ID!): Table tables: [Table] @@ -7,4 +22,16 @@ type Table { id: ID! name: String! recordsCount: Int! + schema: [Field!]! + views: [View!]! +} + +type View { + id: ID! + name: String! + type: ViewType! +} + +enum ViewType { + grid } diff --git a/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql b/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql new file mode 100644 index 000000000..d41b4983e --- /dev/null +++ b/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql @@ -0,0 +1,16 @@ +query GetTableQuery($tableId: ID!) { + table(id: $tableId) { + id + name + schema { + id + name + type + } + views { + id + name + type + } + } +} diff --git a/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.ts b/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.ts index eb6ab09b0..bd059b6e9 100644 --- a/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.ts +++ b/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.ts @@ -1,3 +1,4 @@ +import { GetTableQueryStore } from "$houdini" import { trpc } from "$lib/trpc/client" import { tableCreator } from "@undb/table" import { superValidate } from "sveltekit-superforms" @@ -18,6 +19,7 @@ export const load: LayoutLoad = async (event) => { return { table, + t: await new GetTableQueryStore().fetch({ event, variables: { tableId } }), createRecord, } } diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index 9b6b2dda4..307c19c23 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -13,9 +13,36 @@ export class Graphql { public get yoga() { return yoga({ typeDefs: ` + enum FieldType { + string + number + id + createdAt + updatedAt + autoIncrement + } + + type Field { + id: ID! + name: String! + type: FieldType! + } + + enum ViewType { + grid + } + + type View { + id: ID! + name: String! + type: ViewType! + } + type Table { id: ID! name: String! + schema: [Field!]! + views: [View!]! recordsCount: Int! } @@ -36,9 +63,11 @@ export class Graphql { }, }, Table: { + // @ts-ignore recordsCount: (table) => 100, }, }, + batching: true, }) } }