Skip to content

Commit

Permalink
feat: support GraphQL Upload Spec (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxtaa authored Aug 28, 2020
1 parent 9324747 commit 777cc55
Show file tree
Hide file tree
Showing 7 changed files with 9,186 additions and 11 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,43 @@ async function main() {
main().catch((error) => console.error(error))
```

### File Upload

#### Browser

```js
import { request } from 'graphql-request'

const UploadUserAvatar = gql`
mutation uploadUserAvatar($userId: Int!, $file: Upload!) {
updateUser(id: $userId, input: { avatar: $file })
}
`

request('/api/graphql', UploadUserAvatar, {
userId: 1,
file: document.querySelector('input#avatar').files[0],
})
```

#### NodeJS

```js
import { createReadStream } from 'fs'
import { request } from 'graphql-request'

const UploadUserAvatar = gql`
mutation uploadUserAvatar($userId: Int!, $file: Upload!) {
updateUser(id: $userId, input: { avatar: $file })
}
`

request('/api/graphql', UploadUserAvatar, {
userId: 1,
file: createReadStream('./avatar.img'),
})
```

[TypeScript Source](examples/receiving-a-raw-response)

### More examples coming soon...
Expand Down
Loading

0 comments on commit 777cc55

Please sign in to comment.