From f3b2b3c19f844737a22977658ab7c349c89c80e6 Mon Sep 17 00:00:00 2001 From: Peter Lyons Date: Mon, 10 Dec 2018 20:49:54 -0700 Subject: [PATCH] fix: ignore non-numeric default value for Float field Closes #49 --- src/ElasticApiParser.js | 5 +++++ src/__tests__/ElasticApiParser-test.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/ElasticApiParser.js b/src/ElasticApiParser.js index 6d461df..48eee15 100644 --- a/src/ElasticApiParser.js +++ b/src/ElasticApiParser.js @@ -323,6 +323,11 @@ 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; + } } else if (fieldName === 'format') { result.defaultValue = 'json'; } diff --git a/src/__tests__/ElasticApiParser-test.js b/src/__tests__/ElasticApiParser-test.js index 92a495a..6f5d9ff 100644 --- a/src/__tests__/ElasticApiParser-test.js +++ b/src/__tests__/ElasticApiParser-test.js @@ -377,6 +377,12 @@ describe('ElasticApiParser', () => { defaultValue: 'json', }); }); + + it('should ignore non-numeric default for float', () => { + expect( + parser.paramToGraphQLArgConfig({ type: 'number', default: 'ABC' }, 'someField') + ).not.toHaveProperty('defaultValue'); + }); }); describe('settingsToArgMap()', () => {