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

Add to the context values the response of the route, because it is usefull for set cookies for example. #66

Closed
aleleba opened this issue Mar 23, 2023 · 8 comments
Labels
enhancement New feature or request released Has been released and published

Comments

@aleleba
Copy link

aleleba commented Mar 23, 2023

Story

As a user or client or server

I want some feature

I want to add to the context values the response of the route, because it is usefull for set cookies for example.

So that some value

I want to add to the context values the response of the route, because it is usefull for set cookies for example.

Acceptance criteria

Something like this:

createHandler({
  schema,
  context: (req, res, params) => ({ req, res, params })
})
@aleleba aleleba changed the title I want to add to the context values the response of the route, because it is usefull for set cookies for example. Add to the context values the response of the route, because it is usefull for set cookies for example. Mar 24, 2023
@aleleba
Copy link
Author

aleleba commented Mar 27, 2023

@enisdenjo Hi, hope you are doing great, do you know if is in the plans work on this item?, or if not what is the guide for contribute, because this is a must on my apps to migrate from graphql-express. I think I will be return to graphql-express until this is already done, if you need help to contribute this feature, it should be a pleasure to help.

@enisdenjo
Copy link
Member

hey hey, sorry for the delay. I already have something in the pipe for this! will be pushed tomorrow

@aleleba
Copy link
Author

aleleba commented Mar 27, 2023

@enisdenjo thank you!, if you need help, it sholud be a pleasure to help 👍🏼

@enisdenjo enisdenjo added the enhancement New feature or request label Mar 28, 2023
@aleleba
Copy link
Author

aleleba commented Mar 28, 2023

@enisdenjo thank you for your improval, but the fix is missing on express version.

@enisdenjo
Copy link
Member

Oh right, thanks for the heads up! I'll add it there too and then release a new version.

enisdenjo pushed a commit that referenced this issue Mar 28, 2023
# [1.17.0](v1.16.0...v1.17.0) (2023-03-28)

### Features

* **use/express,use/fastify,use/koa:** Request context with the response ([665175e](665175e)), closes [#66](#66)
* **use/http,use/http2:** Request context with the response ([e2cc0cd](e2cc0cd)), closes [#66](#66)
@enisdenjo
Copy link
Member

🎉 This issue has been resolved in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enisdenjo enisdenjo added the released Has been released and published label Mar 28, 2023
@enisdenjo
Copy link
Member

This is now live with v1.17.0, example usage with express would roughly be (very similar for all other node-style handlers too):

import express from 'express'; // yarn add express
import { createHandler } from 'graphql-http/lib/use/express';
import { schema } from './my-graphql-schema';

const app = express();
app.all(
  '/graphql',
  createHandler({
    schema,
    context(req) {
      req.context.res.setHeader('x-my-header', 'my-value');
      return undefined;
    },
  }),
);

app.listen({ port: 4000 });
console.log('Listening to port 4000');

@aleleba
Copy link
Author

aleleba commented Mar 28, 2023

Thank you @enisdenjo, I tried and worked 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released Has been released and published
Projects
None yet
Development

No branches or pull requests

2 participants