-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: edge deletion behavior cyclic import structure (#89)
- Loading branch information
Showing
8 changed files
with
133 additions
and
108 deletions.
There are no files selected for viewing
102 changes: 3 additions & 99 deletions
102
...es/entity-full-integration-tests/src/__integration-tests__/EntityEdgesIntegration-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/entity-full-integration-tests/src/__integration-tests__/entities/ChildEntity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
AlwaysAllowPrivacyPolicyRule, | ||
CacheAdapterFlavor, | ||
DatabaseAdapterFlavor, | ||
Entity, | ||
EntityCompanionDefinition, | ||
EntityConfiguration, | ||
EntityEdgeDeletionBehavior, | ||
EntityPrivacyPolicy, | ||
UUIDField, | ||
ViewerContext, | ||
} from '@expo/entity'; | ||
|
||
import ParentEntity from './ParentEntity'; | ||
|
||
interface ChildFields { | ||
id: string; | ||
parent_id: string; | ||
} | ||
|
||
class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<any, string, ViewerContext, any, any> { | ||
protected readonly readRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
protected readonly createRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
protected readonly updateRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
protected readonly deleteRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
} | ||
|
||
export default class ChildEntity extends Entity<ChildFields, string, ViewerContext> { | ||
static getCompanionDefinition(): EntityCompanionDefinition< | ||
ChildFields, | ||
string, | ||
ViewerContext, | ||
ChildEntity, | ||
TestEntityPrivacyPolicy | ||
> { | ||
return childEntityCompanion; | ||
} | ||
} | ||
|
||
const childEntityConfiguration = new EntityConfiguration<ChildFields>({ | ||
idField: 'id', | ||
tableName: 'children', | ||
schema: { | ||
id: new UUIDField({ | ||
columnName: 'id', | ||
cache: true, | ||
}), | ||
parent_id: new UUIDField({ | ||
columnName: 'parent_id', | ||
cache: true, | ||
association: { | ||
associatedEntityClass: ParentEntity, | ||
edgeDeletionBehavior: EntityEdgeDeletionBehavior.CASCADE_DELETE_INVALIDATE_CACHE, | ||
}, | ||
}), | ||
}, | ||
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES, | ||
cacheAdapterFlavor: CacheAdapterFlavor.REDIS, | ||
}); | ||
|
||
const childEntityCompanion = new EntityCompanionDefinition({ | ||
entityClass: ChildEntity, | ||
entityConfiguration: childEntityConfiguration, | ||
privacyPolicyClass: TestEntityPrivacyPolicy, | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/entity-full-integration-tests/src/__integration-tests__/entities/ParentEntity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
AlwaysAllowPrivacyPolicyRule, | ||
CacheAdapterFlavor, | ||
DatabaseAdapterFlavor, | ||
Entity, | ||
EntityCompanionDefinition, | ||
EntityConfiguration, | ||
EntityPrivacyPolicy, | ||
UUIDField, | ||
ViewerContext, | ||
} from '@expo/entity'; | ||
|
||
import ChildEntity from './ChildEntity'; | ||
|
||
interface ParentFields { | ||
id: string; | ||
} | ||
|
||
class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<any, string, ViewerContext, any, any> { | ||
protected readonly readRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
protected readonly createRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
protected readonly updateRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
protected readonly deleteRules = [new AlwaysAllowPrivacyPolicyRule()]; | ||
} | ||
|
||
export default class ParentEntity extends Entity<ParentFields, string, ViewerContext> { | ||
static getCompanionDefinition(): EntityCompanionDefinition< | ||
ParentFields, | ||
string, | ||
ViewerContext, | ||
ParentEntity, | ||
TestEntityPrivacyPolicy | ||
> { | ||
return parentEntityCompanion; | ||
} | ||
} | ||
|
||
const parentEntityConfiguration = new EntityConfiguration<ParentFields>({ | ||
idField: 'id', | ||
tableName: 'parents', | ||
inboundEdges: () => [ChildEntity], | ||
schema: { | ||
id: new UUIDField({ | ||
columnName: 'id', | ||
cache: true, | ||
}), | ||
}, | ||
databaseAdapterFlavor: DatabaseAdapterFlavor.POSTGRES, | ||
cacheAdapterFlavor: CacheAdapterFlavor.REDIS, | ||
}); | ||
|
||
const parentEntityCompanion = new EntityCompanionDefinition({ | ||
entityClass: ParentEntity, | ||
entityConfiguration: parentEntityConfiguration, | ||
privacyPolicyClass: TestEntityPrivacyPolicy, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters