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 apolloBatchIndex and apolloBatchSize fields on the context object #177

Closed
wants to merge 5 commits into from

Conversation

n1mmy
Copy link
Contributor

@n1mmy n1mmy commented Oct 19, 2016

This is so that users can detect when clients have requested batching. This will be useful for performance monitoring (see https://github.com/apollostack/optics-agent-js/issues/47)

This lets users detect whether or not their query is running in a batch,
which is useful for performance debugging.
@glasser
Copy link
Member

glasser commented Oct 19, 2016

Do we want to include this even when there's no batching? ie, is there any point to distinguishing between "sent a single query" and "sent a size-1 batch"? (I don't know the answer, just though it was worth asking.)

@n1mmy
Copy link
Contributor Author

n1mmy commented Oct 19, 2016

Oh, right, I suggested that to @helfer in person and he agreed it was a good idea, then I forgot to implement it. Will add unless someone suggests a reason why it would be bad to distinguish.

@DxCx
Copy link
Contributor

DxCx commented Oct 19, 2016

Few comments i want to raise:

  1. Batching is being handled (Copy/Paste mostly) in 3 different files.
    i think we should add core module for batchedRunQuery, getting the common logic there.
  2. I'm not sure context is the right place to add this metadata, context is an object created by the user (Talking about the server developer, not the final user) for the user. modifying it for the user (without the user explicitly asks so) might bring chaos, because imagine that this is just 1 feature added, but later on more and more people will start overloading context after you.
  3. if you decided to use context anyway, i think you should add metadata key to the context, and only then append the info.
  4. we can trick the schema and hook resolvers for appending metadata to info object (which is by definition created internally for the user to use) but this is abit more work and more open for flaws..

would like to hear more thoughts :)

@glasser
Copy link
Member

glasser commented Oct 19, 2016 via email

@helfer
Copy link
Contributor

helfer commented Oct 19, 2016

@DxCx I agree, see also #176.

As for the key we use on the context, I think we should stick to just apolloBatchIndex if that's the only one we have for now, but if we add batchSize as well, then let's "namespace" it in a apolloContext field as @DxCx suggested.

@n1mmy
Copy link
Contributor Author

n1mmy commented Oct 19, 2016

The current PR has both context.apolloBatchIndex and context.apolloBatchSize. Happy to change to context.apolloContext.batchIndex and context.apolloContext.batchSize or something like that if that's what people prefer.

@DxCx The situation is I'm trying to find a way to distinguish which query a resolver is running in the context of, for https://github.com/apollostack/optics-agent-js. context is the only reliable way I found to get that information into resolvers. Unfortunately, this interacts poorly with apollo-server transport level batching, as that uses the same context object for each request. I agree overwriting fields of the user-provider context is kinda hacky, but I couldn't think of anything better, unfortunately. Other ideas welcome!

@helfer
Copy link
Contributor

helfer commented Oct 19, 2016

@n1mmy okay, then let's create an apolloContext object on the context.

In the medium to long term I think we should move batching into the core, which will also simplify the integrations.

@n1mmy
Copy link
Contributor Author

n1mmy commented Oct 21, 2016

Closing in favor of #182

@n1mmy n1mmy closed this Oct 21, 2016
@abernix abernix deleted the nim/batch-index branch August 10, 2018 16:51
trevor-scheer pushed a commit that referenced this pull request Oct 17, 2022
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
trevor-scheer pushed a commit that referenced this pull request Oct 17, 2022
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
trevor-scheer pushed a commit that referenced this pull request Oct 19, 2022
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants