aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-09-28 16:58:15 -0700
committerFuwn <[email protected]>2024-09-28 16:58:15 -0700
commit22b87a179af5ca7b148453c1a1a84c85d29f4c4a (patch)
tree01f754c6c18cad902fd3820494065d403ca8a565
parentfeat(api): set up graphql api (diff)
downloaddue.moe-22b87a179af5ca7b148453c1a1a84c85d29f4c4a.tar.xz
due.moe-22b87a179af5ca7b148453c1a1a84c85d29f4c4a.zip
feat(graphl): set up user module
-rw-r--r--src/graphql/hello/resolvers.ts10
-rw-r--r--src/graphql/hello/schema.graphql3
-rw-r--r--src/graphql/server.ts4
-rw-r--r--src/graphql/user/index.ts (renamed from src/graphql/hello/index.ts)0
-rw-r--r--src/graphql/user/resolvers.ts14
-rw-r--r--src/graphql/user/schema.graphql22
6 files changed, 38 insertions, 15 deletions
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<Resolvers> = {
- 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/hello/index.ts b/src/graphql/user/index.ts
index 925a7ece..925a7ece 100644
--- a/src/graphql/hello/index.ts
+++ b/src/graphql/user/index.ts
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<Resolvers> = {
+ 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
+}