
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
@blockprotocol/graph
Advanced tools
Implementation of the Block Protocol Graph service specification for blocks and embedding applications
This package implements the Block Protocol Graph service for blocks and embedding applications.
If you are a block author, we have several templates available to get you started:
npx create-block-app --help
If you want to roll your own, to get started:
yarn add @blockprotocol/graph
or npm install @blockprotocol/graph
To create a GraphBlockHandler, pass the constructor an element in your block, along with any callbacks you wish to register to handle incoming messages.
For React, we provide a useGraphBlockService
hook, which accepts a ref
to an element, and optionally any callbacks
you wish to provide on initialization.
See npx create-block-app my-block --template react
for an example.
For custom elements, this package exports a BlockElementBase
class
which uses the Lit framework, and sets graphService
on the instance.
See npx create-block-app my-block --template custom-element
for an example.
To create a GraphEmbedderHandler, pass the constructor:
element
wrapping your blockcallbacks
to respond to messages from the blockblockEntity
blockGraph
linkedAggregations
These starting values should also be passed in a graph
property object, if the block can be passed or assigned properties.
import { GraphEmbedderHandler } from "@blockprotocol/graph";
const graphService = new GraphEmbedderHandler({
blockEntity: { entityId: "123", properties: { name: "Bob" } },
callbacks: {
updateEntity: ({ data }) => updateEntityInYourDatastore(data),
},
element: elementWrappingTheBlock,
});
For React embedding applications, we provide a useGraphEmbedderService
hook, which accepts a ref
to an element, and optionally any additional constructor arguments you wish to pass.
import { useGraphEmbedderService } from "@blockprotocol/graph";
import { useRef } from "react";
export const App = () => {
const wrappingRef = useRef<HTMLDivElement>(null);
const blockEntity = { entityId: "123", properties: { name: "Bob" } };
const { graphService } = useGraphEmbedderService(blockRef, {
blockEntity,
});
return (
<div ref={wrappingRef}>
<Block graph={{ blockEntity }} />
</div>
);
};
FAQs
Implementation of the Block Protocol Graph service specification for blocks and embedding applications
We found that @blockprotocol/graph demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.