Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express handler receiving HTTP response reference #141

Open
asieraduriz opened this issue Jan 29, 2025 · 0 comments
Open

Express handler receiving HTTP response reference #141

asieraduriz opened this issue Jan 29, 2025 · 0 comments

Comments

@asieraduriz
Copy link

Hello! I just started with my pet project using express and this library to serve my graphql endpoint, and I hit a snag when developing some authentication methods.

It is my understanding that in order to log out, the server should be the one setting the cookies to expire to abstract it from the Frontend, but I wasn't capable of finding that snippet of code in your documentation.

I sort of pieced together what might be helpful and this is what I came up with

import express from "express";
import { schema } from "./schema";
import { createHandler } from "graphql-http/lib/use/express";
const app = express();

app.use("/graphql", (req, res, next) =>
  createHandler({
    schema,
    context: (req) => ({ req, res }),
  })(req, res, next)
);

// Start the server
const PORT = 4000;
app.listen(PORT, () => {
  console.log(`Server is running at http://localhost:${PORT}/graphql`);
});

I would very much appreciate any validation if there's any issue applying such code.
My intention is that for the logout mutation, the resolver can influence the response by setting some headers.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant