graphql-query-generator
Advanced tools
Comparing version 0.3.1 to 0.4.0
#!/usr/bin/env node | ||
const graphQlClient = require('../lib/graphqlClient'); | ||
const chalk = require('chalk'); | ||
const retry = require('../lib/cli/retryHelper').retry; | ||
process.title = 'gql-query-generator'; | ||
var program = require('commander'); | ||
let program = require('commander'); | ||
@@ -18,2 +19,4 @@ let serverUrl = null; | ||
.option('-p, --parallel', 'Executes all queries in parallel') | ||
.option('-r, --retryCount <n>', 'Number of times to retry the query generator if it fails', parseInt) | ||
.option('-t, --retrySnoozeTime <n>', 'Time in milliseconds to wait before retries', parseInt) | ||
.parse(process.argv); | ||
@@ -34,4 +37,6 @@ | ||
let passedTests = 0; | ||
let retryCount = program.retryCount || 0; | ||
let retrySnoozeTime = program.retrySnoozeTime || 1000; | ||
queryGenerator.run() | ||
retry(() => queryGenerator.run(), retryCount, retrySnoozeTime) | ||
.then(queries => { | ||
@@ -81,3 +86,2 @@ console.log(`Fetched ${queries.length} queries, get to work!`); | ||
function maybeSerialisePromises(promises) { | ||
@@ -84,0 +88,0 @@ if(program.parallel) { |
@@ -115,9 +115,11 @@ const _ = require('lodash'); | ||
* @example | ||
* getSkipKey({ name: 'TypeName' }, { name: 'FieldName' }) // => 'FieldName-TypeName' | ||
* getSkipKey({ name: 'TypeName' }, { name: 'FieldName' }, { name: 'ParentTypeName' }) // => 'FieldName-TypeName-ParentTypeName' | ||
* getSkipKey({ name: 'TypeName' }, { name: 'FieldName' }, null) // => 'FieldName-TypeName-ROOT' | ||
*/ | ||
function getSkipKey(fieldTypeDefinition, field) { | ||
return `${field.name}-${fieldTypeDefinition.name}`; | ||
function getSkipKey(fieldTypeDefinition, field, parentFieldTypeDefinition) { | ||
const parentFieldTypeName = parentFieldTypeDefinition ? parentFieldTypeDefinition.name : 'ROOT'; | ||
return `${field.name}-${fieldTypeDefinition.name}-${parentFieldTypeName}`; | ||
} | ||
module.exports = function buildQueryTreeFromField(field, typeDictionary, skipped = []) { | ||
module.exports = function buildQueryTreeFromField(field, typeDictionary, skipped = [], parentFieldTypeDefinition = null) { | ||
const fieldTypeName = magiclyExtractFieldTypeName(field); | ||
@@ -137,3 +139,3 @@ const fieldTypeDefinition = typeDictionary[fieldTypeName]; | ||
if (fieldTypeDefinition.kind === 'OBJECT') { | ||
skipped.push(getSkipKey(fieldTypeDefinition, field)); | ||
skipped.push(getSkipKey(fieldTypeDefinition, field, parentFieldTypeDefinition)); | ||
} | ||
@@ -148,7 +150,7 @@ | ||
if (skipped.indexOf(getSkipKey(childFieldType, childField)) === -1) { | ||
if (skipped.indexOf(getSkipKey(childFieldType, childField, fieldTypeDefinition)) === -1) { | ||
queriesForRootField.forEach((rootFieldQuery) => { | ||
queryNode = queryNode || {}; | ||
queryNode[rootFieldQuery] = queryNode[rootFieldQuery] || []; | ||
queryNode[rootFieldQuery].push(buildQueryTreeFromField(childField, typeDictionary, skipped)); | ||
queryNode[rootFieldQuery].push(buildQueryTreeFromField(childField, typeDictionary, skipped, fieldTypeDefinition)); | ||
}); | ||
@@ -155,0 +157,0 @@ } |
{ | ||
"name": "graphql-query-generator", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Generates queries from the GraphQL endpoint via schema introspection.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -37,2 +37,17 @@ const should = require('chai').should(); | ||
] | ||
}, | ||
DeeplyNestedObject2: { | ||
name: 'DeeplyNestedObject2', | ||
kind: 'OBJECT', | ||
fields: [ | ||
{ name: 'DeepNest', type: { name: 'DeeplyNestedObject' }, args: [] } | ||
] | ||
}, | ||
ObjectContainingTwoDeeplyNestedObjects: { | ||
name: 'ObjectContainingTwoDeeplyNestedObjects', | ||
kind: 'OBJECT', | ||
fields: [ | ||
{ name: 'DeepNest', type: { name: 'DeeplyNestedObject' }, args: [] }, | ||
{ name: 'DeepNest2', type: { name: 'DeeplyNestedObject2' }, args: [] } | ||
] | ||
} | ||
@@ -68,3 +83,3 @@ }; | ||
ignoreList.length.should.equal(1); | ||
ignoreList[0].should.equal('MyObjectField-ObjectField'); | ||
ignoreList[0].should.equal('MyObjectField-ObjectField-ROOT'); | ||
}); | ||
@@ -88,4 +103,4 @@ | ||
ignoreList.length.should.equal(2); | ||
ignoreList[0].should.equal('MyObjectWithNested-ObjectNestingOtherObject'); | ||
ignoreList[1].should.equal('NestedObject-ObjectField'); | ||
ignoreList[0].should.equal('MyObjectWithNested-ObjectNestingOtherObject-ROOT'); | ||
ignoreList[1].should.equal('NestedObject-ObjectField-ObjectNestingOtherObject'); | ||
}); | ||
@@ -111,2 +126,18 @@ | ||
it('should handle very similar objects[test covering skipList naming bug]', () => { | ||
const ignoreList = []; | ||
const result = buildQueryTreeFromField({ | ||
type: { | ||
name: 'ObjectContainingTwoDeeplyNestedObjects' | ||
}, | ||
name: 'MyBug', | ||
args: [] | ||
}, | ||
typeDictionary, ignoreList | ||
); | ||
result.MyBug.length.should.equal(2); | ||
should.not.equal(result.MyBug[0], null); | ||
should.not.equal(result.MyBug[1], null); | ||
}); | ||
it('should not support default value for non nullable args[NOT IMPLEMENTED YET!]', () => { | ||
@@ -113,0 +144,0 @@ const arg = { |
66740
20
1745