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

Making custom handlers requires a defineContext function #72

Closed
kentcdodds opened this issue Mar 20, 2020 · 3 comments · Fixed by #74
Closed

Making custom handlers requires a defineContext function #72

kentcdodds opened this issue Mar 20, 2020 · 3 comments · Fixed by #74

Comments

@kentcdodds
Copy link
Contributor

The docs don't mention anything about this and I'm not sure of an ergonomic way to create this function...

@kettanaito
Copy link
Member

kettanaito commented Mar 20, 2020

That's a good point, @kentcdodds. Could you please show me how are you creating a custom request handler and what is your goal?

The defineContext function is used internally to define which ctx utility functions are available for specific request handlers. There are two main groups of request handlers, per docs: rest and graphql. Since those operate in different domains, they have different context utilities declared by defineContext, which establishes them in the third argument of a response resolver: ctx.

However, as of Custom context utilities I see little benefit in passing them to defineContext, as you may import your custom context functions manually. I think it's a matter of marking defineContext as optional when creating a custom request handler, and describing what this function does for general knowledge in the documentation.

@kettanaito
Copy link
Member

As of 0.9.2 the defineContext property is no longer required on a custom request handler.

I've updated the Custom request handler documentation to reflect on how to use the defineContext property to provide your custom context utilities.

I still don't recommend defineContext as the go-to, and would advise to just declare custom context utility functions and import them manually, but I can still see a use case of creating your own custom set of request handlers and even putting them into a separate package to distribute in the stack.

@kentcdodds
Copy link
Contributor Author

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

Successfully merging a pull request may close this issue.

2 participants