| 5629 | var _definition = require_definition(); |
| 5630 | var _scalars = require_scalars(); |
| 5631 | function astFromValue(value, type) { |
| 5632 | if ((0, _definition.isNonNullType)(type)) { |
| 5633 | const astValue = astFromValue(value, type.ofType); |
| 5634 | if ((astValue === null || astValue === void 0 ? void 0 : astValue.kind) === _kinds.Kind.NULL) { |
| 5635 | return null; |
| 5636 | } |
| 5637 | return astValue; |
| 5638 | } |
| 5639 | if (value === null) { |
| 5640 | return { |
| 5641 | kind: _kinds.Kind.NULL |
| 5642 | }; |
| 5643 | } |
| 5644 | if (value === void 0) { |
| 5645 | return null; |
| 5646 | } |
| 5647 | if ((0, _definition.isListType)(type)) { |
| 5648 | const itemType = type.ofType; |
| 5649 | if ((0, _isIterableObject.isIterableObject)(value)) { |
| 5650 | const valuesNodes = []; |
| 5651 | for (const item of value) { |
| 5652 | const itemNode = astFromValue(item, itemType); |
| 5653 | if (itemNode != null) { |
| 5654 | valuesNodes.push(itemNode); |
| 5655 | } |
| 5656 | } |
| 5657 | return { |
| 5658 | kind: _kinds.Kind.LIST, |
| 5659 | values: valuesNodes |
| 5660 | }; |
| 5661 | } |
| 5662 | return astFromValue(value, itemType); |
| 5663 | } |
| 5664 | if ((0, _definition.isInputObjectType)(type)) { |
| 5665 | if (!(0, _isObjectLike.isObjectLike)(value)) { |
| 5666 | return null; |
| 5667 | } |
| 5668 | const fieldNodes = []; |
| 5669 | for (const field of Object.values(type.getFields())) { |
| 5670 | const fieldValue = astFromValue(value[field.name], field.type); |
| 5671 | if (fieldValue) { |
| 5672 | fieldNodes.push({ |
| 5673 | kind: _kinds.Kind.OBJECT_FIELD, |
| 5674 | name: { |
| 5675 | kind: _kinds.Kind.NAME, |
| 5676 | value: field.name |
| 5677 | }, |
| 5678 | value: fieldValue |
| 5679 | }); |
| 5680 | } |
| 5681 | } |
| 5682 | return { |
| 5683 | kind: _kinds.Kind.OBJECT, |
| 5684 | fields: fieldNodes |
| 5685 | }; |
| 5686 | } |
| 5687 | if ((0, _definition.isLeafType)(type)) { |
| 5688 | const serialized = type.serialize(value); |