Skip to content

Commit f3b2b3c

Browse files
focusaurusnodkz
authored andcommitted
fix: ignore non-numeric default value for Float field
Closes #49
1 parent 5ee582d commit f3b2b3c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/ElasticApiParser.js

+5
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ export default class ElasticApiParser {
323323

324324
if (paramCfg.default) {
325325
result.defaultValue = paramCfg.default;
326+
// Handle broken data where default is not valid for the given type
327+
// https://github.com/graphql-compose/graphql-compose-elasticsearch/issues/49
328+
if (result.type === 'Float' && Number.isNaN(Number(paramCfg.default))) {
329+
delete result.defaultValue;
330+
}
326331
} else if (fieldName === 'format') {
327332
result.defaultValue = 'json';
328333
}

src/__tests__/ElasticApiParser-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ describe('ElasticApiParser', () => {
377377
defaultValue: 'json',
378378
});
379379
});
380+
381+
it('should ignore non-numeric default for float', () => {
382+
expect(
383+
parser.paramToGraphQLArgConfig({ type: 'number', default: 'ABC' }, 'someField')
384+
).not.toHaveProperty('defaultValue');
385+
});
380386
});
381387

382388
describe('settingsToArgMap()', () => {

0 commit comments

Comments
 (0)