Skip to content

Commit 61ceb22

Browse files
committed
fix type issues
1 parent 21463da commit 61ceb22

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

packages/hypergraph-react/src/internal/use-entity-public.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Graph } from '@graphprotocol/grc-20';
2-
import { Constants, type Entity } from '@graphprotocol/hypergraph';
2+
import { Constants, type Entity, Utils } from '@graphprotocol/hypergraph';
33
import { useQuery as useQueryTanstack } from '@tanstack/react-query';
44
import * as Either from 'effect/Either';
55
import * as Option from 'effect/Option';
@@ -175,7 +175,7 @@ export const parseResult = <S extends Schema.Schema.AnyNoContext>(queryData: Ent
175175
return { data: null, invalidEntity: null };
176176
}
177177

178-
const schemaWithId = Schema.extend(Schema.Struct({ id: Schema.String }))(type);
178+
const schemaWithId = Utils.addIdSchemaField(type);
179179
const decode = Schema.decodeUnknownEither(schemaWithId);
180180
const queryEntity = queryData.entity;
181181
let rawEntity: Record<string, string | boolean | number | unknown[] | Date> = {

packages/hypergraph-react/src/internal/use-query-public.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Graph } from '@graphprotocol/grc-20';
2-
import type { Entity } from '@graphprotocol/hypergraph';
3-
import { Constants } from '@graphprotocol/hypergraph';
2+
import { Constants, type Entity, Utils } from '@graphprotocol/hypergraph';
43
import { useQuery as useQueryTanstack } from '@tanstack/react-query';
54
import * as Either from 'effect/Either';
65
import * as Option from 'effect/Option';
@@ -187,7 +186,7 @@ type EntityQueryResult = {
187186
};
188187

189188
export const parseResult = <S extends Schema.Schema.AnyNoContext>(queryData: EntityQueryResult, type: S) => {
190-
const schemaWithId = Schema.extend(Schema.Struct({ id: Schema.String }))(type);
189+
const schemaWithId = Utils.addIdSchemaField(type);
191190
const decode = Schema.decodeUnknownEither(schemaWithId);
192191
const data: Entity.Entity<S>[] = [];
193192
const invalidEntities: Record<string, unknown>[] = [];
@@ -271,16 +270,15 @@ export const useQueryPublic = <S extends Schema.Schema.AnyNoContext>(type: S, pa
271270
queryDocument = entitiesQueryDocumentLevel2;
272271
}
273272

274-
const filterResult = filter ? translateFilterToGraphql(filter, type) : {};
275-
console.log('filterResult', filterResult);
273+
const filterParams = filter ? translateFilterToGraphql(filter, type) : {};
276274

277275
const result = await request<EntityQueryResult>(`${Graph.TESTNET_API_ORIGIN}/graphql`, queryDocument, {
278276
spaceId: space,
279277
typeIds,
280278
relationTypeIdsLevel1: relationTypeIds.level1,
281279
relationTypeIdsLevel2: relationTypeIds.level2,
282280
first,
283-
filter: filterResult,
281+
filter: filterParams,
284282
});
285283
return result;
286284
},

packages/hypergraph/src/type/type.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,19 @@ export const Relation =
5757
Option.getOrElse(() => []),
5858
);
5959

60-
const schemaWithId = Schema.extend(schema)(
61-
Schema.Struct({ id: Schema.String, _relation: Schema.Struct({ id: Schema.String }) }),
60+
const schemaWithId = Schema.asSchema(
61+
Schema.extend(schema)(
62+
Schema.Struct({
63+
id: Schema.String,
64+
_relation: Schema.Struct({ id: Schema.String }),
65+
}),
66+
),
6267
// manually adding the type ids to the schema since they get lost when extending the schema
63-
).pipe(Schema.annotations({ [TypeIdsSymbol]: typeIds }));
68+
).pipe(Schema.annotations({ [TypeIdsSymbol]: typeIds })) as Schema.Schema<
69+
Schema.Schema.Type<S> & { readonly id: string; readonly _relation: { readonly id: string } },
70+
Schema.Schema.Encoded<S> & { readonly id: string; readonly _relation: { readonly id: string } },
71+
never
72+
>;
6473

6574
return Schema.Array(schemaWithId).pipe(
6675
Schema.annotations({
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Schema from 'effect/Schema';
2+
3+
export const addIdSchemaField = <S extends Schema.Schema.AnyNoContext>(schema: S) =>
4+
Schema.asSchema(Schema.extend(Schema.Struct({ id: Schema.String }))(schema)) as Schema.Schema<
5+
Schema.Schema.Type<S> & { readonly id: string },
6+
Schema.Schema.Encoded<S> & { readonly id: string },
7+
never
8+
>;

packages/hypergraph/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './addIdSchemaField.js';
12
export * from './assertExhaustive.js';
23
export * from './automergeId.js';
34
export * from './base58.js';

0 commit comments

Comments
 (0)