R
Railway10mo ago
Yashu

Talk to another private service with correct URL?

I have added the private URL of serviceB to serverA. serverA: webapp serverB: api I have deploy a graphql apis on serverB at example.com/graphql URL. I have tried in the serverA as environment variable API_URL in following ways: - serviceB/graphql - serviceB:<PORT>/graphql If I directly added the internal URL with sub-path it doesn't work. Am I doing something wrong here?
5 Replies
Percy
Percy10mo ago
Project ID: 2531c331-6f54-4d37-b68e-0140e94619c0
Yashu
Yashu10mo ago
2531c331-6f54-4d37-b68e-0140e94619c0
Brody
Brody10mo ago
please show both code and errors
Yashu
Yashu10mo ago
Here's the error I get from the webapp service,
networkError: TypeError: Failed to parse URL from api.railway.internal/graphql
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[cause]: TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:611:13)
at new Request (node:internal/deps/undici/undici:7132:25)
at fetch2 (node:internal/deps/undici/undici:10715:25)
at Object.fetch (node:internal/deps/undici/undici:11574:18)
at fetch (node:internal/process/pre_execution:229:25)
at /app/node_modules/.pnpm/@apollo+client@3.8.5_graphql@16.8.1_reactdom@18.2.0_react@18.2.0/node_modules/@apollo/client/link/http/http.cjs:581:13
at new Subscription (/app/node_modules/.pnpm/zen-observable@0.8.15/node_modules/zen-observable/lib/Observable.js:197:34)
at Observable.subscribe (/app/node_modules/.pnpm/zen-observable@0.8.15/node_modules/zen-observable/lib/Observable.js:279:14)
at Object.complete (/app/node_modules/.pnpm/@apollo+client@3.8.5_graphql@16.8.1_react-dom@18.2.0_react@18.2.0/node_modules/@apollo/client/utilities/utilities.cjs:1351:43) {
input: 'api.railway.internal/graphql',
code: 'ERR_INVALID_URL'
}
networkError: TypeError: Failed to parse URL from api.railway.internal/graphql
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[cause]: TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:611:13)
at new Request (node:internal/deps/undici/undici:7132:25)
at fetch2 (node:internal/deps/undici/undici:10715:25)
at Object.fetch (node:internal/deps/undici/undici:11574:18)
at fetch (node:internal/process/pre_execution:229:25)
at /app/node_modules/.pnpm/@apollo+client@3.8.5_graphql@16.8.1_reactdom@18.2.0_react@18.2.0/node_modules/@apollo/client/link/http/http.cjs:581:13
at new Subscription (/app/node_modules/.pnpm/zen-observable@0.8.15/node_modules/zen-observable/lib/Observable.js:197:34)
at Observable.subscribe (/app/node_modules/.pnpm/zen-observable@0.8.15/node_modules/zen-observable/lib/Observable.js:279:14)
at Object.complete (/app/node_modules/.pnpm/@apollo+client@3.8.5_graphql@16.8.1_react-dom@18.2.0_react@18.2.0/node_modules/@apollo/client/utilities/utilities.cjs:1351:43) {
input: 'api.railway.internal/graphql',
code: 'ERR_INVALID_URL'
}
I need to use the GraphQL internal URI to make SSR request from webapp using apollo client
function createApolloClient({ headers }: ClientOptions) {
const isSSR = typeof window === "undefined";

return new ApolloClient({
ssrMode: isSSR,
link: new HttpLink({
uri: process.env.API_URL || process.env.NEXT_PUBLIC_API_URL,
headers,
credentials:
process.env.NODE_ENV === "development" ? "same-origin" : "include",
}),
defaultOptions: isSSR
? {
query: {
fetchPolicy: "no-cache",
},
}
: undefined,
});
}
function createApolloClient({ headers }: ClientOptions) {
const isSSR = typeof window === "undefined";

return new ApolloClient({
ssrMode: isSSR,
link: new HttpLink({
uri: process.env.API_URL || process.env.NEXT_PUBLIC_API_URL,
headers,
credentials:
process.env.NODE_ENV === "development" ? "same-origin" : "include",
}),
defaultOptions: isSSR
? {
query: {
fetchPolicy: "no-cache",
},
}
: undefined,
});
}
Brody
Brody10mo ago
1. you are missing the scheme (http://) 2. you are missing a port