Demonstration bridge between ATproto and GraphQL. Generate schema types and interface with the ATmosphere via GraphQL queries. Includes a TypeScript server with IDE.
1# ATProto <=> GraphQL Bridge
2
3A bridge between ATProto (server-side) and GraphQL (client-side) for developing efficient UIs for the ATmosphere.
4
5> Note: This is a demonstration. Support for simple ATproto procedures and types is supported, but full support requires more work.
6
7**Installation:**
8
9```
10npm install
11```
12
13## Schema Generation
14
15This project uses [@atproto/lex](https://www.npmjs.com/package/@atproto/lex-cli) to download Lexicons and generate xRPC calls that are used in the backend.
16
17Example usage:
18
19```
20ts-lex install app.bsky.actor.getProfile com.atproto.server.getSession
21npm run generate
22```
23
24This will generate schema definitions for the `getProfile` and `getSession` procedures and recursively import all their referenced types, e.g.
25
26```
27type Lexicon_app_bsky_actor {
28 getProfile(actor: ID!): Lexicon_app_bsky_actor_defs_profileViewDetailed
29}
30
31# app.bsky.actor.defs#profileViewDetailed
32type Lexicon_app_bsky_actor_defs_profileViewDetailed {
33 did: ID!
34 handle: ID!
35 displayName: String
36 description: String
37 pronouns: String
38 website: String
39 avatar: String
40 banner: String
41 followersCount: Int
42 followsCount: Int
43 postsCount: Int
44 associated: Lexicon_app_bsky_actor_defs_profileAssociated
45 joinedViaStarterPack: Lexicon_app_bsky_graph_defs_starterPackViewBasic
46 indexedAt: String
47 createdAt: String
48 viewer: Lexicon_app_bsky_actor_defs_viewerState
49 labels: [Lexicon_com_atproto_label_defs_label!]
50 pinnedPost: Lexicon_com_atproto_repo_strongRef
51 verification: Lexicon_app_bsky_actor_defs_verificationState
52 status: Lexicon_app_bsky_actor_defs_statusView
53}
54
55# ...
56```
57
58
59## Example GraphQL Server
60
61This 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.
62
63- GraphQL API endpoint at `/graphql`
64- Interactive GraphiQL interface for development at `/graphiql`
65
66### Building
67
68```bash
69npm run server
70```
71
72The server will start on `http://localhost:8000`. An example query and variables:
73
74```
75# Query
76query ($actor: ID!) {
77 lexicon {
78 app {
79 bsky {
80 actor {
81 getProfile(actor: $actor) {
82 avatar
83 postsCount
84 description
85 displayName
86 }
87 }
88 }
89 }
90 }
91}
92
93# Variables
94{
95 "actor": "did:plc:olka44iewlycp4vxa6srsabp"
96}
97
98# Response
99{
100 "data": {
101 "lexicon": {
102 "app": {
103 "bsky": {
104 "actor": {
105 "getProfile": {
106 "avatar": "https://cdn.bsky.app/img/avatar/plain/did:plc:olka44iewlycp4vxa6srsabp/bafkreicozgr2pxfq5cdnfxlhrc6si3sunraekbp2pccqukvh6dapr4en5i",
107 "postsCount": 374,
108 "description": "browser tab collector\nnon-recurring engineer\nsomerville, ma",
109 "displayName": "tim ryan"
110 }
111 }
112 }
113 }
114 }
115 }
116}
117```
118
119## License
120
121MIT