From 22b87a179af5ca7b148453c1a1a84c85d29f4c4a Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 28 Sep 2024 16:58:15 -0700 Subject: feat(graphl): set up user module --- src/graphql/hello/index.ts | 4 ---- src/graphql/hello/resolvers.ts | 10 ---------- src/graphql/hello/schema.graphql | 3 --- src/graphql/server.ts | 4 ++-- src/graphql/user/index.ts | 4 ++++ src/graphql/user/resolvers.ts | 14 ++++++++++++++ src/graphql/user/schema.graphql | 22 ++++++++++++++++++++++ 7 files changed, 42 insertions(+), 19 deletions(-) delete mode 100644 src/graphql/hello/index.ts delete mode 100644 src/graphql/hello/resolvers.ts delete mode 100644 src/graphql/hello/schema.graphql create mode 100644 src/graphql/user/index.ts create mode 100644 src/graphql/user/resolvers.ts create mode 100644 src/graphql/user/schema.graphql diff --git a/src/graphql/hello/index.ts b/src/graphql/hello/index.ts deleted file mode 100644 index 925a7ece..00000000 --- a/src/graphql/hello/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import typeDefs from './schema.graphql?raw'; -import { resolvers } from './resolvers'; - -export default { typeDefs, resolvers }; diff --git a/src/graphql/hello/resolvers.ts b/src/graphql/hello/resolvers.ts deleted file mode 100644 index f882765f..00000000 --- a/src/graphql/hello/resolvers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { WithIndex } from '../$types'; -import type { Resolvers } from './$types'; - -export const resolvers: WithIndex = { - Query: { - hello() { - return 'Hello SvelteKit!'; - } - } -}; diff --git a/src/graphql/hello/schema.graphql b/src/graphql/hello/schema.graphql deleted file mode 100644 index d3dba234..00000000 --- a/src/graphql/hello/schema.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type Query { - hello: String! -} diff --git a/src/graphql/server.ts b/src/graphql/server.ts index ad3ea146..2d74d878 100644 --- a/src/graphql/server.ts +++ b/src/graphql/server.ts @@ -1,7 +1,7 @@ import { createSchema, createServer } from 'sveltekit-graphql'; -import helloModule from './hello'; +import userModule from './user'; -const schema = createSchema([helloModule]); +const schema = createSchema([userModule]); const server = createServer(schema); export default server; diff --git a/src/graphql/user/index.ts b/src/graphql/user/index.ts new file mode 100644 index 00000000..925a7ece --- /dev/null +++ b/src/graphql/user/index.ts @@ -0,0 +1,4 @@ +import typeDefs from './schema.graphql?raw'; +import { resolvers } from './resolvers'; + +export default { typeDefs, resolvers }; diff --git a/src/graphql/user/resolvers.ts b/src/graphql/user/resolvers.ts new file mode 100644 index 00000000..a18358be --- /dev/null +++ b/src/graphql/user/resolvers.ts @@ -0,0 +1,14 @@ +import { getUserBadges } from '$lib/Database/SB/User/badges'; +import type { WithIndex } from '../$types'; +import type { Resolvers, Badge } from './$types'; + +export const resolvers: WithIndex = { + Query: { + User: async (_, args /* , _context */) => { + return { + id: args.id, + badges: await getUserBadges(args.id) as Badge[] + } + } + } +}; diff --git a/src/graphql/user/schema.graphql b/src/graphql/user/schema.graphql new file mode 100644 index 00000000..d4360a39 --- /dev/null +++ b/src/graphql/user/schema.graphql @@ -0,0 +1,22 @@ +type Query { + User(id: Int!): User +} + +type User { + id: Int! + badges: [Badge] +} + +type Badge { + post: String + image: String + description: String + id: Int + time: String + category: String + hidden: Boolean + source: String + designer: String + shadow_hidden: Boolean + click_count: Int +} -- cgit v1.2.3