-
Notifications
You must be signed in to change notification settings - Fork 13
add backlinksTotalCountsTypeId1 #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@graphprotocol/hypergraph-react": patch | ||
| "@graphprotocol/hypergraph": patch | ||
| --- | ||
|
|
||
| add temporary backlinksTotalCountsTypeId1 to Entity.findManyPublic and useEntities | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,11 @@ export type FindManyPublicParams<S extends Schema.Schema.AnyNoContext> = { | |
| direction: 'asc' | 'desc'; | ||
| } | ||
| | undefined; | ||
| backlinksTotalCountsTypeId1?: string | undefined; | ||
| }; | ||
|
|
||
| const entitiesQueryDocumentLevel0 = gql` | ||
| query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { | ||
| query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { | ||
| entities( | ||
| filter: { and: [{ | ||
| relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, | ||
|
|
@@ -41,12 +42,15 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: Entity | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const entitiesQueryDocumentLevel1 = gql` | ||
| query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { | ||
| query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { | ||
| entities( | ||
| first: $first | ||
| filter: { and: [{ | ||
|
|
@@ -65,6 +69,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| relationsList( | ||
| filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, | ||
| ) { | ||
|
|
@@ -98,7 +105,7 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI | |
| `; | ||
|
|
||
| const entitiesQueryDocumentLevel2 = gql` | ||
| query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { | ||
| query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { | ||
| entities( | ||
| first: $first | ||
| filter: { and: [{ | ||
|
|
@@ -117,6 +124,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| relationsList( | ||
| filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, | ||
| ) { | ||
|
|
@@ -142,6 +152,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| relationsList( | ||
| filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel2}}, | ||
| # filter: {spaceId: {is: $spaceId}, toEntity: {relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $relationTypeIdsLevel2}}}}} | ||
|
|
@@ -179,7 +192,7 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI | |
| `; | ||
|
|
||
| const entitiesOrderedByPropertyQueryDocumentLevel0 = gql` | ||
| query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) { | ||
| query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { | ||
| entities: entitiesOrderedByProperty( | ||
| filter: { and: [{ | ||
| relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, | ||
|
|
@@ -200,12 +213,15 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const entitiesOrderedByPropertyQueryDocumentLevel1 = gql` | ||
| query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) { | ||
| query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { | ||
| entities: entitiesOrderedByProperty( | ||
| first: $first | ||
| filter: { and: [{ | ||
|
|
@@ -226,6 +242,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| relationsList( | ||
| filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, | ||
| ) { | ||
|
|
@@ -259,7 +278,7 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy | |
| `; | ||
|
|
||
| const entitiesOrderedByPropertyQueryDocumentLevel2 = gql` | ||
| query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) { | ||
| query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { | ||
| entities: entitiesOrderedByProperty( | ||
| first: $first | ||
| filter: { and: [{ | ||
|
|
@@ -280,6 +299,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| relationsList( | ||
| filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, | ||
| ) { | ||
|
|
@@ -305,6 +327,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy | |
| time | ||
| point | ||
| } | ||
| backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { | ||
| totalCount | ||
| } | ||
| relationsList( | ||
| filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel2}}, | ||
| ) { | ||
|
|
@@ -352,6 +377,9 @@ type EntityQueryResult = { | |
| time: string; | ||
| point: string; | ||
| }[]; | ||
| backlinksTotalCountsTypeId1: { | ||
| totalCount: number; | ||
| } | null; | ||
| relationsList: { | ||
| id: string; | ||
| entity: { | ||
|
|
@@ -412,7 +440,7 @@ type GraphSortDirection = 'ASC' | 'DESC'; | |
| export const parseResult = <S extends Schema.Schema.AnyNoContext>(queryData: EntityQueryResult, type: S) => { | ||
| const schemaWithId = Utils.addIdSchemaField(type); | ||
| const decode = Schema.decodeUnknownEither(schemaWithId); | ||
| const data: Entity.Entity<S>[] = []; | ||
| const data: (Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number })[] = []; | ||
|
||
| const invalidEntities: Record<string, unknown>[] = []; | ||
|
|
||
| for (const queryEntity of queryData.entities) { | ||
|
|
@@ -454,7 +482,11 @@ export const parseResult = <S extends Schema.Schema.AnyNoContext>(queryData: Ent | |
|
|
||
| if (Either.isRight(decodeResult)) { | ||
| // injecting the schema to the entity to be able to access it in the preparePublish function | ||
| data.push({ ...decodeResult.right, __schema: type }); | ||
| data.push({ | ||
| ...decodeResult.right, | ||
| __schema: type, | ||
| backlinksTotalCountsTypeId1: queryEntity.backlinksTotalCountsTypeId1?.totalCount, | ||
| }); | ||
| } else { | ||
| invalidEntities.push(rawEntity); | ||
| } | ||
|
|
@@ -466,7 +498,7 @@ export const findManyPublic = async <S extends Schema.Schema.AnyNoContext>( | |
| type: S, | ||
| params?: FindManyPublicParams<S>, | ||
| ) => { | ||
| const { filter, include, space, first = 100, offset = 0, orderBy } = params ?? {}; | ||
| const { filter, include, space, first = 100, offset = 0, orderBy, backlinksTotalCountsTypeId1 } = params ?? {}; | ||
|
|
||
| // constructing the relation type ids for the query | ||
| const relationTypeIds = Utils.getRelationTypeIds(type, include); | ||
|
|
@@ -534,6 +566,13 @@ export const findManyPublic = async <S extends Schema.Schema.AnyNoContext>( | |
| queryVariables.sortDirection = sortDirection; | ||
| } | ||
|
|
||
| if (backlinksTotalCountsTypeId1) { | ||
| queryVariables.backlinksTotalCountsTypeId1 = backlinksTotalCountsTypeId1; | ||
| queryVariables.backlinksTotalCountsTypeId1Present = true; | ||
| } else { | ||
| queryVariables.backlinksTotalCountsTypeId1Present = false; | ||
| } | ||
|
|
||
| const result = await request<EntityQueryResult>(`${Graph.TESTNET_API_ORIGIN}/graphql`, queryDocument, queryVariables); | ||
|
|
||
| const { data, invalidEntities } = parseResult(result, type); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,6 +279,7 @@ export const searchManyPublic = async <S extends Schema.Schema.AnyNoContext>( | |
| offset, | ||
| }); | ||
|
|
||
| // @ts-expect-error TODO: fix this | ||
| const { data, invalidEntities } = parseResult({ entities: result.search }, type); | ||
|
Comment on lines
+282
to
283
|
||
| return { data, invalidEntities }; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type cast assumes local (private mode) entities will have
backlinksTotalCountsTypeId1, but this field is only populated in public mode queries viafindManyPublic. Local entities retrieved throughuseEntitiesPrivatewon't have this field, making this cast potentially misleading. The field should be marked as optional and only expected whenmode === 'public'.