Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload scalar return empty object as resolver argument #211

Closed
mittalyashu opened this issue Jun 27, 2020 · 7 comments
Closed

Upload scalar return empty object as resolver argument #211

mittalyashu opened this issue Jun 27, 2020 · 7 comments

Comments

@mittalyashu
Copy link

Schema

scalar Upload

type Mutation {
  uploadImage(image: Upload): Image
}

Resolver

This is the resolver to import Upload scalar

const { GraphQLUpload } = require('graphql-upload');

module.exports = {
  Upload: GraphQLUpload
}

Resolver to handle image upload

const uploadImage = input => {
  const data = { ...input }
  console.log(data)

  // upload to image server
}

module.exports = {
  uploadImage
}

The Data variable return { image: {} }

@jaydenseric
Copy link
Owner

First, make sure the client is sending a valid GraphQL multipart request to the server. Use the Chrome dev tools network inspector to verify this.

Secondly, make sure the graphqlUploadKoa or graphqlUploadExpress middleware is setup correctly.

Make sure no other middleware is parsing the multipart request, particularly before the graphql-upload middleware.

@mittalyashu
Copy link
Author

I believe the issue is not from GraphQL server instead from the resolver itself.

Though, I did check all the things you have mentioned add made the required changes for graphqlUploadExpress.

And, the problem seems still persistent.

@jaydenseric
Copy link
Owner

jaydenseric commented Jun 27, 2020

If in the server project you run npm ls graphql-upload, is there only one version installed? If not, you need to make sure that only one version is being used so that the middleware and scalar can work together properly.

@mittalyashu
Copy link
Author

mittalyashu commented Jun 27, 2020

└── graphql-upload@11.0.0

Yup, using latest version.

Does it request to install this package in frontend (react.js project) where we use the mutation.

const mutationUploadImage = gql`
  mutation UploadImage(
    $image: Upload!
  ) {
    uploadImage(image: $image) {
      publicLink
    }
  }
`

My guess would be, when I pass the $image as variable it doesn't get sent and that's why it shows empty object in the resolver.

@jaydenseric
Copy link
Owner

You should have already verified that the front end is sending a valid GraphQL multipart request, so it is irrelevant at this point.

@mittalyashu
Copy link
Author

I have double checked the mutation query in the frontend and there seems nothing wrong with that.

But, after inspecting the network tab, it seems it is not able to add the File blob as a variable.

Screenshot 2020-06-27 at 3 29 19 PM

@jaydenseric
Copy link
Owner

That doesn't look like a multipart request; your problem is on the client. Setup your client to send the right requests; here are a list of client implementations to choose from:

https://github.com/jaydenseric/graphql-multipart-request-spec#client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants