Gorodov Maksim
07/08/2018, 9:16 AM// datamodel.graphql
type File {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
filename: String!
mimetype: String!
encoding: String!
url: String! @unique
}
// schema.graphql
uploadFile(file: Upload!): File!
// mutation.js
const uploadFile = async(_, args, context, info) => {
console.log(args.file) // always {}
return await processUpload(await args.file, context);
};
Frontend:
// mutation.js
export const UPLOAD_FILE = gql`
mutation uploadFile($file: Upload!) {
uploadFile(file: $file) {
id
}
}
`;
// it is onChange handler for input[type='file']
const file = e.currentTarget.files[0];
console.log(file); // checkout this screenshot to see what is in 'file' - <http://prntscr.com/k3vso2>
if (file) {
uploadFile({
variables: {
file: file,
},
});
}
Also, maybe it is because my client on frontend configured not correctly, here is a gist of it's configuration - https://gist.github.com/SilencerWeb/67237dd3f1300149bd5e743614e96c94