-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Hapi Integration #5
Comments
I don't know much about hapi, but if you are sure the Express middleware won't work just import the import {processRequest} from 'apollo-upload-server' Once you have something working we can add it in here. |
Closing this for now, feel free to submit a pull request if you get around to working on it. |
I'm trying to get this working with Hapi but quickly got stuck with this error: Error: Unknown event error
at Object.exports.assert (/Users/teddy/leav_core/node_modules/podium/node_modules/hoek/lib/index.js:736:11)
at internals.Request.internals.Podium.on.internals.Podium.addListener (/Users/teddy/leav_core/node_modules/podium/lib/index.js:291:10)
at IncomingForm.parse (/Users/teddy/leav_core/node_modules/formidable/lib/incoming_form.js:126:6)
at Promise (/Users/teddy/leav_core/node_modules/apollo-upload-server/dist/apollo-upload-server.js:25:10)
at Promise (<anonymous>)
at processRequest (/Users/teddy/leav_core/node_modules/apollo-upload-server/src/index.js:16:10)
at _callee2$ (/Users/teddy/leav_core/server.js:142:68)
at tryCatch (/Users/teddy/leav_core/node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (/Users/teddy/leav_core/node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (/Users/teddy/leav_core/node_modules/regenerator-runtime/runtime.js:117:21) I'm just calling server.register({
register: graphqlHapi,
options: {
path: '/graphql',
route: {
pre: [
{
method: async (req, reply) => {
try {
const processedRequest = await processRequest(req, {
uploadDir: '/tmp'
});
} catch(e) {
console.log(e);
}
},
assign: 'fileUpload'
}
]
},
graphqlOptions: (req) => { ... }
}
}); I don't think this error is linked to your code, it might come from |
I don't really understand the way registering that middleware works, but are you sure |
With this approach you have to use @TdyP I'm very interested in this, so please do update this thread with anything you discover :) Happy to help out as well. |
Maybe we should abstract out the logic of |
That might work, but as far as I remember the problem was more that Hapi wants either multipart or regular, it's difficult to support both, and that complicated things a lot. Also, the apollo hapi plugin uses both GET and POST for the route which further complicated matters because it's not allowed (/possible) to use multipart with a GET request. Ideally we would need to customize the apollo hapi plugin, but then that needs to be maintained with updates from apollo etc, so that doesn't seem like a viable option. |
Not much success so far for me. I managed to get the request body parsing working if I plug the processRequest on any hook before the So, using the Didn't dug any further on exporting a new |
I took almost exactly the same roundtrip and got stuck. I image it would be required to either have some changes made in apollo hapi or go the super hacky way as you described. |
I made it work without the export default {
method: 'POST',
path: '/graphql',
config: {
payload: {
multipart: {
output: 'file'
}
},
pre: [{
assign: 'payload',
method ({headers, payload}, reply) {
if (payload.operations) {
const pay = {...JSON.parse(payload.operations)}
each(payload, ({filename: name, headers, bytes: size, path}, key) => {
if (name) {
set(pay, key, {type: headers['content-type'], name, size, path})
}
})
reply(pay)
} else {
reply()
}
}
}]
},
async handler ({payload, pre}, reply) {
const {query, variables} = pre.payload || payload
try {
const result = await graphql(schema, query, {}, {}, variables)
reply(result)
} catch (err) {
reply(err)
}
}
} |
Closing this because it is not something I will be working on, but if anyone has an elegant solution feel free to report back or raise a PR 🙂 |
It would be great to have support for hapijs. I might take a look at this if I find the time.
The text was updated successfully, but these errors were encountered: