-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var Hapi = require('hapi'); | ||
var graffiti = require('../'); | ||
var graffitiMongoose = require('@risingstack/graffiti-mongoose'); | ||
|
||
var server = new Hapi.Server(); | ||
server.connection({ port: 3000 }); | ||
|
||
server.register({ | ||
register: graffiti.hapi, | ||
options: { | ||
adapter: graffitiMongoose, | ||
models: [] | ||
} | ||
}, { | ||
routes: { | ||
prefix: '/graphql' | ||
} | ||
}, function (err) { | ||
if (err) { | ||
console.error('Failed to load plugin:', err); | ||
} | ||
|
||
server.start(function () { | ||
console.log('Server running at:', server.info.uri); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
var config = require('../config'); | ||
var checkDep = require('../util').checkDep; | ||
|
||
function isGet(request) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
function create() { | ||
var checkDep = require('../util').checkDep; | ||
var boom = require('boom'); | ||
|
||
return function hapi() { | ||
function create(options) { | ||
|
||
var graphql = checkDep(options, 'graphql'); | ||
|
||
var plugin = { | ||
register: function(server, options, next) { | ||
|
||
var models = checkDep(options, 'models'); | ||
var adapter = checkDep(options, 'adapter'); | ||
|
||
var schema = adapter.getSchema(models); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
handler: function(request, reply) { | ||
|
||
var query = request.query.q; | ||
|
||
return graphql(schema, query) | ||
.then(function(result) { | ||
reply(result); | ||
}) | ||
.catch(function(err) { | ||
reply(boom.badImplementation(err)); | ||
}); | ||
} | ||
}); | ||
|
||
next(); | ||
} | ||
}; | ||
|
||
plugin.register.attributes = { | ||
name: 'graffiti-hapi', | ||
version: '1.0.0' | ||
}; | ||
|
||
return plugin; | ||
} | ||
|
||
module.exports.create = create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
var config = require('../config'); | ||
var checkDep = require('../util').checkDep; | ||
|
||
function isGet(request) { | ||
|