undefined properties when uploading using apollo-server-express
See original GitHub issueI’ve been trying to add the upload feature to our graphql endpoint. We manage to hit the graphql mutation but the file stream is undefined. I can see on the developer tools that nothing is being sent in the request body which is odd. A console.log on the mutation server side renders { preview: ‘blob:http://localhost:3000/ba021b5c-57e6-4fba-b574-a4933250b0c2’ } and nothing else.
stream, filename, mimetype, encoding are all undefined.
Mutation Field
uploadFile: {
type: UploadType,
args: {
file: {
type: GraphQLUpload
}
},
async resolve(_, { file }) {
const { stream, filename, mimetype, encoding } = await file;
console.log(file);
return {
stream,
filename,
mimetype,
encoding
};
}
}
Object Type
const {
GraphQLObjectType,
GraphQLString
} = require('graphql');
const UploadType = new GraphQLObjectType({
name: 'UploadType',
fields: () => ({
filename: {
type: GraphQLString
},
mimetype: {
type: GraphQLString
},
encoding: {
type: GraphQLString
}
})
});
module.exports = UploadType;
Mutation
const UPLOAD_FILE = gql`
mutation uploadFile($file: Upload!) {
uploadFile(file: $file) {
filename
}
}
`;
Mutation Component
<Mutation mutation={UPLOAD_FILE}>
{uploadFile => ( ... )}
</Mutation>
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Migrating to Apollo Server 4 - Apollo GraphQL Docs
Migrate from apollo-server-express. If you used the apollo-server-express package in Apollo Server 3, use the expressMiddleware function in Apollo Server 4 ...
Read more >Undefined args on a mutation, using apollo-server
Im working with apollo-server, everything works as expetected but the mutation arguments are undefined when the mutation is called from the ...
Read more >Apollo Server Express | Part 7 | Authentication (Login and ...
apollo # apollo-server-express #nodejs #curdDo Consider Joining our patron page for special and on-demand lectures and solutions, ...
Read more >Apollo-server-express and express-session: session undefined
I am using the boilerplate from apollo-server-express. ... Main error: Error: Cannot set properties of undefined (setting 'userId').
Read more >apollo-server-express | Yarn - Package Manager
This is the Express integration of Apollo Server. Apollo Server is a community-maintained open-source GraphQL server that works with many Node.js HTTP server ......
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
Aah, that’s interesting. This is probably something we should clarify in our docs – that if your query accepts an
Upload
rather than a (non-null)Upload!
the argument can be null instead of aPromise
.Glad you figured out the issue with apollo-boost!
Update: I managed to remove apollo-boost that was the issue they don’t provide the upload feature on it or at least I cant find how to enable it anywhere. I managed to get it to work with the following config.