Skip to content

Commit

Permalink
Minor graphql fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Jan 17, 2025
1 parent d36de7d commit 8aee5e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
7 changes: 3 additions & 4 deletions spellsource-web/src/lib/apollo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import { ApolloClient, ApolloProvider, createHttpLink, InMemoryCache } from "@ap
import { setContext } from "@apollo/client/link/context";
import { FunctionComponent, PropsWithChildren, RefObject, useEffect, useRef, useState } from "react";
import { useSession } from "next-auth/react";
import { usePrevious } from "react-use";
import { graphqlHost } from "./config";

export const ApolloClientProvider: FunctionComponent<PropsWithChildren> = ({ children }) => {
const { data: session, status } = useSession();
const prevStatus = usePrevious(status);
const tokenRef = useRef<string | null>(session?.token?.accessToken ?? null);
const [apolloClient] = useState(() => createApolloClient(tokenRef));

useEffect(() => {
if (prevStatus === "authenticated" && status === "unauthenticated") {
console.log("Clearing the cache");
if (status === "authenticated") {
apolloClient.resetStore();
} else {
apolloClient.clearStore();
}
}, [status]);

Expand Down
7 changes: 5 additions & 2 deletions spellsource-web/src/lib/art-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ export const generateArt = async (p1: any) => {
}),
})
.then(async (res) => {
if (isArray(res.body)) {
await onGenerateArt(block, res.body);
const body = await res.json();
if (isArray(body)) {
await onGenerateArt(block, body);
} else {
console.error(body);
}
})
.finally(() => onRequestStop(block));
Expand Down
5 changes: 1 addition & 4 deletions spellsource-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ApolloClientProvider } from "../lib/apollo";
import { SessionProvider } from "next-auth/react";
import "bootstrap/dist/css/bootstrap.min.css";
import Head from "next/head";
import { SSRProvider } from "react-bootstrap";

export default ({ Component, pageProps }: AppProps) => {
return (
Expand All @@ -14,9 +13,7 @@ export default ({ Component, pageProps }: AppProps) => {
<Head>
<link rel="shortcut icon" href="/static/assets/icon.png" />
</Head>
<SSRProvider>
<Component {...pageProps} />
</SSRProvider>
<Component {...pageProps} />
</ApolloClientProvider>
</SessionProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion spellsource-web/src/pages/api/art/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
return;
}

const result = await generateArt(req.body);
const result = await generateArt(JSON.parse(req.body));

res.status(200).json(result);
};

0 comments on commit 8aee5e3

Please sign in to comment.