question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about 'Upload value invalid' error.

See original GitHub issue

Hi! I’m sorry if this is not the best way for adding this, please direct me to a better place if that’s the case. I followed your implementation for adding Upload capabilities to an existing application. The code uses the GraphQLUpload and FileUpload classes, and the mutation looks something like this:

@typeGraphql.Mutation(() => Boolean)
    async addProfilePicture(
        @typeGraphql.Arg("picture", () => GraphQLUpload)
        {
        createReadStream,
        filename
        }: FileUpload): Promise<boolean> {
      return new Promise(async (resolve, reject) =>
        createReadStream()
          .pipe(createWriteStream(__dirname + `/../../../images/${filename}`))
          .on("finish", () => resolve(true))
          .on("error", () => reject(false))
      );
    }

In Postman I have the following body:

operations:{"query":"mutation addProfilePicture($picture: Upload!) {addProfilePicture(picture: $picture)}", "variables": {"picture": null}}
map:{"0":["variables.picture"]}

and a local file added in the ‘0’ field.

when running a query with Postman, I get the error:

Variable \"$picture\" got invalid value {}; Expected type Upload. Upload value invalid

I’ve been at this for 3 days already. could use a bit of help…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
thachpcommented, Oct 24, 2020

@flashcrow2000 It took me a while to solve this problem. Give this a try… it worked for me. I’m using Node 15, NestJS Graphql

  1. Add to package.json
    "resolutions": {
        "graphql-upload": "^11.0.0"
    },
  1. Check to make sure that there is only one graphql-upload folder under your node_modules. I used yarn why, and manually checked dir node_modules/apollo-server-core/node_modules. There should only be three visible dir under it … (apollo-graphql, apollo-server-types and graphql-tools)
yarn why v1.22.4
[1/4] Why do we have the module "graphql-upload"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "graphql-upload@11.0.0"
info Reasons this module exists
   - "apollo-server-core" depends on it
   - Hoisted from "apollo-server-core#graphql-upload"
   - Hoisted from "@nestjs#graphql#apollo-server-core#graphql-upload"
info Disk size without dependencies: "1.19MB"
info Disk size with unique dependencies: "2.27MB"
info Disk size with transitive dependencies: "3.33MB"
info Number of shared dependencies: 18
Done in 0.80s.

  1. If you are using ApolloClient, make sure that you include the createUploadLink…
import { createUploadLink } from "apollo-upload-client";
...
export const gclient = new ApolloClient({
    cache: new InMemoryCache(),
    link: createUploadLink(),    
    uri: "/graphql"
});

  1. When filing your input variables, make sure that the file input value is type File or Blob. https://github.com/jaydenseric/graphql-upload/issues/185#issuecomment-583572804
0reactions
masouditcommented, Jan 16, 2022

Hi, it depends on ApolloClient that you used. 1- If used import { ApolloClient } from ‘apollo-client’ must be used “createUploadLink” instead of "createHttpLink "means,

import { createUploadLink } from 'apollo-upload-client'
const httpLink = createUploadLink({
  uri: httpEndpoint,
})

2- if used createApolloClient, exact this package:

import { createApolloClient, restartWebsockets } from 'vue-cli-plugin-apollo/graphql-client'
const { apolloClient, wsClient } = createApolloClient({
    ...defaultOptions,
    ...options,
  })
``
You do not need to set anything and Upload work complete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Variable "$file" got invalid value {}; Upload value invalid
I am using typegraphql and graphql-upload on my backend: @Mutation(() => Boolean) async uploadImage( @Arg('file', () => GraphQLUpload) upload: ...
Read more >
400 Bad request when uploading a file via GraphQL
I'm trying to implement a single file upload. ... still get the same error → "“Variable “$file” got invalid value {}; Upload value...
Read more >
Failed when trying to upload a file from Graphql
My problem is with the updateFieldsValues mutation. ... "errors": [ { "message": "Invalid input: foto_do_cnpj_cpf ([\"uploads/7c3b7885-16d5- ...
Read more >
Focused Build - Error Uploading Test Script : "Invalid value for ...
The error received upon upload is: "Invalid value for step number: 1.10." Steps to reproduce: Download the .txt file attached to this question...
Read more >
How can I fix the UTF-8 error when bulk uploading users?
Open the CSV file from Excel and verify the data: Even if you find a problem, do not save the file in Excel....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found