Skip to content

Commit

Permalink
Add request options parameter, fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Dec 10, 2016
1 parent d89e466 commit 0782c01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ The "tester" function is used to create a function that can be used to test a sp
* method - The HTTP Method to use for the requests. This is optional, and will default to POST
* contentType - The Content Type Header to set for the requests. This is optional, and will default to "application/graphql"

This function will return a function that can be used to make requests to the API. This returned function takes a single parameter as being the GraphQL Query to execute, and will return a Promise for the response from the server. This Promise will be resolved with an Object containing:
This function will return a function that can be used to make requests to the API. This returned function takes:

* a GraphQL Query to execute
* an optional [request options Object](https://github.com/request/request#requestoptions-callback) that will add to and override the default options

It will return a Promise for the response from the server. This Promise will be resolved with an Object containing:
* success - True if the query was a success. False if not. Note that in this case Success means there was no "errors" element returned.
* status - The HTTP Status Code of the response received.
* headers - The HTTP Headers of the response received.
Expand Down
12 changes: 4 additions & 8 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function tester({
contentType = 'application/graphql',
authorization = null
}) {
return (query) => {
return (query, requestOptions) => {
return new Promise((resolve, reject) => {
if (server) {
freeport((err, port) => {
Expand All @@ -35,13 +35,9 @@ export function tester({
'Content-Type': contentType,
};
if (authorization !== null) headers['Authorization'] = authorization;

request({
method,
uri: url,
headers: headers,
body: query
}, (error, message, body) => {
let options = { method, uri: url, headers, body: query };
options = Object.assign(options, requestOptions);
request(options, (error, message, body) => {
if (server && typeof(server.shutdown) === 'function') {
server.shutdown();
}
Expand Down

0 comments on commit 0782c01

Please sign in to comment.