File Uploading
GraphQL CMS also supports file uploading.
By default it is impossible to automatically define which fields in GraphQL Type has to be used to save information on uploaded file.
For example we have field primaryImage: {type: GraphQLString},
in productType
which we want to use to save uploaded file name.
To be able to do that we have to extend config object.
We need to add uploadRoot
property where we are defining full path to your public folder.
In inputType
property of current field we are defining type 'file'.
You can also provide uploadPath
property to specify where to save the file for a particular Type:
`domain.com/${uploadPath}/${file}`
If you don't provide uploadPath
by default in uploadRoot
it will create a folder productType
where it will save all uploaded files for productType
.
let config = {
schema: printSchema(schema),
exclude: ['paymentType'],
uploadRoot: '/var/www/site.com/public',
rules: {
productType: {
uploadPath: 'product',
fields: {
primaryImage: {
inputType: 'file'
}
}
}
}
};
Code above will generate the following:
And preview on hover: