Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Send response to thunk with request
Browse files Browse the repository at this point in the history
  • Loading branch information
calebmer committed May 1, 2016
1 parent 8eba52f commit d647019
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,28 @@ describe('test harness', () => {
});
});

it('will send request and response when using thunk', async () => {
const app = express();

let hasRequest = false;
let hasResponse = false;

app.use(urlString(), graphqlHTTP((req, res) => {
if (req) {
hasRequest = true;
}
if (res) {
hasResponse = true;
}
return { schema: TestSchema };
}));

await request(app).get(urlString({ query: '{test}' }));

expect(hasRequest).to.equal(true);
expect(hasResponse).to.equal(true);
});

describe('Error handling functionality', () => {
it('handles field errors caught by GraphQL', async () => {
const app = express();
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ export default function graphqlHTTP(options: Options): Middleware {

// Resolve the Options to get OptionsData.
new Promise(resolve => {
resolve(typeof options === 'function' ? options(request) : options);
resolve(
typeof options === 'function' ?
options(request, response) :
options
);
}).then(optionsData => {
// Assert that optionsData is in fact an Object.
if (!optionsData || typeof optionsData !== 'object') {
Expand Down

0 comments on commit d647019

Please sign in to comment.