Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
gullitmiranda-apollo-upload-client
Advanced tools
Enhances Apollo Client for intuitive file uploads via GraphQL mutations.
Enhances Apollo for intuitive file uploads via GraphQL mutations or queries. Use with apollo-upload-server.
Install with npm:
npm install apollo-upload-client
Setup Apollo Client with a special network interface:
import ApolloClient from 'apollo-client'
import { createNetworkInterface } from 'apollo-upload-client'
const client = new ApolloClient({
networkInterface: createNetworkInterface({
uri: '/graphql'
})
})
Alternatively enable query batching:
import ApolloClient from 'apollo-client'
import { createBatchingNetworkInterface } from 'apollo-upload-client'
const client = new ApolloClient({
networkInterface: createBatchingNetworkInterface({
uri: '/graphql'
})
})
Also setup apollo-upload-server.
Once setup, you will be able to use FileList
, File
and ReactNativeFile
instances anywhere within mutation or query input variables.
With apollo-upload-server
setup, the files upload to a temp directory. Upload
input type metadata replaces file instances in the arguments received by the resolver. See the server usage.
See server usage for this example.
import React from 'react'
import { graphql, gql } from 'react-apollo'
export default graphql(gql`
mutation updateUserAvatar($userId: String!, $avatar: Upload!) {
updateUserAvatar(userId: $userId, avatar: $avatar) {
id
}
}
`)(({ userId, mutate }) => {
const handleChange = ({ target }) => {
if (target.validity.valid) {
mutate({
variables: {
userId,
avatar: target.files[0]
}
}).then(({ data }) => console.log('Mutation response:', data))
}
}
return (
<input
type="file"
accept={'image/jpeg,image/png'}
required
onChange={handleChange}
/>
)
})
See server usage for this example.
import React from 'react'
import { graphql, gql } from 'react-apollo'
export default graphql(gql`
mutation updateGallery($galleryId: String!, $images: [Upload!]!) {
updateGallery(galleryId: $galleryId, images: $images) {
id
}
}
`)(({ galleryId, mutate }) => {
const handleChange = ({ target }) => {
if (target.validity.valid) {
mutate({
variables: {
galleryId,
images: target.files
}
}).then(({ data }) => console.log('Mutation response:', data))
}
}
return (
<input
type="file"
accept={'image/jpeg,image/png'}
multiple
required
onChange={handleChange}
/>
)
})
React Native polyfills FormData under the hood and objects with the properties uri
, type
and name
substitute window.File
. It would be risky to assume all objects with those properties in variables are files. Use ReactNativeFile
instances in query or mutation variables to explicitly mark files for upload:
import { ReactNativeFile } from 'apollo-upload-client'
// ✂
// Single file
const file = new ReactNativeFile({
uri: uriFromCameraRoll,
type: 'image/jpeg',
name: 'photo.jpg'
})
// Multiple files
const files = ReactNativeFile.list({
uri: uriFromCameraRoll1,
type: 'image/jpeg',
name: 'photo-1.jpg'
}, {
uri: uriFromCameraRoll2,
type: 'image/jpeg',
name: 'photo-2.jpg'
})
// ✂
5.1.0
prepublishOnly
instead of prepublish
.ReactNativeFile
to a separate extract-files
package.FAQs
Enhances Apollo Client for intuitive file uploads via GraphQL mutations.
We found that gullitmiranda-apollo-upload-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.