jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

graphqlUploadExpress missing createReadStream #293

Closed sgentile closed 2 years ago

sgentile commented 2 years ago

I have a server setup as below. I've added the graphqlUploadExpress - I'm seeing the file come through, however it's missing createReadStream ?

     async function main() {
    // Bootstrap Apollo Server
    // Use Apollo server as express middleware through 'applyMiddleware'
    const { schema } = await getBuiltMesh();
    const server = new ApolloServer({
        schema,
    });
    await server.start();

    // Bootstrap Client App
    // Next.js creates a handler that can be used as express middleware
    await nextApp.prepare();
    const app = express();
    app.get('*', nextApp.getRequestHandler());
    app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }));
    server.applyMiddleware({
        app: app
    });
    await new Promise((r) => app.listen({ port: 4000 }, r));
    console.log(`🚀 Server ready at     http://localhost:4000${server.graphqlPath}`);
}

schema

scalar Upload

type File {
    filename: String!
    mimetype: String!
    encoding: String!
}

type Mutation {
    createBucket: Boolean
    uploadFile(file: Upload!): Boolean
    uploadFiles(files: [Upload]): Boolean
}

type Query {
    getFiles: Boolean
}
jaydenseric commented 2 years ago

Did you setup the Upload scalar correctly? You've got it in your schema SDL, but what about resolvers?

Are you using an outdated version of Apollo Server that ships a conflicting older version of graphql-upload that needs to be disabled in Apollo Server options?

jaydenseric commented 2 years ago

If you still have this issue and have determined that it is a graphql-upload bug and you’re able to provide minimal reproduction steps, we can reopen.

protatix commented 2 years ago

@jaydenseric I have same problem and investigating for last two days. Package versions; "apollo-server": "3.6.3", "apollo-server-express": "3.6.3" "graphql-upload": "13.0.0", "graphql": "15.8.0",

After upgrading Apollo Server v2 to v3, not fixed my problem. I've added express middleware and also my resolver looks like; Query: { Store: Store.getWidgets, Upload: GraphQLUpload, },

When I upload a file I got this object and createReadStream returns undefined in the file object; Other properties such as filename, mimetype and encoding are reachable. args { image: { promise: {}, file: { filename: 'istanbul.jpg', mimetype: 'image/jpeg', encoding: '7bit' } } }

sgentile commented 2 years ago

Did you setup the Upload scalar correctly? You've got it in your schema SDL, but what about resolvers?

Are you using an outdated version of Apollo Server that ships a conflicting older version of graphql-upload that needs to be disabled in Apollo Server options?

yes to setting up scalar - and no to the conflicting older version