Skip to content

Commit

Permalink
feat(website): replace using axios with fetch
Browse files Browse the repository at this point in the history
Using the solution at remix-run/remix#4414 (comment).
However, it would be better if we do not have to write a custom fetch
function at all.
  • Loading branch information
IgnisDa committed Nov 15, 2022
1 parent 7c1629d commit 4babcdc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ Thumbs.db
# edgedb
libs/main-db/dbschema/edgeql-js

# website
!apps/website/app/lib

# Moon
.moon/cache
.moon/docker
Expand Down
1 change: 1 addition & 0 deletions apps/website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ public/build

app/tailwind.css
app/lib/routes.d.ts
!app/lib
19 changes: 9 additions & 10 deletions apps/website/app/lib/services/graphql.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import axios from 'axios';
import { Thunder, ZeusScalars } from '@codefarem/generated/orchestrator-graphql';
import {
Thunder,
ZeusScalars,
} from '@codefarem/generated/orchestrator-graphql';
import { ApplicationConfig } from '../config.server';

/**
Expand All @@ -8,20 +10,17 @@ import { ApplicationConfig } from '../config.server';
export const graphqlSdk = (authorizationToken = '') => {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
connection: 'keep-alive',
};
if (authorizationToken)
headers.Authorization = `Bearer ${authorizationToken}`;
return Thunder(async (query) => {
const response = await axios.post(
const response = await fetch(
`${ApplicationConfig.APPLICATION_API_URL}/graphql`,
JSON.stringify({ query }),
{ headers }
{ method: 'POST', body: JSON.stringify({ query }), headers }
);
if (!response?.data?.data) {
console.dir(response?.data?.errors, { depth: Infinity })
throw new Error(`There was an error in the graphql request, please check developer logs`)
}
return response.data.data;
const data = await response.json();
return data.data;
});
};

Expand Down
1 change: 0 additions & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@routes-gen/remix": "0.3.5",
"@types/uuid": "8.3.4",
"@uiw/react-codemirror": "4.12.3",
"axios": "1.1.3",
"change-case": "4.1.2",
"clsx": "1.2.1",
"codemirror": "6.0.1",
Expand Down
26 changes: 4 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4babcdc

Please sign in to comment.