2

below code is for mutation

field :companyUpdate, Types::CompanyType do
    argument :id, !types.ID
    argument :file, Types::FileType
    resolve -> (obj, args, ctx) {
      company = ::Network::Company.find(args[:id])
      company.update!(logo: args[:file])
      company
    }
  end

and file_type.rb is

    Types::FileType = GraphQL::ScalarType.define do
  name 'File'
  description 'action_dispatch_uploaded_file'
  coerce_input ->(action_dispatch_uploaded_file, ctx) {
    action_dispatch_uploaded_file
  }
end

it is not working. apollo client is using apollo-upload-client for uploading the file but it gives error as file is null. what's the solution?

Vimox Shah
  • 99
  • 1
  • 9

1 Answers1

-4

Define a File type in your schema. submit the form normally! In the server side, before sending data to GraphQL resolver, save the file and store change the variable!

something like this.

Update:

Apollo Server 2 has file upload support! use this article from Apollo in order to have file upload support in your backend:

  • I did not get can you explain little bit more? how can I store file before sending data to resolver? @mohsen-zarezardeyni – Vimox Shah Jun 06 '18 at 05:55