From 802dcc9f5a4b2f0824e2600cd080d33691056d16 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 28 Sep 2024 16:40:08 -0700 Subject: feat(api): set up graphql api --- src/graphql/client.ts | 3 +++ src/graphql/hello/index.ts | 4 ++++ src/graphql/hello/resolvers.ts | 10 ++++++++++ src/graphql/hello/schema.graphql | 3 +++ src/graphql/server.ts | 7 +++++++ src/routes/graphql/+server.ts | 1 + 6 files changed, 28 insertions(+) create mode 100644 src/graphql/client.ts create mode 100644 src/graphql/hello/index.ts create mode 100644 src/graphql/hello/resolvers.ts create mode 100644 src/graphql/hello/schema.graphql create mode 100644 src/graphql/server.ts create mode 100644 src/routes/graphql/+server.ts (limited to 'src') diff --git a/src/graphql/client.ts b/src/graphql/client.ts new file mode 100644 index 00000000..367b8381 --- /dev/null +++ b/src/graphql/client.ts @@ -0,0 +1,3 @@ +import { HoudiniClient } from '$houdini'; + +export default new HoudiniClient({ url: '/graphql' }); diff --git a/src/graphql/hello/index.ts b/src/graphql/hello/index.ts new file mode 100644 index 00000000..925a7ece --- /dev/null +++ b/src/graphql/hello/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/hello/resolvers.ts b/src/graphql/hello/resolvers.ts new file mode 100644 index 00000000..f882765f --- /dev/null +++ b/src/graphql/hello/resolvers.ts @@ -0,0 +1,10 @@ +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 new file mode 100644 index 00000000..d3dba234 --- /dev/null +++ b/src/graphql/hello/schema.graphql @@ -0,0 +1,3 @@ +type Query { + hello: String! +} diff --git a/src/graphql/server.ts b/src/graphql/server.ts new file mode 100644 index 00000000..ad3ea146 --- /dev/null +++ b/src/graphql/server.ts @@ -0,0 +1,7 @@ +import { createSchema, createServer } from 'sveltekit-graphql'; +import helloModule from './hello'; + +const schema = createSchema([helloModule]); +const server = createServer(schema); + +export default server; diff --git a/src/routes/graphql/+server.ts b/src/routes/graphql/+server.ts new file mode 100644 index 00000000..f8e47dc5 --- /dev/null +++ b/src/routes/graphql/+server.ts @@ -0,0 +1 @@ +export { default as GET, default as POST, default as OPTIONS } from '$graphql/server'; -- cgit v1.2.3