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

Reporting protobuf: conflict with other libraries #3312

Closed
pierre-elie opened this issue Sep 18, 2019 · 3 comments · Fixed by #3539
Closed

Reporting protobuf: conflict with other libraries #3312

pierre-elie opened this issue Sep 18, 2019 · 3 comments · Fixed by #3539

Comments

@pierre-elie
Copy link

  • package apollo-engine-reporting-protobuf
  • version 0.4.0
  • node 12.10.0

apollo-engine-reporting-protobuf modifies the behavior of 3rd party package protobufjs by removing its support for Long:

const protobufJS = require('protobufjs/minimal');
// Remove Long support. Our uint64s tend to be small (less
// than 104 days).
// https://github.com/protobufjs/protobuf.js/issues/1253
protobufJS.util.Long = undefined;
protobufJS.configure();

This is an issue for other packages depending on protobufjs, in my case @google-cloud/logging.

Whenever I try to send logs via Google Cloud's lib I get the following exception:

(node:66122) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'fromNumber' of undefined
    at Field.resolve (/Volumes/Double/graphql-server/node_modules/protobufjs/src/field.js:289:38)
    at Type.setup (/Volumes/Double/graphql-server/node_modules/protobufjs/src/type.js:435:41)
    at Type.encode_setup [as encode] (/Volumes/Double/graphql-server/node_modules/protobufjs/src/type.js:485:17)
    at Type.LogEntry$encode [as encode] (eval at Codegen (/Volumes/Double/graphql-server/node_modules/@protobufjs/codegen/index.js:50:33), <anonymous>:19:12)
    at Type.encode_setup [as encode] (/Volumes/Double/graphql-server/node_modules/protobufjs/src/type.js:485:25)
    at BundleDescriptor.getByteLength [as byteLengthFunction] (/Volumes/Double/graphql-server/node_modules/google-gax/src/grpc.ts:322:22)
    at /Volumes/Double/graphql-server/node_modules/google-gax/src/bundlingCalls/bundleExecutor.ts:139:40
    at Array.forEach (<anonymous>)
    at BundleExecutor.schedule (/Volumes/Double/graphql-server/node_modules/google-gax/src/bundlingCalls/bundleExecutor.ts:138:18)
    at /Volumes/Double/graphql-server/node_modules/google-gax/src/bundlingCalls/bundleApiCaller.ts:77:20

...which makes sense, since Longs are not supported anymore by the lib.

It seems very "aggressive" to change a global library potentially used by other dependencies.

@allenhartwig
Copy link

I too am experiencing problems with my application's functionality with this tampering of the protobufjs library.

What I have done as a temporary measure to prevent this undefined assignment to Long is to put the following snippet before importing apollo-server.

const protobufJS = require('protobufjs/minimal');
const utilProxy = new Proxy(protobufJS.util, {
  set(obj, prop, value) {
    if (prop !== "Long") {
      obj[prop] = value;
    }
  }
});
protobufJS.util = utilProxy;

Hopefully the Apollo team finds a better means of dealing with this soon.

@tizmagik
Copy link

Thanks for reporting this @pierre-elie I just hit this recently, too, trying to use @google-cloud/logging-winston in an apollo server. I originally thought it was some bug in Google's code, but now this makes more sense. Thanks for the workaround for now @allenhartwig

@trevor-scheer
Copy link
Member

Thank you all for the report!

This is resolved in the latest release:
8d065d8

Please update your apollo-server-* and @apollo/gateway versions to latest!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 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 a pull request may close this issue.

4 participants