{"action":"created","issue":{"url":"https://api.github.com/repos/jaydenseric/graphql-upload/issues/141","repository_url":"https://api.github.com/repos/jaydenseric/graphql-upload","labels_url":"https://api.github.com/repos/jaydenseric/graphql-upload/issues/141/labels{/name}","comments_url":"https://api.github.com/repos/jaydenseric/graphql-upload/issues/141/comments","events_url":"https://api.github.com/repos/jaydenseric/graphql-upload/issues/141/events","html_url":"https://github.com/jaydenseric/graphql-upload/issues/141","id":435432680,"node_id":"MDU6SXNzdWU0MzU0MzI2ODA=","number":141,"title":"Finish triggered twice, once with undefined operations","user":{"login":"NGPixel","id":15522395,"node_id":"MDQ6VXNlcjE1NTIyMzk1","avatar_url":"https://avatars3.githubusercontent.com/u/15522395?v=4","gravatar_id":"","url":"https://api.github.com/users/NGPixel","html_url":"https://github.com/NGPixel","followers_url":"https://api.github.com/users/NGPixel/followers","following_url":"https://api.github.com/users/NGPixel/following{/other_user}","gists_url":"https://api.github.com/users/NGPixel/gists{/gist_id}","starred_url":"https://api.github.com/users/NGPixel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NGPixel/subscriptions","organizations_url":"https://api.github.com/users/NGPixel/orgs","repos_url":"https://api.github.com/users/NGPixel/repos","events_url":"https://api.github.com/users/NGPixel/events{/privacy}","received_events_url":"https://api.github.com/users/NGPixel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-04-20T19:43:05Z","updated_at":"2019-04-21T00:20:23Z","closed_at":null,"author_association":"NONE","body":"Using Node.js **v10.15.3** on Ubuntu **18.04.2 LTS**\r\n\r\nI'm getting the error `BadRequestError: Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec).`\r\n\r\nAt first it looked like a middleware messing with the body, but after further debugging, the `operations` field is present and placing graphql-upload as the first middleware results in the same issue.\r\n\r\nAdding a few console.log in the `processRequest.js` file reveals that the `operations` field is found and parsed correctly. However, the `finish` event is called twice; once with an undefined `operations` and a second time with the proper value:\r\n\r\n```\r\nFIELD operations { operationName: null,\r\n  variables: { data: null },\r\n  extensions: {},\r\n  query:\r\n   'mutation ($file: Upload!) {\\n  assets {\\n    upload(data: $file) {\\n      responseResult {\\n        succeeded\\n        message\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n}\\n' }\r\nFIELD map {\"1\":[\"variables.data\"]}\r\n\r\nFINISH operations undefined\r\n[ { BadRequestError: Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec).\r\n    message:\r\n     'Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec).',\r\n    locations: undefined,\r\n    path: undefined,\r\n    extensions: { code: 'INTERNAL_SERVER_ERROR' } } ]\r\n\r\nFINISH operations { operationName: null,\r\n  variables: { data: Promise {\r\n     { filename: 'artwork.jpg',\r\n       mimetype: 'image/jpeg',\r\n       encoding: '7bit',\r\n       createReadStream: [Function: createReadStream] } } } },\r\n  extensions: {},\r\n  query:\r\n   'mutation ($file: Upload!) {\\n  assets {\\n    upload(data: $file) {\\n      responseResult {\\n        succeeded\\n        message\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n}\\n' }\r\n```\r\n\r\nAny idea what could be causing this?\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/jaydenseric/graphql-upload/issues/comments/485203796","html_url":"https://github.com/jaydenseric/graphql-upload/issues/141#issuecomment-485203796","issue_url":"https://api.github.com/repos/jaydenseric/graphql-upload/issues/141","id":485203796,"node_id":"MDEyOklzc3VlQ29tbWVudDQ4NTIwMzc5Ng==","user":{"login":"mike-marcacci","id":690517,"node_id":"MDQ6VXNlcjY5MDUxNw==","avatar_url":"https://avatars1.githubusercontent.com/u/690517?v=4","gravatar_id":"","url":"https://api.github.com/users/mike-marcacci","html_url":"https://github.com/mike-marcacci","followers_url":"https://api.github.com/users/mike-marcacci/followers","following_url":"https://api.github.com/users/mike-marcacci/following{/other_user}","gists_url":"https://api.github.com/users/mike-marcacci/gists{/gist_id}","starred_url":"https://api.github.com/users/mike-marcacci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike-marcacci/subscriptions","organizations_url":"https://api.github.com/users/mike-marcacci/orgs","repos_url":"https://api.github.com/users/mike-marcacci/repos","events_url":"https://api.github.com/users/mike-marcacci/events{/privacy}","received_events_url":"https://api.github.com/users/mike-marcacci/received_events","type":"User","site_admin":false},"created_at":"2019-04-21T00:20:23Z","updated_at":"2019-04-21T00:20:23Z","author_association":"COLLABORATOR","body":"Hmm, this is indeed weird behavior. Given that this library never actually emits a `finish` event, I do suspect that your initial idea is correct: another middleware might be directly manipulating the request stream. Because streams are processed asynchronously, it likely doesn't matter that the middleware order was switched – child middleware will be called (and can fire off a stray `finish` event) as soon as the `map` field is parsed.\r\n\r\nOne thing to note here is that in order for a stream to be split to multiple consumers and provide the same exact content to all of them, them must all be attached synchronously, and in the same js event frame. In other words, a consumer that's attached to a partially-consumed stream will only receive the remaining data.\r\n\r\nIf you *do* have a use case that requires a stream to be forked like this (which is unlikely), you'll have to create your own koa/express middleware and directly call graphql-upload's [`processRequest()`](https://github.com/jaydenseric/graphql-upload#function-processrequest) with the relevant streams.\r\n\r\nEither way, I'd first try removing the other middleware to see if you can reproduce the problem with this library on its own. More generally, look for anything else that might be working directly with the request stream; this is probably the culprit.\r\n\r\nHope that helps, and best luck tracking this down!"}}
{"actor":{"display_login":"mike-marcacci"}}