| 360 | |}; |
| 361 | |
| 362 | class InputArgView extends React.PureComponent<InputArgViewProps, {}> { |
| 363 | _previousArgSelection: ?ObjectFieldNode; |
| 364 | _getArgSelection = () => { |
| 365 | return this.props.selection.fields.find( |
| 366 | field => field.name.value === this.props.arg.name, |
| 367 | ); |
| 368 | }; |
| 369 | |
| 370 | _removeArg = () => { |
| 371 | const {selection} = this.props; |
| 372 | const argSelection = this._getArgSelection(); |
| 373 | this._previousArgSelection = argSelection; |
| 374 | this.props.modifyFields( |
| 375 | selection.fields.filter(field => field !== argSelection), |
| 376 | true, |
| 377 | ); |
| 378 | }; |
| 379 | |
| 380 | _addArg = () => { |
| 381 | const { |
| 382 | selection, |
| 383 | arg, |
| 384 | getDefaultScalarArgValue, |
| 385 | parentField, |
| 386 | makeDefaultArg, |
| 387 | } = this.props; |
| 388 | const argType = unwrapInputType(arg.type); |
| 389 | |
| 390 | let argSelection = null; |
| 391 | if (this._previousArgSelection) { |
| 392 | argSelection = this._previousArgSelection; |
| 393 | } else if (isInputObjectType(argType)) { |
| 394 | const fields = argType.getFields(); |
| 395 | argSelection = { |
| 396 | kind: 'ObjectField', |
| 397 | name: {kind: 'Name', value: arg.name}, |
| 398 | value: { |
| 399 | kind: 'ObjectValue', |
| 400 | fields: defaultInputObjectFields( |
| 401 | getDefaultScalarArgValue, |
| 402 | makeDefaultArg, |
| 403 | parentField, |
| 404 | Object.keys(fields).map(k => fields[k]), |
| 405 | ), |
| 406 | }, |
| 407 | }; |
| 408 | } else if (isLeafType(argType)) { |
| 409 | argSelection = { |
| 410 | kind: 'ObjectField', |
| 411 | name: {kind: 'Name', value: arg.name}, |
| 412 | value: getDefaultScalarArgValue(parentField, arg, argType), |
| 413 | }; |
| 414 | } |
| 415 | |
| 416 | if (!argSelection) { |
| 417 | console.error('Unable to add arg for argType', argType); |
| 418 | } else { |
| 419 | return this.props.modifyFields( |
nothing calls this directly
no test coverage detected
searching dependent graphs…