-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyGraphQLSchema.js
39 lines (35 loc) · 1.13 KB
/
MyGraphQLSchema.js
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
const { GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');
const UserApiClient = require('./services/RandomUser/UserApiClient');
// sources:
// https://graphql.org/graphql-js/constructing-types/
// https://graphql.org/graphql-js/running-an-express-graphql-server/
// https://github.com/graphql/graphiql/
// https://graphql.org/learn/schema/#type-system
// https://medium.com/codingthesmartway-com-blog/creating-a-graphql-server-with-node-js-and-express-f6dddc5320e1
// https://blog.apollographql.com/graphql-vs-rest-5d425123e34b
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'world';
},
},
randomUser: {
type: GraphQLString,
resolve() {
const randomUserApi = UserApiClient.createInstance();
return randomUserApi.get()
.then((user) => {
return user.name;
})
.catch((err) => {
});
}
}
},
}),
});
module.exports = schema;