{"action":"closed","issue":{"url":"https://api.github.com/repos/jaydenseric/apollo-upload-server/issues/73","repository_url":"https://api.github.com/repos/jaydenseric/apollo-upload-server","labels_url":"https://api.github.com/repos/jaydenseric/apollo-upload-server/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/jaydenseric/apollo-upload-server/issues/73/comments","events_url":"https://api.github.com/repos/jaydenseric/apollo-upload-server/issues/73/events","html_url":"https://github.com/jaydenseric/apollo-upload-server/issues/73","id":320389198,"number":73,"title":"Getting an empty object {} in server instead of file","user":{"login":"saostad","id":16025625,"avatar_url":"https://avatars3.githubusercontent.com/u/16025625?v=4","gravatar_id":"","url":"https://api.github.com/users/saostad","html_url":"https://github.com/saostad","followers_url":"https://api.github.com/users/saostad/followers","following_url":"https://api.github.com/users/saostad/following{/other_user}","gists_url":"https://api.github.com/users/saostad/gists{/gist_id}","starred_url":"https://api.github.com/users/saostad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saostad/subscriptions","organizations_url":"https://api.github.com/users/saostad/orgs","repos_url":"https://api.github.com/users/saostad/repos","events_url":"https://api.github.com/users/saostad/events{/privacy}","received_events_url":"https://api.github.com/users/saostad/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-05-04T18:54:06Z","updated_at":"2018-05-08T12:33:26Z","closed_at":"2018-05-08T12:33:26Z","author_association":"NONE","body":"Hi, \r\nI am getting an empty object in server!\r\ncan you please tell me what is my problem?\r\n\r\n**server.js:** \r\n```\r\napp.use(\r\n  \"/graphql\",\r\n  bodyParser.json(),\r\n  apolloUploadExpress(/* Options */),\r\n  graphqlExpress((req: any) => {\r\n    return {\r\n      schema,\r\n      context: {\r\n        EMP_ID: req.EMP_ID\r\n      }\r\n    };\r\n  })\r\n);\r\n```\r\n\r\n**Type Definition:** \r\n```\r\nscalar Upload\r\ntype File {\r\n  id: ID!\r\n  path: String!\r\n  filename: String!\r\n  mimetype: String!\r\n  encoding: String!\r\n}\r\n```\r\n\r\n**Mutations:** \r\n`uploadFile (file: Upload!): File!`\r\n\r\n**resolvers object:**\r\n```\r\nimport { GraphQLUpload } from \"apollo-upload-server\";\r\nconst resolvers = {\r\n  Upload: GraphQLUpload,\r\n  Query: queryResolvers,\r\n  Mutation: mutationsResolvers\r\n};\r\n```\r\n\r\n**Resolver:** \r\n`uploadFile: (_: any, { file }) => saveFile.processUpload(file)`\r\n\r\n**saveFile Module:** \r\n```\r\nimport * as fs from \"fs\";\r\nimport { logger } from \"./index\";\r\n\r\nconst uploadDir = \"./uploads\";\r\n\r\nconst storeFS = ({ stream, filename }) => {\r\n  const id = Date.now();\r\n  const path = `${uploadDir}/${id}-${filename}`;\r\n  return new Promise((resolve, reject) =>\r\n    stream\r\n      .on(\"error\", error => {\r\n        if (stream.truncated)\r\n          // Delete the truncated file\r\n          fs.unlinkSync(path);\r\n        reject(error);\r\n      })\r\n      .pipe(fs.createWriteStream(path))\r\n      .on(\"error\", error => reject(error))\r\n      .on(\"finish\", () => resolve({ id, path }))\r\n  );\r\n};\r\n\r\nconst processUpload = async upload => {\r\n  try {\r\n    console.log(upload);\r\n    const { stream, filename, mimetype, encoding } = await upload;\r\n    console.log(stream, filename, mimetype, encoding);\r\n    return await storeFS({ stream, filename });\r\n  } catch (error) {\r\n    logger.log(error);\r\n  }\r\n};\r\n\r\nexport const saveFile = {\r\n  processUpload\r\n};\r\n```\r\n\r\n**In Client in React Component:**\r\n```\r\nimport React from \"react\";\r\n\r\nimport { graphql } from \"react-apollo\";\r\nimport gql from \"graphql-tag\";\r\n\r\nconst UploadFile = ({ mutate }) => {\r\n  const handleChange = ({\r\n    target: {\r\n      validity,\r\n      files: [file]\r\n    }\r\n  }) => {\r\n    validity.valid &&\r\n      mutate({\r\n        variables: { file }\r\n      });\r\n  };\r\n\r\n  return <input type=\"file\" required onChange={handleChange} />;\r\n};\r\n\r\nexport default graphql(gql`\r\n  mutation($file: Upload!) {\r\n    uploadFile(file: $file) {\r\n      id\r\n      filename\r\n      encoding\r\n      mimetype\r\n      path\r\n    }\r\n  }\r\n`)(UploadFile);\r\n```"}}
{"actor":{"display_login":"jaydenseric"}}