Skip to content

Commit 0abe7a2

Browse files
committed
fix: ignore non-numeric default value for Float field (graphql-compose#49)
1 parent 5ee582d commit 0abe7a2

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/ElasticApiParser.js

Lines changed: 5 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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)