2

I want to upload image on by using graphql-upload package

This is my scheme file

const { GraphQLSchema, GraphQLObjectType, GraphQLBoolean } = require("graphql");
const { GraphQLUpload } = require("graphql-upload");

    const schema = new GraphQLSchema({
      mutation: new GraphQLObjectType({
        name: "Mutation",
        fields() {
          return {
            uploadImage: {
              description: "Uploads an image.",
              type: GraphQLBoolean,
              args: {
                image: {
                  description: "Image file.",
                  type: GraphQLUpload
                }
              },
              async resolve(parent, { image }) {
                const { filename, mimetype, createReadStream } = await image;
                const stream = createReadStream();
                // Promisify the stream and store the file, then…
                return true;
              }
            }
          };
        }
      })
    });

This is my server file. When I run the file it gives error on the browser side. it showed: {"errors":[{"message":"Must provide query string."}]}.

const express = require("express");
const graphqlHTTP = require("express-graphql");
const { graphqlUploadExpress } = require("graphql-upload");
const schema = require("./schema");

express()
  .use(
    "/graphql",
    graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
    graphqlHTTP({ schema })
  )
  .listen(3000);

**What am I doing wrong? **

Krisna
  • 2,854
  • 2
  • 24
  • 66
  • This is an issue with how the client is sending the request, not an issue with your backend configuration. Please share the relevant front end code. Are you using an appropriate [client library](https://github.com/jaydenseric/graphql-multipart-request-spec#client) to send the request? – Daniel Rearden Dec 14 '19 at 14:29
  • I am new in Graphql-upload. Would please help me for the front end part? – Krisna Dec 14 '19 at 14:47
  • Sure, like I said please edit your question to include the relevant client configuration. – Daniel Rearden Dec 14 '19 at 14:57
  • If you're using Apollo, you can follow the instructions [here](https://github.com/jaydenseric/apollo-upload-client). – Daniel Rearden Dec 14 '19 at 14:58
  • So you need to install `apollo-upload-client` and use `createUploadLink` instead of `new HttpLink` as shown in the docs I linked. – Daniel Rearden Dec 14 '19 at 17:16
  • Hi Daniel, Here is my whole project. Still could not figure it out :( https://stackoverflow.com/questions/59343119/unhandled-rejection-error-network-error-response-not-successful-received-st – Krisna Dec 16 '19 at 05:54
  • 1
    same issue here. any solutions? Please post up. – guerrillacodester Feb 17 '22 at 18:36

0 Answers0