@@ -6,50 +6,27 @@ import { gql, request } from 'graphql-request';
66import { useMemo } from 'react' ;
77import { useHypergraph } from '../HypergraphSpaceContext.js' ;
88import type { Mapping , MappingEntry } from '../types.js' ;
9- import { GEO_ENDPOINT } from './constants.js' ;
9+ import { GEO_API_TESTNET_ENDPOINT } from './constants.js' ;
1010import type { QueryPublicParams } from './types.js' ;
1111
1212const entitiesQueryDocument = gql `
13- query entities($spaceId: String!, $typeId: String!, $relationTypeIds: [String!]!) {
14- entities(
15- filter: {
16- currentVersion: {
17- version: {
18- versionTypes: {some: {type: {entityId: {equalTo: $typeId}}}}
19- versionSpaces: {some: {spaceId: {equalTo: $spaceId}}}
20- }
21- }
13+ query entities($spaceId: String!) {
14+ entities(spaceId: $spaceId, filter: {}) {
15+ id
16+ name
17+ values {
18+ propertyId
19+ value
2220 }
23- ) {
24- nodes {
25- id
26- name
27- currentVersion {
28- versionId
29- version {
30- triples {
31- nodes {
32- attributeId
33- textValue
34- booleanValue
35- numberValue
36- valueType
37- unitOption
38- }
39- }
40- relationsByFromVersionId(filter: {typeOfId: {in: $relationTypeIds}}) {
41- nodes {
42- toEntity {
43- nodeId
44- id
45- name
46- }
47- typeOf {
48- id
49- name
50- }
51- }
52- }
21+ relations {
22+ to {
23+ id
24+ name
25+ }
26+ type {
27+ id
28+ entity {
29+ name
5330 }
5431 }
5532 }
@@ -59,39 +36,25 @@ query entities($spaceId: String!, $typeId: String!, $relationTypeIds: [String!]!
5936
6037type EntityQueryResult = {
6138 entities : {
62- nodes : {
63- id : string ;
64- name : string ;
65- currentVersion : {
66- versionId : string ;
67- version : {
68- triples : {
69- nodes : {
70- attributeId : string ;
71- textValue : string ;
72- booleanValue : boolean ;
73- numberValue : number ;
74- valueType : 'TEXT' | 'CHECKBOX' | 'POINT' | 'URL' | 'TIME' | 'NUMBER' ;
75- unitOption : unknown ;
76- } [ ] ;
77- } ;
78- relationsByFromVersionId : {
79- nodes : {
80- typeOf : {
81- name : string ;
82- id : string ;
83- } ;
84- toEntity : {
85- nodeId : string ;
86- id : string ;
87- name : string ;
88- } ;
89- } [ ] ;
90- } ;
39+ id : string ;
40+ name : string ;
41+ values : {
42+ propertyId : string ;
43+ value : string ;
44+ } [ ] ;
45+ relations : {
46+ to : {
47+ id : string ;
48+ name : string ;
49+ } ;
50+ type : {
51+ id : string ;
52+ entity : {
53+ name : string ;
9154 } ;
9255 } ;
9356 } [ ] ;
94- } ;
57+ } [ ] ;
9558} ;
9659
9760export const parseResult = < S extends Entity . AnyNoContext > (
@@ -104,33 +67,33 @@ export const parseResult = <S extends Entity.AnyNoContext>(
10467 const data : Entity . Entity < S > [ ] = [ ] ;
10568 const invalidEntities : Record < string , unknown > [ ] = [ ] ;
10669
107- for ( const queryEntity of queryData . entities . nodes ) {
108- const queryEntityVersion = queryEntity . currentVersion . version ;
70+ for ( const queryEntity of queryData . entities ) {
10971 const rawEntity : Record < string , string | boolean | number | unknown [ ] | URL | Date > = {
11072 id : queryEntity . id ,
11173 } ;
74+
11275 // take the mappingEntry and assign the attributes to the rawEntity
11376 for ( const [ key , value ] of Object . entries ( mappingEntry ?. properties ?? { } ) ) {
114- const property = queryEntityVersion . triples . nodes . find ( ( a ) => a . attributeId === value ) ;
77+ const property = queryEntity . values . find ( ( a ) => a . propertyId === value ) ;
11578 if ( property ) {
11679 if ( type . fields [ key ] === Type . Checkbox ) {
117- rawEntity [ key ] = property . booleanValue ;
80+ rawEntity [ key ] = Boolean ( property . value ) ;
11881 } else if ( type . fields [ key ] === Type . Point ) {
119- rawEntity [ key ] = property . textValue ;
82+ rawEntity [ key ] = property . value ;
12083 } else if ( type . fields [ key ] === Type . Url ) {
121- rawEntity [ key ] = property . textValue ;
84+ rawEntity [ key ] = property . value ;
12285 } else if ( type . fields [ key ] === Type . Date ) {
123- rawEntity [ key ] = property . textValue ;
86+ rawEntity [ key ] = property . value ;
12487 } else if ( type . fields [ key ] === Type . Number ) {
125- rawEntity [ key ] = Number ( property . textValue ) ;
88+ rawEntity [ key ] = Number ( property . value ) ;
12689 } else {
127- rawEntity [ key ] = property . textValue ;
90+ rawEntity [ key ] = property . value ;
12891 }
12992 }
13093 }
13194
13295 for ( const [ key , relationId ] of Object . entries ( mappingEntry ?. relations ?? { } ) ) {
133- const properties = queryEntityVersion . relationsByFromVersionId . nodes . filter ( ( a ) => a . typeOf . id === relationId ) ;
96+ const properties = queryEntity . relations . filter ( ( a ) => a . type . id === relationId ) ;
13497 if ( properties . length === 0 ) {
13598 rawEntity [ key ] = [ ] as unknown [ ] ;
13699 continue ;
@@ -158,9 +121,9 @@ export const parseResult = <S extends Entity.AnyNoContext>(
158121 }
159122
160123 const newRelationEntities = properties . map ( ( property ) => ( {
161- id : property . toEntity . id ,
162- name : property . toEntity . name ,
163- type : relationMappingEntry . typeIds [ 0 ] ,
124+ id : property . to . id ,
125+ name : property . to . name ,
126+ type : property . type . id ,
164127 // TODO: should be determined by the actual value
165128 __deleted : false ,
166129 // TODO: should be determined by the actual value
@@ -181,7 +144,8 @@ export const parseResult = <S extends Entity.AnyNoContext>(
181144 const decodeResult = decode ( {
182145 ...rawEntity ,
183146 __deleted : false ,
184- __version : queryEntity . currentVersion . versionId ,
147+ // __version: queryEntity.currentVersion.versionId,
148+ __version : '' ,
185149 } ) ;
186150
187151 if ( Either . isRight ( decodeResult ) ) {
@@ -215,7 +179,7 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
215179 const result = useQueryTanstack ( {
216180 queryKey : [ `entities:geo:${ typeName } ` ] ,
217181 queryFn : async ( ) => {
218- const result = await request < EntityQueryResult > ( GEO_ENDPOINT , entitiesQueryDocument , {
182+ const result = await request < EntityQueryResult > ( GEO_API_TESTNET_ENDPOINT , entitiesQueryDocument , {
219183 spaceId : space ,
220184 typeId : mappingEntry ?. typeIds [ 0 ] ,
221185 relationTypeIds,
0 commit comments