Exporting Data
This guide gives information common to all exports. At this time, only the export of products and gift cards is available.
Workflow​
Schedule export​
The chart below describes what the workflow looks like for each export. The changes for each export involve the mutation and the background worker adapted to the data type.
sequenceDiagram
Client ->>+ Saleor: mutation
Saleor ->> Saleor: Validate input data
Saleor ->>+ Background Worker: Schedule export
Background Worker -->>- Saleor: Scheduled
Saleor -->>- Client: return ExportFile instance
Handling background worker result​
Background worker result is also handled in the same way for all workers. The chart below shows what happens in case of the successful and failed worker results.
graph TD
D[Export data <br> Background Worker] -->|Success| E[Send email to user <br> with a link to <br> download file]
D -->|Success| X[Set SUCCESS <br>ExportFile status]
E -->Y[Create export file <br>sent event]
X -->F[Create data export <br>success event]
D -->|Failed| G[Set FAILED <br>ExportFile status]
G --> U[Create data export <br>failed event]
U --> J[Send email to the user<br>with information <br>about failing export]
J --> K[Create export failed <br>info sent event]
Mutations​
The input data for the mutations may differ insignificantly, but all of them return the same data type: the ExportFile object, being a Job instance.
It corresponds to running the export background worker, keeping task status, and creating a file.
ExportFile object contains the following fields:
id: a unique export file ID. Could be use to check export status.status: status of running the job.user: instance ofUserwho requested exporting products. Set tonullif export requested byApp.app: instance ofAppwhich requested exporting products. Set tonullif export requested byUser.createdAt: the date and time when the export was started.updatedAt: the date and time when the job was last time updated.url: URL to the exported file. Set tonullwhen the file doesn't exist yet.events: a list of events associated with the export.
In addition, the following field is available on every mutation result:
errors: a list of errors that occurred during mutation execution.
Fetching ExportFile instance​
Export is done in the asynchronous worker, so as a result, you might get an export file instance with a PENDING status. To check if the task status has changed, you can fetch ExportFile by ID with the use of exportFile query:
- Query
- Variables
- Result
query ExportFile($id: ID!){
exportFile(id: $id) {
id
status
createdAt
updatedAt
url
}
}
{
"id": "RXhwb3J0RmlsZToxMA=="
}
{
"data": {
"exportFile": {
"id": "RXhwb3J0RmlsZToxMA==",
"status": "SUCCESS",
"createdAt": "2020-06-05T09:15:42.924676+00:00",
"updatedAt": "2020-06-05T09:16:27.691838+00:00",
"url": "http://localhost:8000/media/export_files/product_data_05_06_2020.csv"
}
}
}