-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make readable the Protocols + hide the subgraph api key
- Loading branch information
Koplo
committed
Nov 23, 2024
1 parent
8a47126
commit 8c9053a
Showing
8 changed files
with
1,484 additions
and
45 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
export const API_KEY = process.env.NEXT_PUBLIC_GRAPH_API_KEY; | ||
export const SUBGRAPH_URL = `https://gateway.thegraph.com/api/${API_KEY}/subgraphs/id/7ruo9nxQ3LUqnKkbLgmETDQ27j6A2DFx5L5eV6MS2TAz`; | ||
|
||
export async function request<T>(query: string, variables?: Record<string, any>): Promise<T> { | ||
const response = await fetch('/api/subgraph', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
variables, | ||
}), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch data'); | ||
} | ||
|
||
const { data, errors } = await response.json(); | ||
if (errors) { | ||
throw new Error(errors[0].message); | ||
} | ||
|
||
return data; | ||
} | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
const API_KEY = process.env.NEXT_PUBLIC_GRAPH_API_KEY; | ||
const SUBGRAPH_URL = `https://gateway.thegraph.com/api/${API_KEY}/subgraphs/id/7ruo9nxQ3LUqnKkbLgmETDQ27j6A2DFx5L5eV6MS2TAz`; | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const { query, variables } = await req.json(); | ||
|
||
const response = await fetch(SUBGRAPH_URL, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
variables, | ||
}), | ||
}); | ||
|
||
const data = await response.json(); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
console.error('Subgraph query error:', error); | ||
return NextResponse.json({ error: 'Failed to fetch data' }, { status: 500 }); | ||
} | ||
} |
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
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
This file was deleted.
Oops, something went wrong.