MCPcopy Create free account
hub / github.com/hashintel/hash / updateEntity

Function updateEntity

apps/hash-api/src/graph/knowledge/primitive/entity.ts:471–536  ·  view source on GitHub ↗
(
  ...args: Parameters<UpdateEntityFunction<Properties>>
)

Source from the content-addressed store, hash-verified

469 * Update an entity.
470 */
471export const updateEntity = async <
472 Properties extends TypeIdsAndPropertiesForEntity,
473>(
474 ...args: Parameters<UpdateEntityFunction<Properties>>
475): ReturnType<UpdateEntityFunction<Properties>> => {
476 const [context, authentication, params] = args;
477 const { entity, entityTypeIds, propertyPatches } = params;
478
479 for (const beforeUpdateHook of beforeUpdateEntityHooks) {
480 if (entity.metadata.entityTypeIds.includes(beforeUpdateHook.entityTypeId)) {
481 await beforeUpdateHook.callback({
482 context,
483 previousEntity: entity,
484 propertyPatches: propertyPatches ?? [],
485 authentication,
486 });
487 }
488 }
489
490 const { graphApi } = context;
491 const { actorId } = authentication;
492
493 /**
494 * The SDK's patch method auto-enforces the base user property whitelist.
495 * Here we extend it with properties that have special authorization
496 * (validated by the before-update hook which runs above).
497 *
498 * - enabledFeatureFlags: the hook checks admin privileges
499 * - shortname: the hook allows it only for incomplete users (first-time signup)
500 */
501 const additionalAllowedUrls = new Set([enabledFeatureFlagsPropertyBaseUrl]);
502
503 const { shortname } = simplifyProperties<UserProperties>(
504 entity.properties as UserProperties,
505 );
506 if (!shortname) {
507 additionalAllowedUrls.add(shortnamePropertyBaseUrl);
508 }
509
510 const updatedEntity = await entity.patch(
511 graphApi,
512 { actorId },
513 {
514 entityTypeIds,
515 draft: params.draft,
516 propertyPatches,
517 provenance: context.provenance,
518 archived: params.archived,
519 additionalAllowedPropertyBaseUrls: additionalAllowedUrls,
520 },
521 );
522
523 for (const afterUpdateHook of afterUpdateEntityHooks) {
524 if (entity.metadata.entityTypeIds.includes(afterUpdateHook.entityTypeId)) {
525 void afterUpdateHook.callback({
526 context,
527 previousEntity: entity,
528 propertyPatches: propertyPatches ?? [],

Callers 10

updatePageResolverFunction · 0.90
handleUpdateEntityFunction · 0.90
updateEntityResolverFunction · 0.90
setPageParentPageFunction · 0.90
deleteCommentFunction · 0.90
updateOrgNameFunction · 0.90
upgradeWebEntitiesFunction · 0.90
entity.test.tsFile · 0.90
user.test.tsFile · 0.90

Calls 3

simplifyPropertiesFunction · 0.90
addMethod · 0.45
patchMethod · 0.45

Tested by

no test coverage detected