Skip to content

Commit 5f82ccd

Browse files
committed
feat(ElasticApiParser): Set format="json" by default
1 parent 9963b9c commit 5f82ccd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/ElasticApiParser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ export default class ElasticApiParser {
222222
};
223223
if (paramCfg.default) {
224224
result.defaultValue = paramCfg.default;
225+
} else if(fieldName === 'format') {
226+
result.defaultValue = 'json';
225227
}
226228

227229
return result;

src/__tests__/ElasticApiParser-test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,26 +201,23 @@ describe('ElasticApiParser', () => {
201201
it('should convert to GraphQLEnumType', () => {
202202
const type = parser.getEnumType('f1', ['AND', 'OR']);
203203
expect(type).toBeInstanceOf(GraphQLEnumType);
204-
// $FlowFixMe
205204
expect(type._values[0]).toMatchObject({ name: 'AND', value: 'AND' });
206-
// $FlowFixMe
207205
expect(type._values[1]).toMatchObject({ name: 'OR', value: 'OR' });
208206
});
209207

210208
it("should convert '' to empty_string", () => {
211209
const type = parser.getEnumType('f1', ['']);
212210
expect(type).toBeInstanceOf(GraphQLEnumType);
213-
// $FlowFixMe
214211
expect(type._values[0]).toMatchObject({
215212
name: 'empty_string',
216213
value: '',
217214
});
218215
});
219216

220217
it('should convert 1 to number_1', () => {
218+
// $FlowFixMe
221219
const type = parser.getEnumType('f1', [1]);
222220
expect(type).toBeInstanceOf(GraphQLEnumType);
223-
// $FlowFixMe
224221
expect(type._values[0]).toMatchObject({ name: 'number_1', value: 1 });
225222
});
226223

@@ -263,6 +260,15 @@ describe('ElasticApiParser', () => {
263260
defaultValue: 'ABC',
264261
});
265262
});
263+
264+
it('should set defaultValue="json" for `format` argument', () => {
265+
expect(
266+
parser.paramToGraphQLArgConfig({ type: 'string' }, 'format')
267+
).toMatchObject({
268+
type: GraphQLString,
269+
defaultValue: 'json',
270+
});
271+
});
266272
});
267273

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

0 commit comments

Comments
 (0)