Last active
May 15, 2024 22:32
-
-
Save Yuripetusko/59f3b1e2d30d08098231b32a1cefcb45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { graphqlRmrkIndexer } from 'lib/graphql/graphql-client'; | |
export const getPlotByIdQuery = graphqlRmrkIndexer( | |
` | |
query GetPlotByIdData($plotId: String!) { | |
nftById(id: $plotId) { | |
...NftFragment | |
} | |
} | |
`, | |
[NftFragment], | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GraphQLClient } from 'graphql-request'; | |
import { NEXT_PUBLIC_GRAPHQL_HTTP_URL_EVM } from 'lib/app/graphql'; | |
import { initGraphQLTada } from 'gql.tada'; | |
import type { introspection } from './rmrk-evm-indexer-env'; | |
export const gqlClient = new GraphQLClient(NEXT_PUBLIC_GRAPHQL_HTTP_URL_EVM ?? ''); | |
export const graphqlRmrkIndexer = initGraphQLTada<{ | |
introspection: introspection; | |
}>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { graphqlRmrkIndexer } from 'lib/graphql/graphql-client'; | |
export const NftFragment = graphqlRmrkIndexer(` | |
fragment NftFragment on Nft { | |
collection { | |
id | |
} | |
id | |
isTransferable | |
owner | |
activeAssetIds | |
pending | |
priorities | |
equipmentUpdatedAt | |
metadata | |
burned | |
lastTransferabilityCheckAt | |
} | |
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"scripts": { | |
"get-graphql-schema": "source .env.local && get-graphql-schema $NEXT_PUBLIC_GRAPHQL_HTTP_URL_DEV_EVM > lib/graphql/schema.graphql", | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"extends": "./tsconfig.base.json", | |
"compilerOptions": { | |
"strict": true, | |
"noFallthroughCasesInSwitch": true, | |
"noImplicitOverride": true, | |
"noImplicitReturns": true, | |
"noUncheckedIndexedAccess": true, | |
"noUnusedLocals": false, | |
"noUnusedParameters": false, | |
"useDefineForClassFields": true, | |
"useUnknownInCatchVariables": true, | |
"checkJs": false, | |
"verbatimModuleSyntax": true, | |
"noErrorTruncation": true, | |
"module": "esnext", | |
"target": "ES2019", | |
"lib": [ | |
"dom", | |
"dom.iterable", | |
"esnext" | |
], | |
"jsx": "preserve", | |
"baseUrl": "./", | |
"moduleResolution": "node", | |
"allowJs": true, | |
"noEmit": true, | |
"allowSyntheticDefaultImports": true, | |
"isolatedModules": true, | |
"esModuleInterop": true, | |
"skipLibCheck": true, | |
"forceConsistentCasingInFileNames": true, | |
"resolveJsonModule": true, | |
"plugins": [ | |
{ | |
"name": "next" | |
}, | |
{ | |
"name": "@0no-co/graphqlsp", | |
"schemas": [ | |
{ | |
"name": "rmrk-evm-indexer", | |
"schema": "./lib/graphql/schema.graphql", | |
"tadaOutputLocation": "./lib/graphql/rmrk-evm-indexer-env.d.ts", | |
"shouldCheckForColocatedFragments": false | |
}, | |
{ | |
"name": "skybreach-land-indexer", | |
"schema": "./lib/graphql-subsquid/schema.graphql", | |
"tadaOutputLocation": "./lib/graphql-subsquid/skybreach-land-indexer-env.d.ts", | |
"shouldCheckForColocatedFragments": false | |
} | |
] | |
}, | |
], | |
"paths": { | |
"styled-system/*": [ | |
"styled-system/*" | |
], | |
"lib/*": [ | |
"lib/*" | |
], | |
"components/*": [ | |
"components/*" | |
], | |
"contracts/*": [ | |
"contracts/*" | |
] | |
} | |
}, | |
"exclude": [ | |
"node_modules" | |
], | |
"include": [ | |
"next-env.d.ts", | |
"**/*.ts", | |
"**/*.tsx", | |
".next/types/**/*.ts" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useQueries, useQuery } from '@tanstack/react-query'; | |
import { gqlClient } from 'lib/graphql/graphql-client'; | |
import { getPlotByIdQuery } from 'lib/graphql/queries/get-plot-data'; | |
import { nftFragmentToObject } from 'lib/graphql/nft-fragment-to-object'; | |
export const useGetPlot = ({ plotId, enabled = true }: { plotId: number; enabled?: boolean }) => { | |
return useQuery({ | |
queryKey: ['plots', plotId], | |
queryFn: async () => { | |
const data = await gqlClient.request(getPlotByIdQuery, { | |
plotId: getTokenDatabaseId({ tokenId: plotId }), | |
}); | |
return data?.nftById | |
? addPlotStatsToIndexedPlotData(plotId, nftFragmentToObject(data.nftById)) | |
: undefined; | |
}, | |
enabled, | |
}); | |
}; | |
const { | |
data: plotData, | |
isLoading, | |
isError, | |
error, | |
} = useGetPlot({ plotId: plotId || 0, enabled: !!plotId }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment