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

bump to @apollo/server v4 #574

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

magicmark
Copy link

@magicmark magicmark commented Mar 28, 2023

fixes #573

@DanielMSchmidt this ended up being a larger diff that i'd anticipated:

  1. bumped to latest graphql-js, @apollo/server
  2. namespaced the stuff this library adds to the context object under a symbol (as suggested in code)
  3. had to hoist the typedefs and some helpers into index.ts to do this ^ (so we don't export the symbol)
  4. made some typing changes about how we define/pass around the context. i'm the least confident about these changes, and tbh I may have misunderstood how it's currently implemented, so lmk.

tracer,
...params
}: { tracer: MockTracer } & Omit<
InitOptions<InstanceContext>,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this passed as a generic?


obj.addSpan = function (span: Span, info: GraphQLResolveInfo): void {
this._spans.set(buildPath(info.path), span);
const spans = new Map<string, Span>();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this attached to the context object? (closure here means it's no longer exposed)

server?: Tracer;
local?: Tracer;
onFieldResolveFinish?: (error: Error | null, result: any, span: Span) => void;
onFieldResolve?: (
source: any,
args: { [argName: string]: any },
context: SpanContext,
context: TContext,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did the lifecycle methods need to know about the SpanContext? (supposed to be private?)

Comment on lines -132 to -137
if (!requestIsInstanceContextRequest<InstanceContext>(infos)) {
console.warn(
"Context in request passed to apollo-opentracing#requestDidStart is not a SpanContext, aborting tracing"
);
return;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this here since it implicitly exists given the line above (enforced with typescript)

had to move it to a lifecycle method below tho

@@ -101,7 +101,7 @@ There might be certain field resolvers that are not worth the tracing, e.g. when

## Modifying span metadata

If you'd like to add custom tags or logs to span you can construct the extension with `onRequestResolve`. The function is called with two arguments: span and infos `onRequestResolve?: (span: Span, info: RequestStart)`
If you'd like to add custom tags or logs to span you can construct the extension with `onRequestResolve`. The function is called with two arguments: span and infos `onRequestResolve?: (span: Span, info: GraphQLRequestContext)`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was contradicted by L117

Comment on lines -49 to -53
obj.getSpanByPath = function (path: ResponsePath): Span | undefined {
return this._spans.get(buildPath(isArrayPath(path) ? path.prev : path));
};

obj.addSpan = function (span: Span, info: GraphQLResolveInfo): void {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is context.getSpanByPath and context.addSpan supposed to be part of the public API provided by this library?

I don't see it referenced in README.md, other than: onFieldResolve(source: any, args: { [argName: string]: any }, context: SpanContext, info: GraphQLResolveInfo): Allow users to add extra information to the span which implies either:

  • you're supposed to be able to use these fields specifically when doing onFieldResolve, or;
  • this is just a consequence of mutating the context object and we're just being honest

(I've interpreted the latter given think about using symbols to hide these, but lmk!)

@magicmark
Copy link
Author

FWIW if anyone needs this before it's merged, I used this https://gist.github.com/magicmark/8c2e83eaa59cb8671ef7ce71b2b9db2f (result of this diff) and applied it with patch-package

@glensc
Copy link

glensc commented Mar 25, 2024

@DanielMSchmidt perhaps just accept and merge this? if there are bugs, community can submit bugfixes. can be released as 4.0.0 and mark as pre-release in github release. maybe also add more maintainers? like @magicmark can probably support this 4.x changes?

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 this pull request may close these issues.

Migrate to apollo server v4
2 participants