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

feat: support graphql v16 #998

Merged
merged 13 commits into from
Oct 3, 2022

Conversation

dchambers
Copy link
Contributor

@dchambers dchambers commented May 3, 2022

Which problem is this PR solving?

  • Allow developers to use any version of the graphql library they want to by making graphql a peer dependency.
  • Allow developers to use graphql v16 by introducing an adaptor function to abstract away the API change in v16.

Short description of the changes

  • As per the problem solving statement, but defined as three distinct commits:
    1. Prove that graphql can be made a peer dependency. 🟢
    2. Start testing against graphql v16. 🔴
      • Green on CI because CI doesn't run test-all-versions, but verified as failing locally on my machine.
    3. Introduce the graphql adaptor function to fix the broken tests. 🟢
      • Again, verified test-all-versions on my machine, but this time where all versions pass again.

Checklist

  • Ran npm run test-all-versions for the edited package(s) on the latest commit if applicable.

@dchambers dchambers requested a review from a team May 3, 2022 20:20
@github-actions github-actions bot requested a review from obecny May 3, 2022 20:21
@codecov
Copy link

codecov bot commented May 3, 2022

Codecov Report

Merging #998 (e148301) into main (502caae) will decrease coverage by 0.68%.
The diff coverage is 66.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #998      +/-   ##
==========================================
- Coverage   96.08%   95.39%   -0.69%     
==========================================
  Files          14       21       +7     
  Lines         893     1346     +453     
  Branches      191      278      +87     
==========================================
+ Hits          858     1284     +426     
- Misses         35       62      +27     
Impacted Files Coverage Δ
...opentelemetry-instrumentation-graphql/src/types.ts 100.00% <ø> (ø)
...opentelemetry-instrumentation-graphql/src/utils.ts 93.40% <50.00%> (ø)
...try-instrumentation-graphql/src/instrumentation.ts 91.66% <100.00%> (ø)
...tapackages/auto-instrumentations-node/src/utils.ts 98.18% <0.00%> (ø)
...nstrumentation-graphql/src/enums/AttributeNames.ts 100.00% <0.00%> (ø)
...entelemetry-instrumentation-graphql/src/symbols.ts 100.00% <0.00%> (ø)
.../opentelemetry-instrumentation-graphql/src/enum.ts 100.00% <0.00%> (ø)

@dchambers
Copy link
Contributor Author

This PR fixes #784.

@rauno56
Copy link
Member

rauno56 commented May 8, 2022

Thanks for the PR. I appreciate the clear PR description and commit structure. 👍

Allow developers to use any version of the graphql library they want to by making graphql a peer dependency.

Instrumentation users can actually already use any version. Moving it to peer dependency only makes it installed by default on new npm versions.

Green on CI because CI doesn't run test-all-versions, but verified as failing locally on my machine.

Do I understand you correctly that tests fail on graphql v16? How does that qualify supporting it in that case or is it still WIP?

@dchambers
Copy link
Contributor Author

Instrumentation users can actually already use any version. Moving it to peer dependency only makes it installed by default on new npm versions.

Hi @rauno56 👋. So prior to this PR users could only use versions other than graphql v15 by forcing it using something like resolutions (assuming they use Yarn), plus they had no way of knowing whether it would work (it didn't for v16 for example, and I haven't bothered to test v14 as it's now pretty old, and I don't need it).

The peer dependency approach, which includes a formal specification of which peer versions are supported, is what's used by the vast majority of graphql dependent NPM libraries that we currently use (50 out of 53 to be exact), with this being one of the three libraries we use that doesn't currently work that way.

Do I understand you correctly that tests fail on graphql v16? How does that qualify supporting it in that case or is it still WIP?

No, graphql v16 is made to work in commit number 3. I only point out that it doesn't initially work (in commit number 2) to demonstrate the need for the changes in that third commit. This isn't reflected in the CI results however since test-all-versions is only run nightly, rather than being run on every single PR, and therefore I confirm that I've run it locally to make up for, what is otherwise, a lack of evidence for the utility of the PR.

Copy link
Member

@rauno56 rauno56 left a comment

Choose a reason for hiding this comment

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

Sorry, I missed the fact that we had graphql listed under the dependencies not only as a devDep. It's not common among the packages here.

},
"devDependencies": {
"@opentelemetry/api": "1.0.2",
"@opentelemetry/sdk-trace-base": "1.2.0",
"@types/mocha": "8.2.3",
"@types/node": "16.11.21",
"graphql": "^15.5.1",
Copy link
Member

Choose a reason for hiding this comment

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

Why not update it among the dev-deps as well to the latest and leave testing on v15 for TAV?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the great feedback @rauno56. Those changes are now made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rauno56, I finally had some time to get the tests working while using v16 internally. However, since graphql v16 doesn't appear to support Node.js v8 or Node.js v10, that has meant conditionally disabling a few of the tests. Perhaps, therefore, you might prefer to use the latest 15.x internally, so that running npm test locally exercises all tests.

BTW the failing code coverage check appears to be as a result of an as Error cast I perform, which is weird since casting is only a notional concept, and does not translate to code paths that can be tested.

@Flarna
Copy link
Member

Flarna commented May 9, 2022

graphql was move between dependency and devDependency a few times.

  • if it is a dependency - in special with a pinned version - it tends to collide with the user version
  • if it is a dep dependency it results in transpile problems if user has no graphql installed because it needs the types.

As it is part of the autoinstrument metapackage it's a common setup that users have the instrumentation installed even if they don't use graphql.

Refs: #754 and #850

Co-authored-by: Rauno Viskus <Rauno56@users.noreply.github.com>
@dchambers
Copy link
Contributor Author

dchambers commented May 9, 2022

graphql was move between dependency and devDependency a few times.

  • if it is a dependency - in special with a pinned version - it tends to collide with the user version
  • if it is a dep dependency it results in transpile problems if user has no graphql installed because it needs the types.

As it is part of the autoinstrument metapackage it's a common setup that users have the instrumentation installed even if they don't use graphql.

Refs: #754 and #850

So by using peer dependencies I believe that this PR takes a third approach, which is different from both of the two previously utilised approaches. That is:

  1. graphql as a devDependency:
    • Consumers have the flexibility to use any version of graphql that's >= 15.5.1.
    • Consumers are responsible for installing graphql if they don't already have it, and with no feedback from NPM/Yarn as to this requirement.
  2. graphql as a dependency:
    • Consumers have the flexibility to use any version of graphql that's >= 15.5.1.
    • Consumers don't need to install graphql if they don't already have it.
  3. graphql as a peerDependency and a devDependency:
    • Consumers have the flexibility to use any version of graphql that's >= 14.0.0 || 15.0.0 || 16.0.0.
    • Consumers are responsible for installing graphql if they don't already have it, but NPM/Yarn informs them about this requirement when they install @opentelemetry/instrumentation-graphql (assuming they don't already have graphql installed that is).

To be clear, I'm not suggesting that this is perfect, but it does seem (to me) like the best compromise.

@dyladan, as author of #850 do you have any thoughts on whether this is sufficient, or whether there may be a better solution?

typeInfo?: graphqlTypes.TypeInfo,
options?: { maxErrors?: number }
options?: { maxErrors?: number },
typeInfo?: graphqlTypes.TypeInfo
Copy link
Contributor Author

Choose a reason for hiding this comment

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

graphql v16 flips around these two parameters 🤯 . This has no effect at runtime when using v15 Vs v16 because they both pass whatever they receive through, but needs to be changed in the case we want to compile against v16.

@@ -387,7 +387,7 @@ export function wrapFieldResolver<TSource = any, TContext = any, TArgs = any>(
>
>(
() => {
return fieldResolver.call(this, source, args, contextValue, info);
return fieldResolver.call(this, source, args, contextValue, info) as any;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The any used to be baked into the generic return type, whereas it now uses unknown instead, which is insufficient here.

@@ -976,7 +979,7 @@ describe('graphql', () => {
assert.deepStrictEqual(spans.length, 1);
});

it('should instrument parse with error', () => {
itMaybe('should instrument parse with error', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test doesn't work on Node.js v8 and Node.js v10 when using graphql v16, so make only run it on more recent versions of Node.js.

@dchambers
Copy link
Contributor Author

HI @rauno56 / @dyladan 👋 . A week has passed by. Anyway to get this PR moving again?

As a recap it's ready to merge now with some quirks due to upgrading internally to use v16, or there's the option to use v15 internally if you prefer not to have the quirks?

@dchambers
Copy link
Contributor Author

ℹ️ If you're using Yarn then you can actually just force it to use graphql v16 using the resolutions block since the code changes in this PR are only needed for the test code and for the TypeScript types, and are not required for the running of the plugin itself. Here's the config I used in my case:

"resolutions": {
  "@opentelemetry/instrumentation-graphql@npm:0.27.4/graphql": "^16.5.0",
},

@github-actions
Copy link
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@vmarchaud
Copy link
Member

I'm not the right person to review this since i don't even know how graphql works but @open-telemetry/javascript-approvers if someone can that would be nice

@vmarchaud
Copy link
Member

@rauno56 i saw you made modification, are you ok with the current state of the PR ? I can review it if you can more eyes so we can merge this

@rauno56
Copy link
Member

rauno56 commented Oct 3, 2022

@dchambers , I removed the maybe-functionality in tests.

@vmarchaud, your review would be helpful for sure.

Copy link
Member

@rauno56 rauno56 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, @dchambers. Sorry, that it took so long to get merged.

@vmarchaud, nvm about my comment above. I think we can just merge it once CI becomes green.

@rauno56 rauno56 mentioned this pull request Oct 3, 2022
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants