Skip to content

Commit

Permalink
fix: ignore non-numeric default value for Float field
Browse files Browse the repository at this point in the history
Closes #49
  • Loading branch information
focusaurus authored and nodkz committed Dec 11, 2018
1 parent 5ee582d commit f3b2b3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ElasticApiParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/ElasticApiParser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit f3b2b3c

Please sign in to comment.