ATProto <=> GraphQL Bridge#
A bridge between ATProto (server-side) and GraphQL (client-side) for developing efficient UIs for the ATmosphere.
Note: This is a demonstration. Support for simple ATproto procedures and types is supported, but full support requires more work.
Installation:
npm install
Schema Generation#
This project uses @atproto/lex to download Lexicons and generate xRPC calls that are used in the backend.
Example usage:
ts-lex install app.bsky.actor.getProfile com.atproto.server.getSession
npm run generate
This will generate schema definitions for the getProfile and getSession procedures and recursively import all their referenced types, e.g.
type Lexicon_app_bsky_actor {
getProfile(actor: ID!): Lexicon_app_bsky_actor_defs_profileViewDetailed
}
# app.bsky.actor.defs#profileViewDetailed
type Lexicon_app_bsky_actor_defs_profileViewDetailed {
did: ID!
handle: ID!
displayName: String
description: String
pronouns: String
website: String
avatar: String
banner: String
followersCount: Int
followsCount: Int
postsCount: Int
associated: Lexicon_app_bsky_actor_defs_profileAssociated
joinedViaStarterPack: Lexicon_app_bsky_graph_defs_starterPackViewBasic
indexedAt: String
createdAt: String
viewer: Lexicon_app_bsky_actor_defs_viewerState
labels: [Lexicon_com_atproto_label_defs_label!]
pinnedPost: Lexicon_com_atproto_repo_strongRef
verification: Lexicon_app_bsky_actor_defs_verificationState
status: Lexicon_app_bsky_actor_defs_statusView
}
# ...
Example GraphQL Server#
This repo also contains a Rust GraphQL server that can bridge an exported schema to the AT protocol. You can use this as a reference or even expand it to include non-AT GraphQL types.
- GraphQL API endpoint at
/graphql - Interactive GraphiQL interface for development at
/graphiql
Building#
npm run server
The server will start on http://localhost:8000. An example query and variables:
# Query
query ($actor: ID!) {
lexicon {
app {
bsky {
actor {
getProfile(actor: $actor) {
avatar
postsCount
description
displayName
}
}
}
}
}
}
# Variables
{
"actor": "did:plc:olka44iewlycp4vxa6srsabp"
}
# Response
{
"data": {
"lexicon": {
"app": {
"bsky": {
"actor": {
"getProfile": {
"avatar": "https://cdn.bsky.app/img/avatar/plain/did:plc:olka44iewlycp4vxa6srsabp/bafkreicozgr2pxfq5cdnfxlhrc6si3sunraekbp2pccqukvh6dapr4en5i",
"postsCount": 374,
"description": "browser tab collector\nnon-recurring engineer\nsomerville, ma",
"displayName": "tim ryan"
}
}
}
}
}
}
}
License#
MIT