-
Notifications
You must be signed in to change notification settings - Fork 1
/
nexus.ts
58 lines (50 loc) · 1.04 KB
/
nexus.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
49
50
51
52
53
54
55
56
57
58
import { objectType, makeSchema } from 'nexus';
import { ApolloServer } from 'apollo-server';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const Query = objectType({
name: 'Query',
definition(t) {
t.string('hello', {
resolve: () => 'hello chat!',
});
t.list.field('users', {
type: 'User',
resolve: async () => {
const users = await prisma.user.findMany();
return users;
},
});
},
});
const User = objectType({
name: 'User',
definition(t) {
t.int('id');
t.string('email');
t.string('name');
},
});
const schema = makeSchema({
types: [Query, User],
outputs: {
schema: __dirname + '/../schema.graphql',
typegen: __dirname + '/generated/nexus.ts',
},
sourceTypes: {
modules: [
{
module: '@prisma/client',
alias: 'prisma',
},
],
},
});
const server = new ApolloServer({
schema: schema,
});
server.listen().then(async ({ url }) => {
console.log(`\
🚀 Server ready at: ${url}
`);
});