forked from PoCInnovation/Workshops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.js
More file actions
executable file
·87 lines (75 loc) · 1.56 KB
/
Copy pathschema.js
File metadata and controls
executable file
·87 lines (75 loc) · 1.56 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { nexusPrismaPlugin } = require('nexus-prisma')
const { idArg, stringArg, makeSchema, objectType } = require('@nexus/schema')
const User = objectType({
name: 'User',
description: "User table",
definition(t) {
t.model.id()
t.model.name()
t.model.email()
t.model.posts({
pagination: false,
})
},
})
// todo:
// objectType of Post table
const Query = objectType({
name: 'Query',
definition(t) {
t.list.field('getUsers', {
type: 'User',
resolve: (parent, args, ctx) => {
return ctx.prisma.user.findMany()
},
})
// todo
// create the others field
},
})
const Mutation = objectType({
name: 'Mutation',
definition(t) {
t.field('signupUser', {
type: 'User',
args: {
email: stringArg({ nullable: false }),
name: stringArg({ nullable: false }),
},
resolve: (parent, { email, name }, ctx, info) => {
return ctx.prisma.user.create({
data: {
name,
email,
}
})
}
})
// todo
// create the others field
},
})
const schema = makeSchema({
types: [Post, User],
plugins: [nexusPrismaPlugin()],
outputs: {
schema: __dirname + '/../schema.graphql',
typegen: __dirname + '/generated/nexus.ts',
},
typegenAutoConfig: {
contextType: 'Context.Context',
sources: [
{
source: '@prisma/client',
alias: 'prisma',
},
{
source: require.resolve('./context'),
alias: 'Context',
},
],
},
})
module.exports = {
schema
}