diff --git a/src/ElasticApiParser.js b/src/ElasticApiParser.js index 48eee15..c22f36b 100644 --- a/src/ElasticApiParser.js +++ b/src/ElasticApiParser.js @@ -323,10 +323,15 @@ export default class ElasticApiParser { if (paramCfg.default) { result.defaultValue = paramCfg.default; - // Handle broken data where default is not valid for the given type - // https://github.com/graphql-compose/graphql-compose-elasticsearch/issues/49 - if (result.type === 'Float' && Number.isNaN(Number(paramCfg.default))) { - delete result.defaultValue; + if (result.type === 'Float') { + const defaultNumber = Number(result.defaultValue); + if (Number.isNaN(defaultNumber)) { + // Handle broken data where default is not valid for the given type + // https://github.com/graphql-compose/graphql-compose-elasticsearch/issues/49 + delete result.defaultValue; + } else { + result.defaultValue = defaultNumber; + } } } else if (fieldName === 'format') { result.defaultValue = 'json'; diff --git a/src/__tests__/ElasticApiParser-test.js b/src/__tests__/ElasticApiParser-test.js index 6f5d9ff..469e928 100644 --- a/src/__tests__/ElasticApiParser-test.js +++ b/src/__tests__/ElasticApiParser-test.js @@ -383,6 +383,12 @@ describe('ElasticApiParser', () => { parser.paramToGraphQLArgConfig({ type: 'number', default: 'ABC' }, 'someField') ).not.toHaveProperty('defaultValue'); }); + + it('should accept numeric default for float', () => { + expect( + parser.paramToGraphQLArgConfig({ type: 'number', default: '4.2' }, 'someField') + ).toHaveProperty('defaultValue', 4.2); + }); }); describe('settingsToArgMap()', () => {