Skip to content

Commit

Permalink
Update upload docs with Apollo usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bai Chan Kheo committed Mar 6, 2020
1 parent a538119 commit 6419030
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/content/reference/file-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,34 @@ That invokes the following operation:
```

See the [example/fileupload](https://github.com/99designs/gqlgen/tree/master/example/fileupload) package for more examples.

# Usage with Apollo

[apollo-upload-client](https://github.com/jaydenseric/apollo-upload-client) needs to be installed in order for file uploading to work with Apollo:

```javascript
import ApolloClient from "apollo-client";
import { createUploadLink } from "apollo-upload-client";

const client = new ApolloClient({
cache: new InMemoryCache(),
link: createUploadLink({ uri: "/graphql" })
});
```

A `File` object can then be passed into your mutation as a variable:

```javascript
{
query: `
mutation($file: Upload!) {
singleUpload(file: $file) {
id
}
}
`,
variables: {
file: new File(...)
}
}
```

0 comments on commit 6419030

Please sign in to comment.