-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add support for fastify 5 #296
Comments
Thanks for the heads up! Should be able to start on this soon. |
Any news about this ? |
I'm joining the crowd wishing for a swift resolution to this. Considering there's two open pr's trying to solve the same thing I hope the maintainers push for one of them soon. |
I see, should we fork the repo, merge the PR and publish it under another org? It's been a while since I opened the issue |
@olyop @trevor-scheer Could you please take a gander at the two prs? |
Any update on this? I'm stuck on my Fastify/Nest server updates as well due to this. |
Hello! Any update on support for Fastify version 5? |
any news on this? |
Workaround. Use
"@as-integrations/fastify": "patch:@as-integrations/fastify@npm%3A2.1.1#~/.yarn/patches/@as-integrations-fastify-npm-2.1.1-6c130ea02e.patch",
|
This integration seems unmaintained and dead. Forking it is likely the solution, but for me this means I'll stay with the official express integration instead. |
Until an update is released, here's something I cooked up that might be of use; import { Readable } from 'node:stream'
import {
type ApolloServer,
HeaderMap,
type HTTPGraphQLRequest,
type HTTPGraphQLResponse,
} from '@apollo/server'
import { type FastifyReply, type FastifyRequest } from 'fastify'
import plugin from 'fastify-plugin'
import { type Context, createContext } from './server/context'
export function fastifyApollo(apollo: ApolloServer<Context>) {
return plugin(
(fastify) => {
fastify.route({
async handler(request, reply) {
const response = await apollo.executeHTTPGraphQLRequest({
context: () => createContext(request, reply),
httpGraphQLRequest: createRequest(request),
})
return handleResponse(reply, response)
},
method: ['get', 'post', 'options'],
url: '/graphql',
})
},
{
fastify: '5.x',
name: 'apollo',
},
)
}
function createRequest(request: FastifyRequest): HTTPGraphQLRequest {
const url = new URL(request.url, `${request.protocol}://${request.hostname}`)
const headers = new HeaderMap()
for (const [key, value] of Object.entries(request.headers)) {
if (value) {
headers.set(key, Array.isArray(value) ? value.join(', ') : value)
}
}
return {
body: request.body,
headers,
method: request.method.toUpperCase(),
search: url.search,
}
}
function handleResponse(
reply: FastifyReply,
{ body, headers, status }: HTTPGraphQLResponse,
) {
for (const [key, value] of headers) {
void reply.header(key, value)
}
void reply.code(status ?? 200)
if (body.kind === 'complete') {
return body.string
}
const readable = Readable.from(body.asyncIterator)
return reply.send(readable)
} Usage; await fastify.register(fastifyApollo(apollo)) Most of the code is copied from this package and refactored a bit. Does anybody know if |
Hey y'all. Sorry for the silence here, unfortunately priorities have taken my attention elsewhere.
I can't commit to helping with this work but I would like to enable you folks to do it. |
Hey @trevor-scheer, sorry to prod, but just wanted to check in. Is there anything we can do to help here? |
fastify@5
is released 😃.@as-integrations/fastify
peerDependencies includefastify@^4.4.0
. Please consider releasing a new version supportingfastify@5
.The text was updated successfully, but these errors were encountered: