|
1 | 1 | import { Graph, Id, type PropertiesParam, type RelationsParam } from '@graphprotocol/grc-20'; |
2 | 2 | import type { Connect, Entity } from '@graphprotocol/hypergraph'; |
3 | | -import { store, Type } from '@graphprotocol/hypergraph'; |
| 3 | +import { store, TypeUtils } from '@graphprotocol/hypergraph'; |
4 | 4 | import { useQueryClient } from '@tanstack/react-query'; |
5 | 5 | import { useSelector } from '@xstate/store/react'; |
6 | 6 | import type * as Schema from 'effect/Schema'; |
@@ -33,14 +33,20 @@ export function useCreateEntityPublic<const S extends Entity.AnyNoContext>( |
33 | 33 | const fields = type.fields; |
34 | 34 | const values: PropertiesParam = []; |
35 | 35 | for (const [key, value] of Object.entries(mappingEntry.properties || {})) { |
| 36 | + if (data[key] === undefined) { |
| 37 | + if (TypeUtils.isOptional(fields[key])) { |
| 38 | + continue; |
| 39 | + } |
| 40 | + throw new Error(`Value for ${key} is undefined`); |
| 41 | + } |
36 | 42 | let serializedValue: string = data[key]; |
37 | | - if (fields[key] === Type.Checkbox) { |
| 43 | + if (TypeUtils.isCheckboxOrOptionalCheckboxType(fields[key])) { |
38 | 44 | serializedValue = Graph.serializeCheckbox(data[key]); |
39 | | - } else if (fields[key] === Type.Date) { |
| 45 | + } else if (TypeUtils.isDateOrOptionalDateType(fields[key])) { |
40 | 46 | serializedValue = Graph.serializeDate(data[key]); |
41 | | - } else if (fields[key] === Type.Point) { |
| 47 | + } else if (TypeUtils.isPointOrOptionalPointType(fields[key])) { |
42 | 48 | serializedValue = Graph.serializePoint(data[key]); |
43 | | - } else if (fields[key] === Type.Number) { |
| 49 | + } else if (TypeUtils.isNumberOrOptionalNumberType(fields[key])) { |
44 | 50 | serializedValue = Graph.serializeNumber(data[key]); |
45 | 51 | } |
46 | 52 |
|
|
0 commit comments