profusion / apollo-federation-file-upload

Add file upload support to Apollo Federated services.
32 stars 27 forks source link

"TypeError: Right-hand side of 'instanceof' is not an object", #60

Closed garryburch closed 4 months ago

garryburch commented 2 years ago

When I test with:

class InspectionDataSource extends RemoteGraphQLDataSource {
  static extractFileVariables(rootVariables) {
    Object.values(rootVariables || {}).forEach((value) => {
      if (value instanceof Promise) {
        // this is a file upload!
        console.log(value);
      }
    });
  }

  process(args) {
    InspectionDataSource.extractFileVariables(args.request.variables);
    return super.process(args);
  }
}

I Get

Promise {
  {
    filename: 'testernumbers.csv',
    mimetype: 'text/csv',
    encoding: '7bit',
    createReadStream: [Function: createReadStream]
  }
}

As expected - then move to

buildService: ({ url }) => new FileUploadDataSource({ url }),

I run my mutation I get

{
    "errors": [
        {
            "message": "Right-hand side of 'instanceof' is not an object",
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "exception": {
                    "stacktrace": [
                        "TypeError: Right-hand side of 'instanceof' is not an object",
                        "    at /var/www/vhosts/APFM/local/web-hydra/node_modules/@profusion/apollo-federation-upload/build/FileUploadDataSource.js:73:31",
                        "    at Array.reduce (<anonymous>)",
                        "    at extract (/var/www/vhosts/APFM/local/web-hydra/node_modules/@profusion/apollo-federation-upload/build/FileUploadDataSource.js:67:52)",
                        "    at Function.extractFileVariables (/var/www/vhosts/APFM/local/web-hydra/node_modules/@profusion/apollo-federation-upload/build/FileUploadDataSource.js:96:16)",
                        "    at FileUploadDataSource.<anonymous> (/var/www/vhosts/APFM/local/web-hydra/node_modules/@profusion/apollo-federation-upload/build/FileUploadDataSource.js:103:56)",
                        "    at Generator.next (<anonymous>)",
                        "    at /var/www/vhosts/APFM/local/web-hydra/node_modules/@profusion/apollo-federation-upload/build/FileUploadDataSource.js:8:71",
                        "    at new Promise (<anonymous>)",
                        "    at __awaiter (/var/www/vhosts/APFM/local/web-hydra/node_modules/@profusion/apollo-federation-upload/build/FileUploadDataSource.js:4:12)",
                        "    at FileUploadDataSource.process (/var/www/vhosts/APFM/local/web-hydra/node_modules/@profusion/apollo-federation-upload/build/FileUploadDataSource.js:102:16)",
                        "    at sendOperation (/var/www/vhosts/APFM/local/web-hydra/node_modules/@apollo/gateway/dist/executeQueryPlan.js:159:40)",
                        "    at executeFetch (/var/www/vhosts/APFM/local/web-hydra/node_modules/@apollo/gateway/dist/executeQueryPlan.js:111:47)",
                        "    at executeNode (/var/www/vhosts/APFM/local/web-hydra/node_modules/@apollo/gateway/dist/executeQueryPlan.js:82:23)",
                        "    at Object.executeQueryPlan (/var/www/vhosts/APFM/local/web-hydra/node_modules/@apollo/gateway/dist/executeQueryPlan.js:22:33)",
                        "    at Object.ApolloGateway.executor (/var/www/vhosts/APFM/local/web-hydra/node_modules/@apollo/gateway/dist/index.js:109:55)",
                        "    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
                    ]
                }
            }
        }
    ],
    "data": null,
    "extensions": {
        "tracing": {
            "version": 1,
            "startTime": "2022-10-14T18:47:14.574Z",
            "endTime": "2022-10-14T18:47:14.579Z",
            "duration": 5510152,
            "execution": {
                "resolvers": []
            }
        }
    }
}

I can use the Apollo-server service and it works just fine with graphql-upload - move this into our federation gateway and the above is our results so far. - Thanks for the help