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

addToContext should only see request headers #509

Open
jasonkuhrt opened this issue Mar 18, 2020 · 1 comment
Open

addToContext should only see request headers #509

jasonkuhrt opened this issue Mar 18, 2020 · 1 comment
Labels
note/breaking-change This issue existed already scope/schema-context scope/server Related to the server component type/improve Something existing is made better, does not affect the interface (example: better error message)

Comments

@jasonkuhrt
Copy link
Member

Perceived Problem

The API is bloated, currently exposing HTTP.IncomingMessage, so an event emitter, so on:

image

It is not appropriate. It is not how we would design it from scratch. It is inherited without having been really reflected upon.

Aside from burdening the autocomplete DX for users, it permits nonsense:

schema.addToContext(req => {
  req.destroy() // possible but senseless  
})

Ideas / Proposed Solution(s)

  • A new constrained type, about just data
  • just http headers
  • either schema.addToContext(({ headers }) => )
  • or schema.addToContext((headers) => )
  • Call the type... RequestData or NexusRequestData
  • Do we need plugins to be able to contribute typegen here?
  • What if there is server middleware that does some complex logic and wants to add some derived values to the request object which then the user wants to add to context?
    • answer seems to be... don't... cut the indirection and bring schema.addToContext to where you need it...

Related

@jasonkuhrt jasonkuhrt added type/improve Something existing is made better, does not affect the interface (example: better error message) note/breaking-change This issue existed already scope/schema-context scope/server Related to the server component labels Mar 18, 2020
@jasonkuhrt
Copy link
Member Author

Would be made obsolete by #524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
note/breaking-change This issue existed already scope/schema-context scope/server Related to the server component type/improve Something existing is made better, does not affect the interface (example: better error message)
Projects
None yet
Development

No branches or pull requests

1 participant