Expected type "Upload". Upload value invalid.
See original GitHub issueIssue
When uploading a file:
// what the file looks like when it is given to the mutation on the client side (copied and pasted this from the console)
{
lastModified: 1621800013047,
lastModifiedDate: Mon May 24 2021 08:00:13 GMT+1200 (New Zealand Standard Time) {},
name: "avatar",
size: 1083999,
type: "image/png",
webkitRelativePath: "",
__proto__: File
}
using graphql-upload
, I get back an error:
Variable "$file" got invalid value
{
resolve: [function],
reject: [function],
promise: {},
file: {
filename: "avatar",
mimetype: "image/png",
encoding: "7bit",
createReadStream: [function createReadStream]
}
};
Expected type "Upload". Upload value invalid.
Stack:
NOTE: this isnt the exact code, ive just simplified these down a bit to include the important bits
Client side
import { ApolloClient } from '@apollo/client' // v3.3.19
import { createUploadLink } from 'apollo-upload-client' // v15.0.0
const PORT = '18087'
const httpEndpoint = 'http://localhost:${PORT}/graphql'
export function createProvider () {
const apolloClient = new ApolloClient({
// ....
link: createUploadLink({ uri: httpEndpoint })
})
const apolloProvider = new VueApollo({
defaultClient: apolloClient
})
return apolloProvider
}
Server side
// typeDefs
scalar Upload
type Mutation {
uploadFile(file: Upload!): Blob
}
// resolvers
const { Upload } = require('graphql-upload')
{
Mutation: {
uploadFile: (_, { file }) => postUploadFile(file)
},
Upload
}
const express = require('express') // v4.17.1
const { graphqlHTTP } = require('express-graphql') // v0.12.0
const { graphqlUploadExpress } = require('graphql-upload') // v12.0.0, graphql=v15.5.0
const cors = require('cors') // v2.8.5
const { buildFederatedSchema } = require('@apollo/federation') // v0.19.1
const app = express()
app.use(cors())
const schema = buildFederatedSchema([
// different typeDef + resolvers, one including graphql-upload
])
const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB
app.use(
'/graphql',
graphqlUploadExpress({ maxFileSize: MAX_FILE_SIZE, maxFiles: 10 }),
graphqlHTTP({
schema,
// context,
graphiql: true
}
)
const httpServer = http.createServer(app)
// ... starts server
We found that the issue came from the parseValue
part of the Upload scalar:
We just added a temporary fix that doesn’t check:
if (value instanceof Upload) return value.promise;
and does this instead:
return value.promise
Tried looking at the tests in this module and many other ones, but couldnt find a good example of a test that shows what value should look like.
Apologies if this isnt the right module to post this!
Other details
- node v14.16.1
- npm v7.11.2
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Question about 'Upload value invalid' error. #219 - GitHub
when running a query with Postman, I get the error: Variable \"$picture\" got invalid value {}; Expected type Upload. Upload value invalid.
Read more >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 >Issue with Upload API of item - monday Apps & Developers
Im getting this error. {"errors":[{"message":"Variable file of type File! was provided invalid value","locations":[{"line" ...
Read more >400 Bad request when uploading a file via GraphQL
I'm trying to implement a single file upload. ... as a value of the file variable in the mutation, the error says "…got...
Read more >Data Import error message reference - Analytics Help
Message Meaning So...
Empty column header at column number X. The upload file is missing a column header. Ed...
Multiple errors occurred: List of multiple...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It looks like the
Upload
scalar JS is not setup correctly; it appears you’re using:When it should be:
See:
https://github.com/jaydenseric/graphql-upload#class-graphqlupload
As a side note, it’s a good idea to always use deep imports when they are available:
This way only exactly the JS you need in a given context loads into memory, and if you ever bundle that code you won’t rely on slow and unreliable “tree-shaking”.
Closing because I don’t think anything is actionable here, but feel free to continue the conversation or share tips for anyone else in the same boat.