Comments (9)
I'm not sure what you are trying to achieve. Can you please describe it a bit more and include an example of something that is not working as expected? Include a sample request, possibly with got
or similar.
(schema is missing in your example).
from mercurius.
Bella Matteo,
what I'm trying to achieve is file upload thru graphql.
This is the schema I use to define the upload.
Before all, import grapqhl-upload:
import { GraphQLUpload } from 'graphql-upload';
then
typeDefs: buildSchema(`
scalar Upload
`),
resolvers: {
Upload: GraphQLUpload
}
And then when needed:
type Mutation {
addFile(id: ID!, file: Upload!): Boolean
}
In the resolvers, file is managed as standard file
const { filename, mimetype, createReadStream } = await file;
I'm migrating from apollo-server and worked well.
from mercurius.
I'm still not sure what you are trying to achieve. I'm probably missing some context regarding file uploads and graphql, as I always thought they were two very separate concepts (there is nothing special here to handle them).
Having an example including a sample request would be extremely helpful.
(I'm currently boarding a long haul flight, so I'll reply when I get a chance).
from mercurius.
Ok I digged a little bit more and every POST with multipart/form-data to the endpoint returns 400.
I'll make some more test and then I'll try to create a codesandbox or minimal repo for you
Have a nice flight!
from mercurius.
Hey @mcollina, I hope your trip was flawless.
here's a way to reproduce the problem:
add those dependencies to package.json
"fastify": "2.12.0",
"fastify-gql": "3.0.6",
"fastify-cors": "3.0.1",
"fastify-multipart": "1.0.5"
and then in a index.js:
import fastify = require('fastify');
import GQL = require('fastify-gql');
import cors = require('fastify-cors');
import multipart = require('fastify-multipart');
import GraphQLUpload = require('graphql-upload');
const app = fastify();
app.register(cors, { origin: '*' });
app.register(multipart, { addToBody: true });
const schema = `
scalar Upload
type Mutation {
add(x: Int, y: Upload): Int
}
`;
const resolvers = {
Upload: GraphQLUpload,
Mutation: {
add: async (_, { x, y }) => {
console.log(x);
console.log(y);
return x;
}
}
};
app.register(GQL, {
path: '/',
graphiql: 'playground',
schema,
resolvers
});
const port = 4000;
app.listen(port, () => console.log(`🚀 Server ready at http://localhost:${port}`));
If you try to post a file
async function addImage(event) {
const ADDIMAGE = gql`
mutation($file: Upload!) {
add(x: 28, y: $file)
}
`;
const file = event.target.files[0];
console.log(file);
await mutate(client, {
mutation: ADDIMAGE,
variables: {
file
}
});
}
You'll get
Uncaught (in promise) Error: Network error: Response not successful: Received status code 400
from mercurius.
Your problem is that https://github.com/jaydenseric/graphql-upload/blob/master/readme.md does not support fastify.
from mercurius.
Well, this sucks. I have to roll back to apollo-server because file upload is a core feature for my app.
But I can try to spare some time to make fastify-gql compatible with graphql-upload. Any hints will be appreciated.
You can close this issue if you think.
from mercurius.
@mcollina seems resolved by #126
from mercurius.
Closing then!
from mercurius.
Related Issues (20)
- Playground endpoint is not dynamic HOT 2
- Simple subscription example shown in docs fails to push new notifications to client HOT 3
- Occasional "error.originalError.errors.map is not a function" errors HOT 2
- Subscriber.js: Listener not removed on multiple topics
- GraphiQL issues in newest release HOT 2
- Types issue with Typescript module resolution node16 HOT 5
- local graphiql front-end sources for offline development HOT 1
- Implement Relay style pagination HOT 7
- How to disable `/graphql` route? HOT 1
- Multiple endpoints graphql using Fastify and Mercurius trigger error ' The decorator 'graphql' has already been added! ' HOT 1
- Case for a new hook HOT 2
- Community HOT 1
- Timing problems with nested resolvers throwing errors HOT 1
- fastify-cli and Mercurius HOT 2
- DOC: docs don't have a favicon HOT 3
- Better error messages on passing array of executable schemas. HOT 3
- Support custom directives in mercurius core
- Create a tool kit for schema transformations HOT 1
- Several unit tests checking for errors would pass even if the error isn't thrown HOT 2
- Query caching broken with some custom scalars and JIT HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mercurius.