Graph Service
The Graph Service manages the social graphs, including follow/unfollow actions, blocking users, and other social interactions. It allows applications to maintain and query the social connections between users on the Frequency network.
API Reference
Path Table
Method | Path | Description |
---|---|---|
POST | /v1/graphs/getGraphs | Fetch graphs for specified MSA Ids and Block Number |
PUT | /v1/graphs | Request an update to a given user's graph |
GET | /v1/webhooks | Get all registered webhooks |
PUT | /v1/webhooks | Watch graphs for specified dsnpIds and receive updates |
DELETE | /v1/webhooks | Delete all registered webhooks |
GET | /v1/webhooks/users/{msaId} | Get all registered webhooks for a specific MSA Id |
DELETE | /v1/webhooks/users/{msaId} | Delete all webhooks registered for a specific MSA |
GET | /v1/webhooks/urls | Get all webhooks registered to the specified URL |
DELETE | /v1/webhooks/urls | Delete all MSA webhooks registered with the given URL |
GET | /healthz | Check the health status of the service |
GET | /livez | Check the live status of the service |
GET | /readyz | Check the ready status of the service |
Reference Table
Name | Path | Description |
---|---|---|
GraphKeyPairDto | #/components/schemas/GraphKeyPairDto | |
GraphsQueryParamsDto | #/components/schemas/GraphsQueryParamsDto | |
DsnpGraphEdgeDto | #/components/schemas/DsnpGraphEdgeDto | |
UserGraphDto | #/components/schemas/UserGraphDto | |
ConnectionDto | #/components/schemas/ConnectionDto | |
ConnectionDtoWrapper | #/components/schemas/ConnectionDtoWrapper | |
ProviderGraphDto | #/components/schemas/ProviderGraphDto | |
GraphChangeRepsonseDto | #/components/schemas/GraphChangeRepsonseDto | |
WatchGraphsDto | #/components/schemas/WatchGraphsDto |
Path Details
[POST]/v1/graphs/getGraphs
- Summary
Fetch graphs for specified MSA Ids and Block Number
RequestBody
- application/json
{
dsnpIds?: string[]
// Graph type to query (public or private)
privacyType: enum[private, public]
graphKeyPairs: {
// Public graph encryption key as a hex string (prefixed with "0x")
publicKey: string
// Private graph encryption key as a hex string (prefixed with "0x")
privateKey: string
// Key type of graph encryption keypair (currently only X25519 supported)
keyType: enum[X25519]
}[]
}
Responses
- 200 Graphs retrieved successfully
application/json
{
// MSA Id that is the owner of the graph represented by the graph edges in this object
dsnpId: string
dsnpGraphEdges: {
// MSA Id of the user represented by this graph edge
userId: string
// Block number when connection represented by this graph edge was created
since: number
}[]
}[]
[PUT]/v1/graphs
- Summary
Request an update to a given user's graph
RequestBody
- application/json
{
// MSA Id that owns the connections represented in this object
dsnpId: string
// Array of connections known to the Provider for ths MSA referenced in this object
connections: #/components/schemas/ConnectionDtoWrapper
graphKeyPairs: {
// Public graph encryption key as a hex string (prefixed with "0x")
publicKey: string
// Private graph encryption key as a hex string (prefixed with "0x")
privateKey: string
// Key type of graph encryption keypair (currently only X25519 supported)
keyType: enum[X25519]
}[]
// Optional URL of a webhook to invoke when the request is complete
webhookUrl?: string
}
Responses
- 201 Graph update request created successfully
application/json
{
// Reference ID by which the results/status of a submitted GraphChangeRequest may be retrieved
referenceId: string
}
[GET]/v1/webhooks
- Summary
Get all registered webhooks
Responses
- 200 Retrieved all registered webhooks
[PUT]/v1/webhooks
- Summary
Watch graphs for specified dsnpIds and receive updates
RequestBody
- application/json
{
dsnpIds?: string[]
// Webhook URL to call when graph changes for the referenced MSAs are detected
webhookEndpoint: string
}
Responses
- 200 Successfully started watching graphs
[DELETE]/v1/webhooks
- Summary
Delete all registered webhooks
Responses
- 200 Removed all registered webhooks
[GET]/v1/webhooks/users/{msaId}
- Summary
Get all registered webhooks for a specific MSA Id
Parameters(Query)
includeAll?: boolean
Responses
- 200 Retrieved all registered webhooks for the given MSA Id
[DELETE]/v1/webhooks/users/{msaId}
- Summary
Delete all webhooks registered for a specific MSA
Responses
- 200 Removed all registered webhooks for the specified MSA
[GET]/v1/webhooks/urls
- Summary
Get all webhooks registered to the specified URL
Parameters(Query)
url: string
Responses
- 200 Retrieved all webhooks registered to the specified URL
[DELETE]/v1/webhooks/urls
- Summary
Delete all MSA webhooks registered with the given URL
Parameters(Query)
url: string
Responses
- 200 Removed all webhooks registered to the specified URL
[GET]/healthz
- Summary
Check the health status of the service
Responses
- 200 Service is healthy
[GET]/livez
- Summary
Check the live status of the service
Responses
- 200 Service is live
[GET]/readyz
- Summary
Check the ready status of the service
Responses
- 200 Service is ready
References
#/components/schemas/GraphKeyPairDto
{
// Public graph encryption key as a hex string (prefixed with "0x")
publicKey: string
// Private graph encryption key as a hex string (prefixed with "0x")
privateKey: string
// Key type of graph encryption keypair (currently only X25519 supported)
keyType: enum[X25519]
}
#/components/schemas/GraphsQueryParamsDto
{
dsnpIds?: string[]
// Graph type to query (public or private)
privacyType: enum[private, public]
graphKeyPairs: {
// Public graph encryption key as a hex string (prefixed with "0x")
publicKey: string
// Private graph encryption key as a hex string (prefixed with "0x")
privateKey: string
// Key type of graph encryption keypair (currently only X25519 supported)
keyType: enum[X25519]
}[]
}
#/components/schemas/DsnpGraphEdgeDto
{
// MSA Id of the user represented by this graph edge
userId: string
// Block number when connection represented by this graph edge was created
since: number
}
#/components/schemas/UserGraphDto
{
// MSA Id that is the owner of the graph represented by the graph edges in this object
dsnpId: string
dsnpGraphEdges: {
// MSA Id of the user represented by this graph edge
userId: string
// Block number when connection represented by this graph edge was created
since: number
}[]
}
#/components/schemas/ConnectionDto
{
// MSA Id representing the target of this connection
dsnpId: string
// Indicator connection type (public or private)
privacyType: enum[private, public]
// Indicator of the direction of this connection
direction: enum[connectionTo, connectionFrom, bidirectional, disconnect]
// Indicator of the type of connection (follow or friendship)
connectionType: enum[follow, friendship]
}
#/components/schemas/ConnectionDtoWrapper
{
data: {
// MSA Id representing the target of this connection
dsnpId: string
// Indicator connection type (public or private)
privacyType: enum[private, public]
// Indicator of the direction of this connection
direction: enum[connectionTo, connectionFrom, bidirectional, disconnect]
// Indicator of the type of connection (follow or friendship)
connectionType: enum[follow, friendship]
}[]
}
#/components/schemas/ProviderGraphDto
{
// MSA Id that owns the connections represented in this object
dsnpId: string
// Array of connections known to the Provider for ths MSA referenced in this object
connections: #/components/schemas/ConnectionDtoWrapper
graphKeyPairs: {
// Public graph encryption key as a hex string (prefixed with "0x")
publicKey: string
// Private graph encryption key as a hex string (prefixed with "0x")
privateKey: string
// Key type of graph encryption keypair (currently only X25519 supported)
keyType: enum[X25519]
}[]
// Optional URL of a webhook to invoke when the request is complete
webhookUrl?: string
}
#/components/schemas/GraphChangeRepsonseDto
{
// Reference ID by which the results/status of a submitted GraphChangeRequest may be retrieved
referenceId: string
}
#/components/schemas/WatchGraphsDto
{
dsnpIds?: string[]
// Webhook URL to call when graph changes for the referenced MSAs are detected
webhookEndpoint: string
}
Configuration
ℹ️ Feel free to adjust your environment variables to taste. This application recognizes the following environment variables:
Name | Description | Range/Type | Required? | Default |
---|---|---|---|---|
API_PORT | HTTP port that the application listens on | 1025 - 65535 | 3000 | |
BLOCKCHAIN_SCAN_INTERVAL_SECONDS | How many seconds to delay between successive scans of the chain (after end of chain is reached) | > 0 | 180 | |
CACHE_KEY_PREFIX | Prefix to use for Redis cache keys | string | content-watcher: | |
CAPACITY_LIMIT | Maximum amount of provider capacity this app is allowed to use (per epoch) type: 'percentage' 'amount' value: number (may be percentage, ie '80', or absolute amount of capacity) | JSON (example) | Y | |
DEBOUNCE_SECONDS | Number of seconds to retain pending graph updates in the Redis cache to avoid redundant fetches from the chain | >= 0 | ||
FREQUENCY_URL | Blockchain node address | http(s): or ws(s): URL | Y | |
GRAPH_ENVIRONMENT_TYPE | Graph environment type. | Mainnet|TestnetPaseo | Y | |
HEALTH_CHECK_MAX_RETRIES | Number of /health endpoint failures allowed before marking the provider webhook service down | >= 0 | 20 | |
HEALTH_CHECK_MAX_RETRY_INTERVAL_SECONDS | Number of seconds to retry provider webhook /health endpoint when failing | > 0 | 64 | |
HEALTH_CHECK_SUCCESS_THRESHOLD | Minimum number of consecutive successful calls to the provider webhook /health endpoint before it is marked up again | > 0 | 10 | |
PROVIDER_ACCOUNT_SEED_PHRASE | Seed phrase for provider MSA control key | string | Y | |
PROVIDER_ID | Provider MSA Id | integer | Y | |
QUEUE_HIGH_WATER | Max number of jobs allowed on the 'graphUpdateQueue' before blockchain scan will be paused to allow queue to drain | >= 100 | 1000 | |
RECONNECTION_SERVICE_REQUIRED | Whether to instantiate/activate reconnection-service features | true/false | ||
REDIS_URL | Connection URL for Redis | URL | Y |
The following environment variables are only relevant if RECONNECTION_SERVICE_REQUESTED
is 'true':
Name | Description | Range/Type | Required? | Default |
---|---|---|---|---|
CONNECTIONS_PER_PROVIDER_RESPONSE_PAGE | Number of connection/page to request when requesting provider connections from webhook | > 0 | 100 | |
PROVIDER_ACCESS_TOKEN | An optional bearer token authentication to the provider webhook | string | ||
PROVIDER_BASE_URL | Base URL for provider webhook endpoints | URL | Y | |
WEBHOOK_FAILURE_THRESHOLD | Number of failures allowed in the provider webhook before the service is marked down | > 0 | 3 | |
WEBHOOK_RETRY_INTERVAL_SECONDS | Number of seconds between provider webhook retry attempts when failing | > 0 | 10 |
Best Practices
- Data Integrity: Ensure the integrity of social graph data by implementing robust validation checks.
- Efficient Queries: Optimize queries to handle large social graphs efficiently.
- User Privacy: Protect user privacy by ensuring that graph data is only accessible to authorized entities.