Skip to content

bump to @apollo/server v4#574

Open
magicmark wants to merge 3 commits into
DanielMSchmidt:masterfrom
magicmark:apollo-server-v4
Open

bump to @apollo/server v4#574
magicmark wants to merge 3 commits into
DanielMSchmidt:masterfrom
magicmark:apollo-server-v4

Conversation

@magicmark
Copy link
Copy Markdown

@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.

Comment thread src/__tests__/integration-test.ts Outdated
tracer,
...params
}: { tracer: MockTracer } & Omit<
InitOptions<InstanceContext>,
Copy link
Copy Markdown
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?

Comment thread src/context.ts

obj.addSpan = function (span: Span, info: GraphQLResolveInfo): void {
this._spans.set(buildPath(info.path), span);
const spans = new Map<string, Span>();
Copy link
Copy Markdown
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)

Comment thread src/index.ts
source: any,
args: { [argName: string]: any },
context: SpanContext,
context: TContext,
Copy link
Copy Markdown
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 thread src/index.ts
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
Copy Markdown
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

Comment thread README.md
## 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
Copy Markdown
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 thread src/context.ts
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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