-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
36 lines (34 loc) · 1008 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { createServer } from "node:http";
import { createSchema, createYoga, YogaInitialContext } from "graphql-yoga";
import { useCookies } from "@whatwg-node/server-plugin-cookies";
const yoga = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
cookie(name: String!): String
}
type Mutation {
setCookie(name: String!, value: String!): String
}
`,
resolvers: {
Query: {
async cookie(root, args, ctx: YogaInitialContext) {
const cookie = await ctx.request.cookieStore?.get(args.name);
return cookie?.value;
}
},
Mutation: {
async setCookie(root, args, ctx: YogaInitialContext) {
await ctx.request.cookieStore?.set(args.name, args.value);
return args.value;
}
}
}
}),
plugins: [useCookies()]
});
const server = createServer(yoga);
server.listen(4000, () => {
console.log("Server is running on http://localhost:4000");
});