-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Additional extensions support #934
Additional extensions support #934
Conversation
@sebas5384: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
49c656b
to
79191e3
Compare
Yep, I think the ability to pass in additional extensions is great. The reason we haven't done that so far is that we didn't want to commit to the current One change we discussed is to get rid of the separate What do you think? How are you using the extension API? Anything else you're missing or would like to improve about it? |
Hi @martijnwalraven !
I'm missing some contextual arguments on the lifecycle methods in order to avoid unnecessary statefulness inside the extension instance. For example, Today, I would have to save a reference of the request response inside the extension when the first field will be resolved, though instead I could do it inside |
The idea behind the callback pattern would be that you could keep start and end together:
That would also allow you to use local state when needed. Note that right now a new instance of the I'm also wondering where you're adding a header, because the current API is meant to add GraphQL extension data and doesn't give you access to the underlying response. What is your use case exactly? If we think adding headers is common, maybe we should add the equivalent to |
@martijnwalraven I guess the main benefit I see with callbacks is local scope, for example, the Here's what I would love to do with Apollo Server:
PS: Probably I could write a middleware at the web server level and parse the query, schema, etc... but thats an overhead in my opinion which I could solve it nicely inside the apollo-server as an extension (I actually prefer the middleware concept). For now, I guess if the response is passed to the
Yeah, that's why I would prefer to have a lifecycle for the request, and not the execution of the query (maybe I wrong about it). Someone already touch on this matter: #657 (comment) I see why this PR could take a while to be merge since is about two projects, Hope I'm helping 😄 |
I really think this is a particularly nice benefit! |
@@ -114,7 +115,7 @@ function doRunQuery(options: QueryOptions): Promise<GraphQLResponse> { | |||
logFunction({ action: LogAction.request, step: LogStep.start }); | |||
|
|||
const context = options.context || {}; | |||
let extensions = []; | |||
let extensions = options.extensions !== undefined ? options.extensions : []; | |||
if (options.tracing) { | |||
extensions.push(TracingExtension); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the tracing extension should be applied before all other extensions, otherwise it's going to give misleading numbers (the custom extensions may take a long time to execute, but the tracing would never pick up on that as it'd start recording AFTER they've all executed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. We should also run "didStop" handlers in reverse order for that reason.
Just wondered if there's any update or further thought on getting this merged in? Got a few scenarios where custom extensions would fit the bill nicely. |
I'm working on this this week, along with improving the extensions API. |
I've rolled this into #1105. Thanks! |
Thank you so much @sebas5384 for the initial effort! |
Passing additional extensions (other than the default Tracing and Cache Control) seems to be a need (#657) which could open the door to new and interesting extensions.
TODO: