-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(indexer): new graphql url config option #1303
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||
// Copyright 2025. The Tari Project | ||||||
// | ||||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||||||
// following conditions are met: | ||||||
// | ||||||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||||||
// disclaimer. | ||||||
// | ||||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||||||
// following disclaimer in the documentation and/or other materials provided with the distribution. | ||||||
// | ||||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote | ||||||
// products derived from this software without specific prior written permission. | ||||||
// | ||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||||||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||||||
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||
|
||||||
const DEFAULT_GRAPHQL_ADDRESS = new URL( | ||||||
import.meta.env.VITE_INDEXER_GRAPHQL_ADDRESS || | ||||||
import.meta.env.VITE_GRAPHQL_ADDRESS || | ||||||
"http://localhost:18301", | ||||||
); | ||||||
|
||||||
export async function getGraphQLAddress(): Promise<URL> { | ||||||
try { | ||||||
const resp = await fetch("/graphql_address"); | ||||||
if (resp.status === 200) { | ||||||
const url = await resp.text(); | ||||||
try { | ||||||
return new URL(url); | ||||||
} catch (e) { | ||||||
throw new Error(`Invalid URL: ${url} : {e}`); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the template literal syntax in error message. The error message has incorrect template literal syntax for the error object. - throw new Error(`Invalid URL: ${url} : {e}`);
+ throw new Error(`Invalid URL: ${url} : ${e}`); 📝 Committable suggestion
Suggested change
|
||||||
} | ||||||
} | ||||||
} catch (e) { | ||||||
console.warn(e); | ||||||
} | ||||||
|
||||||
return DEFAULT_GRAPHQL_ADDRESS; | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -114,6 +114,23 @@ impl InstanceInfo { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub fn get_public_graphql_url(&self) -> Url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
match self.settings.get("public_graphql_url") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some(url) => url.parse().expect("Invalid JSON RPC URL"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
None => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let public_ip = self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.get("public_ip") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.map(|s| s.as_str()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.unwrap_or("127.0.0.1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let web_port = self.ports.get("jrpc").expect("jrpc port not found"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
format!("http://{public_ip}:{web_port}/json_rpc") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.parse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.expect("Invalid web URL") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+118
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect URL construction in The method has two issues:
Apply this diff to fix the issues: pub fn get_public_graphql_url(&self) -> Url {
match self.settings.get("public_graphql_url") {
- Some(url) => url.parse().expect("Invalid JSON RPC URL"),
+ Some(url) => url.parse().expect("Invalid GraphQL URL"),
None => {
let public_ip = self
.settings
.get("public_ip")
.map(|s| s.as_str())
.unwrap_or("127.0.0.1");
- let web_port = self.ports.get("jrpc").expect("jrpc port not found");
- format!("http://{public_ip}:{web_port}/json_rpc")
+ let web_port = self.ports.get("web").expect("web port not found");
+ format!("http://{public_ip}:{web_port}/graphql")
.parse()
- .expect("Invalid web URL")
+ .expect("Invalid GraphQL URL")
},
}
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl From<&Instance> for InstanceInfo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Reconsider the dependency between JSON-RPC and GraphQL servers.
The JSON-RPC server startup now requires the GraphQL address to be configured, which creates an unnecessary dependency between these services. They should be able to operate independently.
Apply this diff to decouple the services:
📝 Committable suggestion