keystonejs / keystonejs/keystone
Upload value invalid when using context to upload a file
- Dominant language
- TypeScript
- Stars
- 10k
- Forks
- 1.3k
- Avg merge
- 19h 14m
- Merged PRs (30d)
- 19
Description
Having an `Upload` object in a extended custom mutation and trying to pass it to `query` or `graphql.run` fails with the following error `GraphQLError [Object]: Variable "$data" got invalid value {} at "data.files.create.file.upload"; Upload value invalid.`.
I have the following custom extended mutation:
```js
const typeDefs: GraphQLSchemaExtension['typeDefs'] = `
type Mutation {
uploadFile(file: Upload!): Boolean
}
`;
const resolvers: GraphQLSchemaExtension['resolvers'] = {
Mutation: {
uploadFile: async (_root, { data }, context) => {
console.log(data);
await context.sudo().graphql.run({
query: gql`
mutation ($data: TeacherCreateInput!) {
createFile(data: $data) {
id
}
}
`,
variables: {
data: {
file: { upload: data.file }
},
},
},
});
return true;
},
},
};
```
When executing the FE code that calls this I can see in the logs that `data.file` is a proper `Upload` object (there is no validation error) but when executing the `graphql.run` in the server it's when it fails.
```
Promise {
{
filename: 'duck.jpeg',
mimetype: 'image/jpeg',
encoding: '7bit',
createReadStream: [Function: createReadStream]
}
}
```
Contributor guide
Research direction
Start at the server-side `graphql.run` entry point used by the custom mutation and reproduce the failure with an `Upload` passed through `context.sudo().graphql.run`. Trace how the upload value is handled between the outer mutation and the nested `createFile` mutation; done means the nested mutation accepts the forwarded upload without the “Upload value invalid” error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100