regbit
regbit
SSolidJS
Created by regbit on 6/28/2023 in #support
Solid-Start + GraphQL session info
Right now as a workaround I passed event from createServerData$ down to gqlCall to pull cookies from there for the fetch and it works. But still feels like I'm missing something.
4 replies
SSolidJS
Created by regbit on 6/28/2023 in #support
Solid-Start + GraphQL session info
Maybe I'm calling GQL fetch incorrectly? Right now the call path looks like this:
// /src/routes/decisions/(decisions).tsx
...
export function routeData() {
return createServerData$(
async () => {
return await getUserDecisionsGQL();
},
);
};
...
// /src/routes/decisions/(decisions).tsx
...
export function routeData() {
return createServerData$(
async () => {
return await getUserDecisionsGQL();
},
);
};
...
->
// /src/db/requests/decision.tsx
...
export const getUserDecisionsGQL = async function () {
const res = await gqlCall(GET_USER_DECISIONS);
return res.data.getUserDecisions as Decision[];
};
...
// /src/db/requests/decision.tsx
...
export const getUserDecisionsGQL = async function () {
const res = await gqlCall(GET_USER_DECISIONS);
return res.data.getUserDecisions as Decision[];
};
...
->
// /src/lib/actions.tsx
export async function gqlCall(query: string, variables?: any) {
// make graphql query
try {
const response = await fetch("http://localhost:3000/graphql", {
method: "POST",
body: JSON.stringify({ query, variables }),
});

if (response?.ok) {
// turn response into javascript object
const gqlresponse = await response.json();

// return response
return gqlresponse;
} else {
console.log(`HTTP Response Code: ${response?.status}`)
// throw
}
} catch (error) {
console.error('error:', error)
}
};
// /src/lib/actions.tsx
export async function gqlCall(query: string, variables?: any) {
// make graphql query
try {
const response = await fetch("http://localhost:3000/graphql", {
method: "POST",
body: JSON.stringify({ query, variables }),
});

if (response?.ok) {
// turn response into javascript object
const gqlresponse = await response.json();

// return response
return gqlresponse;
} else {
console.log(`HTTP Response Code: ${response?.status}`)
// throw
}
} catch (error) {
console.error('error:', error)
}
};
4 replies
SSolidJS
Created by regbit on 6/28/2023 in #support
Solid-Start + GraphQL session info
4 replies