title: Exporting CSV from Django/Graphql
body: <p>I need to generate and output a csv file/data from my db data to my frontend.</p>
  
  <p>I found this and followed the instructions: <a href="https://docs.djangoproject.com/en/2.2/howto/outputting-csv/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/2.2/howto/outputting-csv/</a></p>
  
  <p>However, I am using graphql and graphene. The instructions above don't say in what format the output should be returned. When I return plain <code>String</code>, all I get returned is <code>"&lt;HttpResponse status_code=200, \"text/csv\"&gt;"</code>.</p>
  
  <p>Example of code:</p>
  
  <pre><code>class Query:
      users_csv = graphene.String()
      ...
  
      @classmethod
      @login_required
      def resolve_users_csv(cls, obj, info):
          response = HttpResponse(content_type="text/csv")
          writer = csv.writer(response)
  
          header = [
              "EmployeeEmail",
              "TeamMemberName",
              "PhoneNumber",
              "MobileNumber",
              "IsAdmin",
          ]
          content = []
          for u in User.objects.filter(customer=info.context.user.customer):
              content.append(
                  [
                      str(u.email) if u.email else "",
                      str(u.get_full_name()),
                      str(u.phone_number) if u.phone_number else "",
                      str(u.mobile_number) if u.mobile_number else "",
                      str(u.is_admin),
                  ]
              )
  
          writer.writerow(header)
          writer.writerows(content)
          return response
  </code></pre>
  
  <p>Any help or pointers is very appreciated...</p>