Skip to content

Commit

Permalink
try urql instead of graphql-request
Browse files Browse the repository at this point in the history
  • Loading branch information
artlu99 committed Nov 1, 2024
1 parent 1fb97dc commit 9421da3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
13 changes: 8 additions & 5 deletions functions/getSassyHashes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GraphQLClient, gql } from 'graphql-request';
import { Client, fetchExchange, gql } from '@urql/core';

import { Env } from '../common';

interface SassyHash {
Expand All @@ -8,20 +9,22 @@ interface SassyHash {
isDecrypted: boolean;
}
interface SassyHashGraphQLResponse {
data: { getTextByCastHash: SassyHash };
getTextByCastHash: SassyHash;
}
interface SassyHashRequest {
fid: number;
castHash: string;
}

const fetchSassyHashExpensiveApi = async (fid: number, castHash: string, env: Env) => {
const graphQLClient = new GraphQLClient(env.SASSYHASH_API, {
headers: { authorization: `Bearer ${env.WHISTLES_BEARER_TOKEN}` },
const client = new Client({
url: env.SASSYHASH_API,
exchanges: [fetchExchange],
fetchOptions: { headers: { authorization: `Bearer ${env.WHISTLES_BEARER_TOKEN}` } },
});

try {
const res = await graphQLClient.request<SassyHashGraphQLResponse>(
const res = await client.query<SassyHashGraphQLResponse>(
gql`
query getTextByCastHash($castHash: String!, $viewerFid: Int!) {
getTextByCastHash(castHash: $castHash, viewerFid: $viewerFid) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@tanstack/react-query": "^5.45.0",
"@tanstack/react-query-persist-client": "^5.45.0",
"@upstash/redis": "^1.31.4",
"@urql/core": "^5.0.8",
"antd": "^4.22.4",
"antd-mask-input": "^2.0.7",
"antd-style": "^3.6.2",
Expand All @@ -27,7 +28,6 @@
"echarts-for-react": "^3.0.1",
"elt-react-credit-cards": "^0.0.1",
"exponential-backoff": "^3.1.1",
"graphql-request": "^7.1.1",
"i18next": "^20.4.0",
"idb-keyval": "^6.2.1",
"lucide-react": "^0.394.0",
Expand Down
51 changes: 30 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ __metadata:
version: 5
cacheKey: 8

"@0no-co/graphql.web@npm:^1.0.5":
version: 1.0.10
resolution: "@0no-co/graphql.web@npm:1.0.10"
peerDependencies:
graphql: ^14.0.0 || ^15.0.0 || ^16.0.0
peerDependenciesMeta:
graphql:
optional: true
checksum: d271a3cbf82ac4691d695053a385a1682c5792c7f3c01fa254c0616fd727297f3d19d3a32420dfe701aafd25dde8f093c8a6380de0ff35cce2790539ecbbf8e0
languageName: node
linkType: hard

"@adraffy/ens-normalize@npm:1.10.0":
version: 1.10.0
resolution: "@adraffy/ens-normalize@npm:1.10.0"
Expand Down Expand Up @@ -3284,15 +3296,6 @@ __metadata:
languageName: node
linkType: hard

"@graphql-typed-document-node/core@npm:^3.2.0":
version: 3.2.0
resolution: "@graphql-typed-document-node/core@npm:3.2.0"
peerDependencies:
graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0
checksum: fa44443accd28c8cf4cb96aaaf39d144a22e8b091b13366843f4e97d19c7bfeaf609ce3c7603a4aeffe385081eaf8ea245d078633a7324c11c5ec4b2011bb76d
languageName: node
linkType: hard

"@grpc/grpc-js@npm:~1.8.21":
version: 1.8.22
resolution: "@grpc/grpc-js@npm:1.8.22"
Expand Down Expand Up @@ -5052,6 +5055,16 @@ __metadata:
languageName: node
linkType: hard

"@urql/core@npm:^5.0.8":
version: 5.0.8
resolution: "@urql/core@npm:5.0.8"
dependencies:
"@0no-co/graphql.web": ^1.0.5
wonka: ^6.3.2
checksum: 2e0e1791e49585c5a28d24640d8585b8ff663e2feda73ea344a9ab213ca760466293ea16fa9a7bbc104c1ddeb1d61d320a45fda84a44f3b124b06767323df4c6
languageName: node
linkType: hard

"@vitejs/plugin-react@npm:^4.3.0":
version: 4.3.0
resolution: "@vitejs/plugin-react@npm:4.3.0"
Expand Down Expand Up @@ -5847,6 +5860,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": ^5.10.0
"@typescript-eslint/parser": ^5.8.0
"@upstash/redis": ^1.31.4
"@urql/core": ^5.0.8
"@vitejs/plugin-react": ^4.3.0
antd: ^4.22.4
antd-mask-input: ^2.0.7
Expand All @@ -5865,7 +5879,6 @@ __metadata:
eslint-plugin-react: ^7.24.0
eslint-plugin-react-hooks: ^4.3.0
exponential-backoff: ^3.1.1
graphql-request: ^7.1.1
husky: ^9.0.11
i18next: ^20.4.0
idb-keyval: ^6.2.1
Expand Down Expand Up @@ -8328,17 +8341,6 @@ __metadata:
languageName: node
linkType: hard

"graphql-request@npm:^7.1.1":
version: 7.1.1
resolution: "graphql-request@npm:7.1.1"
dependencies:
"@graphql-typed-document-node/core": ^3.2.0
peerDependencies:
graphql: 14 - 16
checksum: b47b310a3c0b701828d268621a81d71864236fc5959f6ab4f9c3b03f6955f92abdbcf444de39f08776ac498895c7d958957a261f1082d448159218ed83da3157
languageName: node
linkType: hard

"gzip-size@npm:^6.0.0":
version: 6.0.0
resolution: "gzip-size@npm:6.0.0"
Expand Down Expand Up @@ -14724,6 +14726,13 @@ __metadata:
languageName: node
linkType: hard

"wonka@npm:^6.3.2":
version: 6.3.4
resolution: "wonka@npm:6.3.4"
checksum: 6bb57955cb2982fb469a7824484e6854b436f89a7f10b6a981348789d88fbc944665771adc4cc404f62416417eb47ab2b8657d898e5301ccd4a53eaac6a10508
languageName: node
linkType: hard

"word-wrap@npm:^1.2.5":
version: 1.2.5
resolution: "word-wrap@npm:1.2.5"
Expand Down

0 comments on commit 9421da3

Please sign in to comment.