Hello, I’m trying to include a cookie in my requests, I’ve tried to troubleshoot it by following some of the things I found in this forum and GitHub, but so far I’ve been unsuccessful. If anybody can help my with this I would appreciate it.
Here’s the code for my index.ts file:
import { MikroORM } from "@mikro-orm/postgresql"
import { ApolloServer } from "apollo-server-express"
import connectRedis from "connect-redis"
import dotenv from "dotenv"
import express from "express"
import session from "express-session"
import { createClient } from "redis"
import "reflect-metadata"
import { buildSchema } from "type-graphql"
import { __prod__ } from "./constants"
import mikroConfig from "./mikro-orm.config"
import { PostResolver } from "./resolvers/post"
import { UserResolver } from "./resolvers/user"
import { ApolloContext } from "./types"
async function main() {
dotenv.config()
const orm = await MikroORM.init(mikroConfig)
const emFork = orm.em.fork()
await orm.getMigrator().up()
const app = express()
const corsOptions = {
credentials: true,
origin: "https://studio.apollographql.com",
}
app.set("trust proxy", !__prod__)
const RedisStore = connectRedis(session)
const redisClient = createClient({ legacyMode: true })
redisClient.connect().catch(console.error)
app.use(
session({
name: "qid",
store: new RedisStore({ client: redisClient, disableTouch: true }),
saveUninitialized: false,
secret: process.env.SESSION_SECRET!,
resave: false,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 365 * 10, // 10 years
httpOnly: true,
sameSite: "none",
secure: true,
},
})
)
const apolloServer = new ApolloServer({
schema: await buildSchema({
resolvers: [PostResolver, UserResolver],
validate: false,
}),
context: ({ req, res }): ApolloContext => ({ emFork, req, res }),
})
await apolloServer.start()
apolloServer.applyMiddleware({ app, cors: corsOptions })
app.listen(process.env.PORT, () => {
console.log("Express server started on port:", process.env.PORT)
})
}
main()
Here are my Apollo sandbox settings: