8000 Added GraphQL example · javascriptit/examples-1@2f6911e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f6911e

Browse files
committed
Added GraphQL example
1 parent 8114c49 commit 2f6911e

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

graphql/controllers/default.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.install = function() {
2+
3+
F.route('/api/hello', post_hello, ['post', 'raw']);
4+
5+
};
6+
7+
function post_hello() {
8+
var self = this;
9+
10+
MODEL('hello').query(self.body).then((response) => {
11+
self.json(response);
12+
});
13+
};

graphql/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ===================================================
2+
// FOR DEVELOPMENT
3+
// Total.js - framework for Node.js platform
4+
// https://www.totaljs.com
5+
// ===================================================
6+
7+
const options = {};
8+
9+
// options.ip = '127.0.0.1';
10+
// options.port = parseInt(process.argv[2]);
11+
// options.config = { name: 'Total.js' };
12+
// options.sleep = 3000;
13+
// options.inspector = 9229;
14+
// options.debugger = 40894;
15+
16+
require('total.js/debug')(options);

graphql/models/hello.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');
2+
3+
exports.id = 'hello';
4+
5+
exports.schema = new GraphQLSchema({
6+
query: new GraphQLObjectType({
7+
name: 'RootQueryType',
8+
fields: {
9+
hello: {
10+
type: GraphQLString,
11+
resolve() {
12+
return 'world';
13+
}
14+
}
15+
}
16+
})
17+
});
18+
19+
exports.root = { hello: () => 'Hello world!' };
20+
21+
exports.query = function query(q){
22+
23+
return graphql(exports.schema, q, exports.root);
24+
25+
};

0 commit comments

Comments
 (0)
0