At BenchPrep, we want to allow you to leverage all the power of GraphQL. Chief among that power is the ability to ask for what you want, get your results, and generate a downloadable CSV. Additionally, we support sending yourself an email with the CSV file to download.
Let's walk through that process.
List of Records
A GraphQL query can return a list of the records with any fields we want (check out Writing Your First Query). Let's fire it up and grab the list of users with some of their attributes:
Getting the CSV file
Now, let's focus on getting that output and streaming it to us. For that, we will fire up same request to the different endpoint: https://benchprep.com/api/graphql/export/csv
The query itself must be supplied in the query parameter and all your other GraphQL parameters (like variables, operationName) are supported. A great way to grab that request is by clicking COPY CURL on the top right of the playground. Example:
That returned the CSV file; let's take at look at it.
As you can see, each field became a column and each node became a row. We do allow overwriting of the headers using aliases. For example, let's rename state to status and createdAt to creation_date.
Limitations / Assumptions
In order for this process to work, certain assumptions were made:
- We are exporting multiple records, hence it only works for Connections with nodes.
- Non-nodes fields will be ignored.
- Only one query at a time can be converted to the CSV
- Nested fields will be joined by a semicolon delimiter
- Current max page size is 1500
If you need to export more data or if the dataset is large, we recommend taking advantage of our asynchronous exporting. You can achieve that by sending a request here.
In that case, the system will create a background task to generate the CSV file. Once it is complete, the system will send the short-lived download link for the generated CSV file to the email associated with the token.