Hi!
I have a GraphQL handler at http://localhost:3000/graphql and I want to get session info by calling getSession inside of it but when I do it I receive no data (I do get session details when I call it on pages with createServerData$).
Is it expected behavior? If not, what are the ways to debug it (I'm somewhat new to this)?
File at /src/routes/graphql.tsx
import { GraphQLError, graphql } from 'graphql';
import { APIEvent, json } from 'solid-start';
import { getSession } from '@solid-auth/base';
import { authOptions } from '~/server/auth';
import { rootValue, schema } from '~/lib/graphql/graphql';
import logger from "../utils/logger";
const graphQLHandler = async (event: APIEvent) => {
// get session
const session = await getSession(event.request, authOptions);
// return null ;(
console.log('session', session);
// get request body
const body = await new Response(event.request.body).json();
// pass query and save results
const result = await graphql({
rootValue,
schema,
source: body.query,
variableValues: body.variables,
contextValue: { user: session?.user }
});
if(result.errors! && result.errors.length > 0) {
const error = result.errors[0] as GraphQLError;
logger.error(error);
throw error;
};
// send query results as response
return json(result);
};
export const GET = graphQLHandler;
export const POST = graphQLHandler;