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.

GraphQLUpload with processRequest on apollo-server-micro not working

See original GitHub issue

When uploading a file im getting the following error.

imagen

Server code:

const apolloServer = new ApolloServer({
  credentials: true,
  typeDefs: mergeTypeDefs(loadFilesSync(path.join(process.cwd(), 'graphql/schemas'))),
  resolvers: mergeResolvers([...Mutation, ...Query, ...types]),
  context: async ({ req, res }) => {
    const username = req.session.get('username')
    return { db, req, res, username, user: username && await db.models.user.findByPk(username) }
  }
})
const startServer = apolloServer.start()

export default withSession(async (req, res) => {
  res.setHeader('Access-Control-Allow-Origin', '*')
  res.setHeader('Access-Control-Allow-Credentials', 'true')
  res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')

  const contentType = req.headers['content-type']
  if (contentType && contentType.startsWith('multipart/form-data')) {
    req.filePayload = await processRequest(req, res)
  }

  await db.sync()
  await startServer

  return apolloServer.createHandler({ path: '/api/graphql' })(req, res)
})

export const config = {
  api: { bodyParser: false }
}

Resolvers object: imagen

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jaydensericcommented, Nov 27, 2021

Sounds like something weird about how dependencies are installed and resolved in your project.

BTW, it’s best to skip the index module and directly deep import the thing you need:

import GraphQLUpload from 'graphql-upload/public/GraphQLUpload.js';

Or for your funny workaround:

import GraphQLUpload from 'node_modules/graphql-upload/public/GraphQLUpload.js';
0reactions
jorgev259commented, Nov 27, 2021

It is, yarn why showed the direct graphql-upload dependency as the only one. But it seems a similar problem as other similar issues was the culprit.

Solved by using the full path to import the Scalar: import { GraphQLUpload } from 'node_modules/graphql-upload/public/index.js'

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to upload files above 1MB using apollo-server-micro ...
This is working for smaller files, but it somehow seems to be blocking my larger files. When I upload the file, I get...
Read more >
File uploads - Apollo GraphQL Docs
Some integrations might need to use graphql-upload 's processRequest directly. ... local-file-output.txt in the current working directory on EACH upload.
Read more >
apollo-server-micro | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Top 5 graphql-upload Code Examples - Snyk
To help you get started, we've selected a few graphql-upload examples, based on popular ways it is used in public projects. Secure your...
Read more >
graphql-upload-minimal - npm
Minimalistic and developer friendly middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries ...
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