Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find variable: FileList error in React Native #200

Closed
sijad opened this issue Mar 26, 2019 · 4 comments
Closed

Can't find variable: FileList error in React Native #200

sijad opened this issue Mar 26, 2019 · 4 comments
Assignees
Labels
blocking Prevents production or dev due to perf, bug, build error, etc.. bug 🐛 has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository

Comments

@sijad
Copy link

sijad commented Mar 26, 2019

in react native all requests throw this error: "Can't find variable: FileList".

@fbartho fbartho self-assigned this Mar 26, 2019
@fbartho fbartho added bug 🐛 blocking Prevents production or dev due to perf, bug, build error, etc.. has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository labels Mar 26, 2019
@fbartho
Copy link
Collaborator

fbartho commented Mar 26, 2019

Fixed in the newly published v0.7.2

Please let me know if that works for you @sijad

@fbartho fbartho closed this as completed Mar 26, 2019
@sijad
Copy link
Author

sijad commented Mar 26, 2019

yes it's fixed, thanks for your fast response.

@moseslucas
Copy link

@sijad How were you able to upload files in apollo-link-rest ?
Can you share how you passed the fileList in your mutation code?

@NickAlvesX
Copy link

@moseslucas for me it worked this way:

Mutation:

<Mutation mutation={UPLOAD__FILE} {...props}>
  {(upload, { data }) => children({ data, uploadFile: uploadFile(upload) })}
</Mutation>

Upload File func:

const uploadFile = upload => async file => {
  try {
    const result = await upload({ variables: { input: file } })
    return result
  } catch (err) {
    const errors = err.networkError ? err.networkError.result || [err.networkError] : [err]
    return { errors }
  }
}

Query:

const UPLOAD_FILE = gql`
  mutation uploadFile($input: File!) {
    uploadFile(input: $input)
      @rest(
        type: "File"
        path: "YOUR_API_URL"
        method: "POST"
        bodySerializer: "fileEncode"
      ) {
      // response data
    }
  }
`

RestLink Serializer:

import { RestLink } from 'apollo-link-rest'

const restLink = new RestLink({
  uri: BASE_URL,
  bodySerializers: {
    fileEncode: (data: any, headers: Headers) => {
      const formData = new FormData()
      formData.append('file', data, data.name)
      headers.set('Accept', '*/*')
      return { body: formData, headers }
    }
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking Prevents production or dev due to perf, bug, build error, etc.. bug 🐛 has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository
Projects
None yet
Development

No branches or pull requests

4 participants