11import { useState } from 'react' ;
22import { ConnectKitButton , useModal } from 'connectkit' ;
3- import { graphql } from 'gql.tada' ;
43import { useForm } from 'react-hook-form' ;
54import semver from 'semver' ;
65import { Address } from 'viem' ;
@@ -129,9 +128,9 @@ const Manifest = z.object({
129128 repository : z . string ( ) . describe ( 'An optional link to where the subgraph lives.' ) . optional ( ) ,
130129} ) ;
131130
132- const GetSubgraphInfo = graphql ( /* GraphQL */ `
133- query GetSubgraphInfo($subgraphId: ID!) {
134- subgraph(id: $ subgraphId) {
131+ const GetSubgraphInfo = ( subgraphId : string ) => `
132+ {
133+ subgraph(id: " ${ subgraphId } " ) {
135134 id
136135 owner {
137136 id
@@ -155,7 +154,7 @@ const GetSubgraphInfo = graphql(/* GraphQL */ `
155154 }
156155 }
157156 }
158- ` ) ;
157+ ` ;
159158
160159function getEtherscanUrl ( { chainId, hash } : { chainId : number ; hash : string } ) {
161160 switch ( chainId ) {
@@ -172,10 +171,12 @@ function DeploySubgraph({
172171 deploymentId,
173172 subgraphId,
174173 network,
174+ apiKey
175175} : {
176176 deploymentId : string ;
177177 subgraphId : string | undefined ;
178178 network : ( typeof CHAINS ) [ number ] | undefined ;
179+ apiKey : string | undefined ;
179180} ) {
180181 const { writeContractAsync, isPending, error : contractError } = useWriteContract ( { } ) ;
181182 const { setOpen } = useModal ( ) ;
@@ -214,20 +215,31 @@ function DeploySubgraph({
214215 const chain = form . watch ( 'chain' ) ;
215216
216217 const { data : subgraphInfo } = useQuery ( {
217- queryKey : [ 'subgraph-info' , subgraphId , chain , chainId ] ,
218+ queryKey : [ 'subgraph-info' , subgraphId , chain , chainId , apiKey ] ,
218219 queryFn : async ( ) => {
219- if ( ! subgraphId ) return ;
220+ if ( ! subgraphId ) {
221+ toast ( {
222+ description : 'Subgraph ID is missing. Please add it to the URL params and try again.' ,
223+ variant : 'destructive' ,
224+ } ) ;
225+ return ;
226+ }
227+ if ( ! apiKey ) {
228+ toast ( {
229+ description : "apiKey is missing in URL params. Please add it to the URL params and try again." ,
230+ variant : 'destructive' ,
231+ } ) ;
232+ return ;
233+ }
220234
221235 const subgraphEndpoint = chain ? getChainInfo ( chain ) ?. subgraph : null ;
222236
223237 if ( ! subgraphEndpoint ) return ;
224238
225239 const data = await networkSubgraphExecute (
226- GetSubgraphInfo ,
227- { subgraphId } ,
228- {
229- endpoint : subgraphEndpoint ,
230- } ,
240+ GetSubgraphInfo ( subgraphId ) ,
241+ subgraphEndpoint ,
242+ apiKey
231243 ) ;
232244
233245 const metadata = data . subgraph ?. metadata ;
@@ -264,7 +276,7 @@ function DeploySubgraph({
264276 const version = form . watch ( 'versionLabel' ) ;
265277
266278 const versionInfo = subgraphInfo . subgraph ?. versions . find (
267- ( { metadata } ) => metadata ?. label === version ,
279+ ( { metadata } : { metadata : { label : string } } ) => metadata ?. label === version ,
268280 ) ;
269281
270282 if ( ! versionInfo ) return false ;
@@ -280,7 +292,7 @@ function DeploySubgraph({
280292
281293 const version = form . watch ( 'versionLabel' ) ;
282294
283- return ! subgraphInfo . subgraph ?. versions . some ( ( { metadata } ) => metadata ?. label === version ) ;
295+ return ! subgraphInfo . subgraph ?. versions . some ( ( { metadata } : { metadata : { label : string } } ) => metadata ?. label === version ) ;
284296 }
285297
286298 function isOwner ( ) {
@@ -375,7 +387,7 @@ function DeploySubgraph({
375387 if ( e ?. name === 'ContractFunctionExecutionError' ) {
376388 if ( e . cause . name === 'ContractFunctionRevertedError' ) {
377389 toast ( {
378- description : e . cause . reason ,
390+ description : e . cause . message ,
379391 variant : 'destructive' ,
380392 } ) ;
381393 return ;
@@ -565,7 +577,7 @@ function DeploySubgraph({
565577}
566578
567579function Page ( ) {
568- const { id, subgraphId, network } = Route . useSearch ( ) ;
580+ const { id, subgraphId, network, apiKey } = Route . useSearch ( ) ;
569581
570582 const protocolNetwork = network
571583 ? // @ts -expect-error we want to compare if it is a string or not
@@ -581,7 +593,7 @@ function Page() {
581593 < ConnectKitButton />
582594 </ nav >
583595 { id ? (
584- < DeploySubgraph deploymentId = { id } subgraphId = { subgraphId } network = { protocolNetwork } />
596+ < DeploySubgraph deploymentId = { id } subgraphId = { subgraphId } network = { protocolNetwork } apiKey = { apiKey } />
585597 ) : (
586598 < div className = "flex justify-center items-center min-h-screen -mt-16" >
587599 Unable to find the Deployment ID. Go back to CLI
0 commit comments