lens_client/graphql/
queries.rs

1pub struct Queries {
2    pub profile: Profile,
3    pub follow: Follow,
4    pub user: User,
5}
6
7pub struct Profile {
8    pub create_profile: String,
9    pub get_default_profile: String,
10    pub get_profiles: String,
11}
12
13pub struct Follow {
14    pub does_follow: String,
15    pub get_following: String,
16    pub get_followers: String,
17}
18
19pub struct Module {
20    pub follow_module: String,
21    pub fee_follow_module: String,
22}
23
24pub struct User {
25    pub challenge: String,
26    pub login: String,
27}
28
29impl Module {
30    pub fn new() -> Module {
31        Module {
32            follow_module: String::from(
33                r#"{
34                freeFollowModule: true
35             }"#,
36            ),
37            fee_follow_module: String::from(
38                r#"{
39                feeFollowModule: {
40                       amount: {
41                           currency: "%%CURRENCY%%",
42                           value: "%%VALUE%%"
43                       },
44                       recipient: "%%RECIPIENT%%"
45                }
46            }"#,
47            ),
48        }
49    }
50}
51
52/// The GraphQL queries are hardcoded as templates here.
53/// Could be probably smarter using a proper library for this
54/// but this is a quick and dirty solution.
55impl Queries {
56    pub fn new() -> Queries {
57        Queries {
58            profile: Profile {
59                create_profile: String::from(
60                    r#"mutation CreateProfile {
61                    createProfile(request:{ 
62                                  handle: "%%HANDLE%%",
63                                  profilePictureUri: null,
64                                  followNFTURI: null,
65                                  followModule: %%FOLLOW_MODULE%%
66                                  }) {
67                      ... on RelayerResult {
68                        txHash
69                      }
70                      ... on RelayError {
71                        reason
72                      }
73                      __typename
74                    }
75                  }"#,
76                ),
77                get_default_profile: String::from(
78                    r#"query DefaultProfile {
79                    defaultProfile(request: { ethereumAddress: "%%ADDRESS%%"}) {
80                      id
81                      name
82                      bio
83                      isDefault
84                      attributes {
85                        displayType
86                        traitType
87                        key
88                        value
89                      }
90                      metadata
91                      handle
92                      picture {
93                        ... on NftImage {
94                          contractAddress
95                          tokenId
96                          uri
97                          chainId
98                          verified
99                        }
100                        ... on MediaSet {
101                          original {
102                            url
103                            mimeType
104                          }
105                        }
106                      }
107                      coverPicture {
108                        ... on NftImage {
109                          contractAddress
110                          tokenId
111                          uri
112                          chainId
113                          verified
114                        }
115                        ... on MediaSet {
116                          original {
117                            url
118                            mimeType
119                          }
120                        }
121                      }
122                      ownedBy
123                      dispatcher {
124                        address
125                        canUseRelay
126                      }
127                      stats {
128                        totalFollowers
129                        totalFollowing
130                        totalPosts
131                        totalComments
132                        totalMirrors
133                        totalPublications
134                        totalCollects
135                      }
136                      followModule {
137                        ... on FeeFollowModuleSettings {
138                          type
139                          contractAddress
140                          amount {
141                            asset {
142                              name
143                              symbol
144                              decimals
145                              address
146                            }
147                            value
148                          }
149                          recipient
150                        }
151                        ... on ProfileFollowModuleSettings {
152                         type
153                        }
154                        ... on RevertFollowModuleSettings {
155                         type
156                        }
157                      }
158                    }
159                  }"#,
160                ),
161                get_profiles: String::from(
162                    r#"query Profiles {
163                    profiles(request: { ownedBy: ["%%ADDRESS%%"], limit: 10 }) {
164                      items {
165                        id
166                        name
167                        bio
168                        attributes {
169                          displayType
170                          traitType
171                          key
172                          value
173                        }
174                        metadata
175                        isDefault
176                        picture {
177                          ... on NftImage {
178                            contractAddress
179                            tokenId
180                            uri
181                            verified
182                          }
183                          ... on MediaSet {
184                            original {
185                              url
186                              mimeType
187                            }
188                          }
189                          __typename
190                        }
191                        handle
192                        coverPicture {
193                          ... on NftImage {
194                            contractAddress
195                            tokenId
196                            uri
197                            verified
198                          }
199                          ... on MediaSet {
200                            original {
201                              url
202                              mimeType
203                            }
204                          }
205                          __typename
206                        }
207                        ownedBy
208                        dispatcher {
209                          address
210                          canUseRelay
211                        }
212                        stats {
213                          totalFollowers
214                          totalFollowing
215                          totalPosts
216                          totalComments
217                          totalMirrors
218                          totalPublications
219                          totalCollects
220                        }
221                        followModule {
222                          ... on FeeFollowModuleSettings {
223                            type
224                            amount {
225                              asset {
226                                symbol
227                                name
228                                decimals
229                                address
230                              }
231                              value
232                            }
233                            recipient
234                          }
235                          ... on ProfileFollowModuleSettings {
236                           type
237                          }
238                          ... on RevertFollowModuleSettings {
239                           type
240                          }
241                        }
242                      }
243                      pageInfo {
244                        prev
245                        next
246                        totalCount
247                      }
248                    }
249                  }"#,
250                ),
251            },
252            follow: Follow {
253                does_follow: String::from(
254                    r#"query DoesFollow {
255                    doesFollow(request: { 
256                                  followInfos: [
257                                    {
258                                      followerAddress: "%%ADDRESS%%",
259                                      profileId: "%%PROFILE_ID%%"
260                                    }
261                                  ] 
262                               }) {
263                      followerAddress
264                      profileId
265                      follows
266                    }
267                  }"#,
268                ),
269                get_following: String::from(
270                    r#"query Following {
271                    following(request: { 
272                                  address: "%%ADDRESS%%",
273                                limit: %%LIMIT%%
274                               }) {
275                      items {
276                        profile {
277                          id
278                          name
279                          bio
280                          attributes {
281                              displayType
282                              traitType
283                              key
284                              value
285                          }
286                          metadata
287                          isDefault
288                          handle
289                          picture {
290                            ... on NftImage {
291                              contractAddress
292                              tokenId
293                              uri
294                              verified
295                            }
296                            ... on MediaSet {
297                              original {
298                                url
299                                width
300                                height
301                                mimeType
302                              }
303                              medium {
304                                url
305                                width
306                                height
307                                mimeType
308                              }
309                              small {
310                                url
311                                width
312                                height
313                                mimeType
314                              }
315                            }
316                          }
317                          coverPicture {
318                            ... on NftImage {
319                              contractAddress
320                              tokenId
321                              uri
322                              verified
323                            }
324                            ... on MediaSet {
325                              original {
326                                url
327                                width
328                                height
329                                mimeType
330                              }
331                              small {
332                                width
333                                url
334                                height
335                                mimeType
336                              }
337                              medium {
338                                url
339                                width
340                                height
341                                mimeType
342                              }
343                            }
344                          }
345                          ownedBy
346                          dispatcher {
347                            address
348                            canUseRelay
349                          }
350                          stats {
351                            totalFollowers
352                            totalFollowing
353                            totalPosts
354                            totalComments
355                            totalMirrors
356                            totalPublications
357                            totalCollects
358                          }
359                          followModule {
360                            ... on FeeFollowModuleSettings {
361                              type
362                              amount {
363                                asset {
364                                  name
365                                  symbol
366                                  decimals
367                                  address
368                                }
369                                value
370                              }
371                              recipient
372                            }
373                            ... on ProfileFollowModuleSettings {
374                             type
375                            }
376                            ... on RevertFollowModuleSettings {
377                             type
378                            }
379                          }
380                        }
381                        totalAmountOfTimesFollowing
382                      }
383                      pageInfo {
384                        prev
385                        next
386                        totalCount
387                      }
388                    }
389                  }"#,
390                ),
391                get_followers: String::from(
392                    r#"query Followers {
393                    followers(request: { 
394                                  profileId: "%%PROFILE_ID%%",
395                                limit: %%LIMIT%%
396                               }) {
397                         items {
398                        wallet {
399                          address
400                          defaultProfile {
401                            id
402                            name
403                            bio
404                            attributes {
405                              displayType
406                              traitType
407                              key
408                              value
409                            }
410                              metadata
411                            isDefault
412                            handle
413                            picture {
414                              ... on NftImage {
415                                contractAddress
416                                tokenId
417                                uri
418                                verified
419                              }
420                              ... on MediaSet {
421                                original {
422                                  url
423                                  mimeType
424                                }
425                              }
426                            }
427                            coverPicture {
428                              ... on NftImage {
429                                contractAddress
430                                tokenId
431                                uri
432                                verified
433                              }
434                              ... on MediaSet {
435                                original {
436                                  url
437                                  mimeType
438                                }
439                              }
440                            }
441                            ownedBy
442                            dispatcher {
443                              address
444                              canUseRelay
445                            }
446                            stats {
447                              totalFollowers
448                              totalFollowing
449                              totalPosts
450                              totalComments
451                              totalMirrors
452                              totalPublications
453                              totalCollects
454                            }
455                            followModule {
456                              ... on FeeFollowModuleSettings {
457                                type
458                                contractAddress
459                                amount {
460                                  asset {
461                                    name
462                                    symbol
463                                    decimals
464                                    address
465                                  }
466                                  value
467                                }
468                                recipient
469                              }
470                              ... on ProfileFollowModuleSettings {
471                               type
472                              }
473                              ... on RevertFollowModuleSettings {
474                               type
475                              }
476                            }
477                          }
478                        }
479                        totalAmountOfTimesFollowed
480                      }
481                      pageInfo {
482                        prev
483                        next
484                        totalCount
485                      }
486                    }
487                  }"#,
488                ),
489            },
490            user: User {
491                challenge: String::from(
492                    r#"query Challenge {
493                    challenge(request: { address: "%%ADDRESS%%" }) {
494                      text
495                    }
496                  }"#,
497                ),
498                login: String::from(
499                    r#"mutation Authenticate {
500                  authenticate(request: {
501                    address: "%%ADDRESS%%",
502                    signature: "%%SIGNATURE%%"
503                  }) {
504                    accessToken
505                    refreshToken
506                  }
507                }"#,
508                ),
509            },
510        }
511    }
512}