-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemaDefs.js
More file actions
51 lines (47 loc) · 1.11 KB
/
schemaDefs.js
File metadata and controls
51 lines (47 loc) · 1.11 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
const { GraphQLID, GraphQLObjectType, GraphQLString } = require("graphql");
var db = [
{ id: "1", name: "Primeiro Usuario" },
{ id: "2", name: "Segundo Usuario" },
{ id: "3", name: "Terceiro Usuario" },
];
var UserType = new GraphQLObjectType({
name: "User",
fields: {
id: {
type: GraphQLID,
resolve: function (root, args, context, info) {
console.log("My custom resolver for ID");
return root.id;
},
},
name: {
type: GraphQLString,
resolve: function (root, args, context, info) {
console.log("My custom resolver for NAME");
return root.name;
},
},
},
});
let typeDef = new GraphQLObjectType({
name: "Query",
fields: {
user: {
type: UserType,
args: {
id: {
type: GraphQLID,
defaultValue: "1",
description: "Returns a user by ID value",
},
},
resolve: async function (root, args, context, info) {
let { id } = args;
return db.find(function (value) {
return value.id == id;
});
},
},
},
});
module.exports = typeDef;