Apollo-server: Reporting protobuf: conflict with other libraries

Created on 19 Sep 2019  ·  3Comments  ·  Source: apollographql/apollo-server

  • 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:

    https://github.com/apollographql/apollo-server/blob/e8faacbd6150999abd5376de64d2a7e44e541f9d/packages/apollo-engine-reporting-protobuf/src/index.js#L2-L8

    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.

    Most helpful comment

    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.

    All 3 comments

    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.

    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

    Thank you all for the report!

    This is resolved in the latest release:
    https://github.com/apollographql/apollo-server/commit/8d065d8b8b7f35f814695e74f5c685b7d68d5e00

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

    Was this page helpful?
    0 / 5 - 0 ratings