Auto-indexing service and GraphQL API for AT Protocol Records
at validation 220 lines 3.1 kB view raw view rendered
1# Variables 2 3GraphQL variables parameterize queries and mutations for reusability and security. 4 5## Basic Variables 6 7### Query with Variables 8 9```graphql 10query GetStatusByEmoji($emoji: String!) { 11 xyzStatusphereStatus(where: { 12 status: { eq: $emoji } 13 }) { 14 edges { 15 node { 16 uri 17 status 18 createdAt 19 } 20 } 21 } 22} 23``` 24 25Variables: 26 27```json 28{ 29 "emoji": "🎉" 30} 31``` 32 33### Mutation with Variables 34 35```graphql 36mutation CreateStatus($statusEmoji: String!, $timestamp: String!) { 37 createXyzStatusphereStatus( 38 input: { 39 status: $statusEmoji 40 createdAt: $timestamp 41 } 42 ) { 43 uri 44 status 45 createdAt 46 } 47} 48``` 49 50Variables: 51 52```json 53{ 54 "statusEmoji": "🚀", 55 "timestamp": "2025-01-30T12:00:00Z" 56} 57``` 58 59## Multiple Variables 60 61```graphql 62query GetFilteredStatuses( 63 $emoji: String! 64 $pageSize: Int! 65 $cursor: String 66) { 67 xyzStatusphereStatus( 68 where: { status: { eq: $emoji } } 69 first: $pageSize 70 after: $cursor 71 sortBy: [{ field: createdAt, direction: DESC }] 72 ) { 73 edges { 74 node { 75 uri 76 status 77 createdAt 78 } 79 cursor 80 } 81 pageInfo { 82 hasNextPage 83 endCursor 84 } 85 totalCount 86 } 87} 88``` 89 90Variables: 91 92```json 93{ 94 "emoji": "✨", 95 "pageSize": 10, 96 "cursor": null 97} 98``` 99 100## Optional Variables 101 102Use default values for optional variables: 103 104```graphql 105query GetProfiles( 106 $name: String = "" 107 $pageSize: Int = 20 108) { 109 appBskyActorProfile( 110 where: { displayName: { contains: $name } } 111 first: $pageSize 112 ) { 113 edges { 114 node { 115 displayName 116 description 117 } 118 } 119 } 120} 121``` 122 123Variables: 124 125```json 126{ 127 "name": "alice" 128} 129``` 130 131Or omit variables to use defaults: 132 133```json 134{} 135``` 136 137## Blob Upload with Variables 138 139```graphql 140mutation UploadImage($imageData: String!, $type: String!) { 141 uploadBlob( 142 data: $imageData 143 mimeType: $type 144 ) { 145 ref 146 mimeType 147 size 148 } 149} 150``` 151 152Variables: 153 154```json 155{ 156 "imageData": "base64EncodedImageData...", 157 "type": "image/jpeg" 158} 159``` 160 161## Update Profile with Variables 162 163```graphql 164mutation UpdateProfile( 165 $name: String! 166 $bio: String! 167 $avatarRef: String! 168 $avatarType: String! 169 $avatarSize: Int! 170) { 171 updateAppBskyActorProfile( 172 rkey: "self" 173 input: { 174 displayName: $name 175 description: $bio 176 avatar: { 177 ref: $avatarRef 178 mimeType: $avatarType 179 size: $avatarSize 180 } 181 } 182 ) { 183 uri 184 displayName 185 description 186 avatar { 187 ref 188 url(preset: "avatar") 189 } 190 } 191} 192``` 193 194Variables: 195 196```json 197{ 198 "name": "Alice Smith", 199 "bio": "Software engineer & designer", 200 "avatarRef": "bafkreiabc123...", 201 "avatarType": "image/jpeg", 202 "avatarSize": 125000 203} 204``` 205 206## Using in HTTP Requests 207 208Send variables in the HTTP request body: 209 210```bash 211curl -X POST http://localhost:8080/graphql \ 212 -H "Content-Type: application/json" \ 213 -H "Authorization: Bearer <token>" \ 214 -d '{ 215 "query": "query GetStatus($emoji: String!) { xyzStatusphereStatus(where: { status: { eq: $emoji } }) { edges { node { status } } } }", 216 "variables": { 217 "emoji": "🎉" 218 } 219 }' 220```