Skip to content

Commit

Permalink
Inject splitgraphClientOptions as expected by makeClient in DebugDDN …
Browse files Browse the repository at this point in the history
…component

This was a recent change that hadn't been implemented in tiny-react-sandbox
  • Loading branch information
milesrichardson committed Mar 15, 2023
1 parent a0525e7 commit ee86cd7
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions packages/tiny-react-sandbox/components/ddn/DebugDDN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,44 @@ import { SplitPaneInputOutput } from "../debugging/SplitPaneInputOutput";

import { AuthWidget } from "./AuthWidget";

import { makeClient } from "@madatdata/client-http/client-http";
import { makeClient, type HTTPStrategies } from "@madatdata/client-http";
import { makeAuthHeaders } from "@madatdata/react";
import { usePersistedCredential } from "./usePersistedCredential";

const client = makeClient({});
const splitgraphClientOptions = {
bodyMode: "json",
strategies: {
makeFetchOptions: ({ credential, query, execOptions }) => {
console.log("got credential...:", credential);

// HACKY: atm, splitgraph API does not accept "object" as valid param
// so remove it from execOptions (hacky because ideal is `...execOptions`)
const httpExecOptions =
execOptions?.rowMode === "object"
? (({ rowMode, ...rest }) => rest)(execOptions)
: execOptions;

return {
method: "POST",
headers: {
"Content-Type": "application/json",
...makeAuthHeaders(
credential
) /* fixme: smell? prefer `this.credential`? */,
},
body: JSON.stringify({ sql: query, ...httpExecOptions }),
};
},
makeQueryURL: async ({ host, database }) => {
return Promise.resolve(host.baseUrls.sql + "/" + database.dbname);
},
} as HTTPStrategies,
};

const client = makeClient({
credential: null,
...splitgraphClientOptions,
});

export const DebugDDN = () => {
const { credential, loading } = usePersistedCredential();
Expand Down

0 comments on commit ee86cd7

Please sign in to comment.