-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added graphi and graphql to project (part1).
* Implement example from graphi project. project: https://github.com/geek/graphi * Graphi options passed through confidence object * test coverage * sources: https://github.com/geek/graphi and http://graphql.org
- Loading branch information
Showing
6 changed files
with
139 additions
and
2 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
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,40 @@ | ||
'use strict'; | ||
|
||
const Graphi = require('graphi'); | ||
|
||
|
||
const schema = ` | ||
type Person { | ||
firstname: String! | ||
lastname: String! | ||
} | ||
type Query { | ||
person(firstname: String!): Person! | ||
} | ||
`; | ||
|
||
const getPerson = function (args, request) { | ||
|
||
return new Promise((resolve) => { | ||
|
||
resolve({ firstname: 'billy', lastname: 'jean' }); | ||
}); | ||
}; | ||
|
||
const resolvers = { | ||
person: getPerson | ||
}; | ||
|
||
|
||
exports.plugin = { | ||
name: 'graphi-registeration', | ||
version: '1.0.0', | ||
description: 'register graphi and build schema.', | ||
register: async function (server, options) { | ||
|
||
await server.register({ plugin: Graphi, options: { schema, resolvers, authStrategy: options.authStrategy, grahpiqlPath: options.grahpiqlPath } }); | ||
} | ||
}; | ||
|
||
// open https://localhost:8000/graphiql?query=%7B%20person(firstname%3A%20%22billy%22)%20%7B%20lastname%20%7D%20%7D&variables=%7B%7D | ||
// curl -k -X POST -H "Content-Type: application/json" -d '{"query":"{person(firstname:\"billy\"){lastname}}"}' https://127.0.0.1:8000/graphql |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('code'); | ||
const Lab = require('lab'); | ||
const { suite, test } = exports.lab = Lab.script(); | ||
|
||
|
||
suite('graphi development', () => { | ||
|
||
test('search returns last name', async () => { | ||
|
||
const University = require('../lib'); | ||
|
||
const server = await University.init('test'); | ||
|
||
expect(server).to.be.an.object(); | ||
|
||
const authenticateRequest = { method: 'POST', url: '/authenticate', payload: { username: 'foofoo', password: '12345678' } }; | ||
|
||
const authRes = await server.inject(authenticateRequest); | ||
|
||
expect(authRes.result.token.length).to.equal(36); | ||
|
||
const request = { method: 'POST', url: '/graphql', headers: { authorization: 'Bearer ' + authRes.result.token }, payload: { query:'{person(firstname:\"billy\"){lastname}}' } }; | ||
|
||
const res = await server.inject(request); | ||
|
||
expect(JSON.parse(res.payload)).to.equal({ | ||
'data': | ||
{ 'person': | ||
{ 'lastname': 'jean' } | ||
} | ||
}); | ||
|
||
await server.stop({ timeout: 4 }); | ||
}); | ||
}); |