-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.js
More file actions
100 lines (91 loc) · 2.16 KB
/
Copy pathschema.js
File metadata and controls
100 lines (91 loc) · 2.16 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
88
89
90
91
92
93
94
95
96
97
98
99
100
const { makeExecutableSchema, addMockFunctionsToSchema } = require('graphql-tools')
const casual = require('casual')
const typeDefs = `
# Curso en el sistema
type Curso {
id: ID!
titulo: String!
# Descripcion del curso
descripcion: String!
profesor: Profesor
rating: Float @deprecated(reason: "porque si")
comentarios: [Comentario]
}
type Profesor {
id: ID!
nombre: String!
nacionalidad: String!
genero: Genero
cursos: [Curso]
}
enum Genero {
FEMENINO
MASCULINO
}
type Comentario {
id: ID!
nombre: String!
cuerpo: String!
}
type Query {
cursos: [Curso]
profesores: [Profesor]
curso(id: Int): Curso
profesor(id: Int): Profesor
}
`
const resolvers = {
Query: {
cursos: () => {
return [{
id: 1,
titulo: 'curso graphql',
descripcion: 'goku gohan',
profesor: {
nombre: 'pablo',
nacionalidad: 'usa'
},
comentarios: [{
nombre: 'picoro',
cuerpo: 'buena pelea'
}]
}, {
id: 2,
titulo: 'curso vue',
descripcion: 'proximo a este',
profesor: {
nombre: 'vegeta',
nacionalidad: 'saiyajin'
},
comentarios: [{
id: 2,
nombre: 'krilin',
cuerpo: 'master'
}]
}]
}
}
}
const schema = makeExecutableSchema({
typeDefs,
resolvers
})
addMockFunctionsToSchema({
schema,
mocks: {
Curso: () => {
return {
id: casual.uuid,
titulo: casual._title,
descripcion: casual.sentence
}
},
Profesor: () => {
return {
nombre: casual.name
}
}
},
preserveResolvers: false
})
module.exports = schema