graphql-query-generator
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "graphql-query-generator", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Generates queries from the GraphQL endpoint via schema introspection.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -56,3 +56,3 @@ [![build](https://api.travis-ci.org/opentable/graphql-query-generator.svg?branch=master)](https://travis-ci.org/opentable/graphql-query-generator) | ||
const queryGenerator = new QueryGenerator(serverUrl); | ||
queries = queryGenerator.run(); | ||
queryPromise = queryGenerator.run(); | ||
}); | ||
@@ -63,4 +63,8 @@ | ||
return queries | ||
.then(queries => Promise.all(queries.map(query => requestToGraphQL(serverUrl, query)))) | ||
return queryPromise | ||
.then(({queries, coverage}) =>{ | ||
console.log(`Coverage: ${coverage.coverageRatio}`); | ||
console.log(`skipped fields: ${coverage.notCoveredFields}`); | ||
return Promise.all(queries.map(query => requestToGraphQL(serverUrl, query))); | ||
}) | ||
.then(results => assert.equal(results.filter(x => x.statusCode !== 200).length, 0)); | ||
@@ -67,0 +71,0 @@ }); |
54
test.js
@@ -1,5 +0,51 @@ | ||
var t = require('./testHelper'); | ||
// var t = require('./testHelper'); | ||
f1(2); | ||
// t.f1(2) // success | ||
// t.f2(2) // Error: f2 is not e function | ||
// f1(2); | ||
// // t.f1(2) // success | ||
// // t.f2(2) // Error: f2 is not e function | ||
const QueryGenerator = require('graphql-query-generator'); | ||
const request = require('request'); | ||
const assert = require('assert'); | ||
describe('Query generation', function() { | ||
const serverUrl = 'http://localhost:12345/graphql'; | ||
let queryPromise = null; | ||
before(() => { | ||
const queryGenerator = new QueryGenerator(serverUrl); | ||
queryPromise = queryGenerator.run(); | ||
}); | ||
it('Generates multiple queries', function() { | ||
this.timeout = 50000; | ||
return queryPromise | ||
.then(({queries, coverage}) =>{ | ||
console.log(`Coverage: ${coverage.coverageRatio}`); | ||
console.log(`skipped fields: ${coverage.notCoveredFields}`); | ||
return Promise.all(queries.map(query => requestToGraphQL(serverUrl, query))); | ||
}) | ||
.then(results => assert.equal(results.filter(x => x.statusCode !== 200).length, 0)); | ||
}); | ||
}); | ||
function requestToGraphQL(serverUrl, query) { | ||
return new Promise((resolve, reject) => { | ||
request(serverUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body:JSON.stringify({ | ||
"query": query, | ||
"variables": "{}", | ||
"operationName": null | ||
}) | ||
}, function (err, result) { | ||
if (err) return reject(err); | ||
resolve(result) | ||
}); | ||
}); | ||
} |
76686
1998
122