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
Image/file upload mutation example? #24
Comments
I found something but i think its outdated: https://medium.com/@danielbuechele/file-uploads-with-graphql-and-apollo-5502bbf3941e#.qpca4mzfd |
I have same problem. Example will help a lot. |
@dsdjolence I using other endpoint to only upload files. |
I found for Apollo 2+ there is plugin that can allow upload files with GraphQL |
@Samuell1 did you get this work with vue-apollo and apollo-upload-client? I currently try but the issue is that the |
nevermind just found the solution in the react examples. |
@dohomi did you find the solution for vue-apollo or nuxt-community/apollo-module? |
@razorabhu1995 the NULL client side debug is happening because the server already took over to process the data upload. As long you see the right mutation according to the apollo-upload-client it should work finde. apollo-module let you use file-upload out of the box (make sure you use the most recent version of all the modules - maybe remove node_modules and reinstall to make 100% sure that all packages are up-to-date) |
Hey @dohomi I'm still getting NULL when I try to upload a file.
|
Did anyone get this to work? |
apollo-upload-client does not have to be imported and integrated. It is already part of vue-apollo, and already integrated.So no need to do anything. |
but how do you exactly do it in vue-apollo? there is no documentation found in the apollo.vuejs.org . |
An example will be great :) |
@jongbonga just pass a file parameter to your mutation something like this:
|
Hi everyone, I get the following error when I pass file to mutation.
Everything should be working but I can't seem to find any example has anyone of your succeeded in finding one?? |
Hey @asolopovas, can you put an example of your mutation? because it seems your passing an empty array. |
here is the example of how I call my mutation: await this.$apollo.mutate({
mutation: require('@/app/graphql/mutations/CreateProduct.gql'),
variables: {
name: item.name,
productImage: item.upload,
units: item.units,
price: item.price,
category: item.category.id
},
context: {
hasUpload: true
}
}) when I here is the example of my mutation: mutation(
$name: String!
$units: Int!
$productImage: Upload!
$price: Float!
$category: ID!
) {
createProduct(input: {
name: $name
units: $units
productImage: $productImage
price: $price
category: { connect: $category }
}) {
id
category {
name
}
}
} |
https://github.com/wolfiton/vue-upload helped me out a lot |
yarn add @apollo/client apollo-upload-client This worked for me. |
As @alexsedeke mentioned, you don't need to add Note that the server you are calling must have configured an Upload integration. // Cache
const cache = new InMemoryCache();
// Create the apollo client
export const apolloClient = new ApolloClient({
uri: 'LINK TO YOUR GRAPHQL SERVER', // Replace here
cache,
});
// Mutation
const UPLOAD_MUTATION = gql`
mutation UploadFile($file: Upload!) {
uploadFile(file: $file)
}
`;
// Call mutation in V4 of VueApollo
const { mutate } = useMutation(UPLOAD_MUTATION);
// Make sure this is a file
mutate({ file });
// Or use the apolloClient
apolloClient.mutate({
mutation: UPLOAD_MUTATION,
variables: { file },
}); Hope it helps! |
AND
are currently (Apollo Vuejs client V4) WRONG. You have to use the const client = new ApolloClient({
link: ApolloLink.from([
// ...
new HttpLink({
uri: '/graphql'
})
])
}) (Source: https://dev.to/marvinrabe/file-upload-with-vue-apollo-client-and-graphql-5emb) Then you can use the normal mutation including the "Upload" Scalar. |
No description provided.
The text was updated successfully, but these errors were encountered: