-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.ts
48 lines (41 loc) · 1021 Bytes
/
schema.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
37
38
39
40
41
42
43
44
45
46
47
48
import { makeExecutableSchema } from "@graphql-tools/schema";
import { getUsers } from "../db/users.js";
const typeDefs = /* GraphQL */ `
type User {
id: ID!
firstName: String!
fullName: String!
lastName: String!
createdAt: String
}
# the schema allows the following query:
type Query {
users: [User]
hello(name: String): String
}
# this schema allows the following mutation:
type Mutation {
doSomething(something: String!): String
}
`;
const resolvers = {
Query: {
users: async () => {
const users = await getUsers();
return users;
},
hello: (_, args) => {
return `hello, ${args?.name || "World"}`;
},
},
Mutation: {
doSomething: (_, { something }) => {
return `${something} successful!`
},
},
User: {
fullName: (parent) => `${parent.firstName} ${parent.lastName}`,
createdAt: (parent) => parent.createdAt?.toISOString(),
},
};
export const schema = makeExecutableSchema({ typeDefs, resolvers });