Skip to content

Commit

Permalink
Due to a breaking-change in graphql-request, we need to prefix endpoi…
Browse files Browse the repository at this point in the history
…nt with hostname if it does not have one
  • Loading branch information
testower committed Jun 11, 2024
1 parent 51639fc commit 8339d62
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions client-next/src/hooks/useTripQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { QueryType, TripQueryVariables } from '../gql/graphql.ts';

const endpoint = import.meta.env.VITE_API_URL;

const getApiUrl = () => {
try {
// the URL constructor will throw exception if endpoint is not a valid URL,
// e.g. if it is a relative path
new URL(endpoint);
return endpoint;
} catch (e) {
return `${window.location.origin}${endpoint}`;
}
};

/**
General purpose trip query document for debugging trip searches
TODO: should live in a separate file, and split into fragments for readability
Expand Down Expand Up @@ -96,9 +107,9 @@ export const useTripQuery: TripQueryHook = (variables) => {
if (variables) {
setLoading(true);
if (pageCursor) {
setData((await request(endpoint, query, { ...variables, pageCursor })) as QueryType);
setData((await request(getApiUrl(), query, { ...variables, pageCursor })) as QueryType);
} else {
setData((await request(endpoint, query, variables)) as QueryType);
setData((await request(getApiUrl(), query, variables)) as QueryType);
}
setLoading(false);
} else {
Expand Down

0 comments on commit 8339d62

Please sign in to comment.