-
Notifications
You must be signed in to change notification settings - Fork 8
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
GraphQL together with gRPC #140
Comments
Hi, having a server serving both gRPC and GraphQL seemed possible. I haven't tried this personally but it would reckon it would not be too different from running gRPC with regular REST. I have taken a look at the article but I am missing a lot context and information because the material (which I assumed is the starting point codebase) is not available unless I pay for it. From my understanding, there is about 2 ways of having this setup:
import Pioneer
import Vapor
import GRPCVapor
import NIOSSL
let gRPCTask = Task {
let gApp = try Application(.detect())
let certificates = try NIOSSLCertificate.fromPEMBytes(Array(sampleCert.utf8))
let privateKey = try NIOSSLPrivateKey.init(bytes: Array(sampleKey.utf8), format: .pem)
app.server.configuration.supportVersions = [.two]
app.server.configuration.tlsConfiguration = .forServer(certificateChain: certificates.map { .certificate($0) }, privateKey: .privateKey(privateKey))
app.middleware.use(GRPCMiddleware(services: [SomeGRPCService()]))
}
let gqlTask = Task {
let server = try Pioneer(
schema: schema(),
resolver: Resolver(),
httpStrategy: .csrfPrevention,
introspection: true,
playground: .sandbox
)
try server.standaloneServer(
at: "graphql",
context: { req, res in
Context(req, res)
}
)
}
import Pioneer
import Vapor
import GRPCVapor
import NIOSSL
// Called before your application initializes.
public func configure(_ app: Application) throws {
let server = try Pioneer(
schema: schema(),
resolver: Resolver(),
httpStrategy: .csrfPrevention,
introspection: true,
playground: .sandbox
)
let certificates = try NIOSSLCertificate.fromPEMBytes(Array(sampleCert.utf8))
let privateKey = try NIOSSLPrivateKey.init(bytes: Array(sampleKey.utf8), format: .pem)
// Setting up HTTP/2 which is probably the cause of issues since normal REST and GraphQL is HTTP/1.1
app.server.configuration.supportVersions = [.two]
app.server.configuration.tlsConfiguration = .forServer(certificateChain: certificates.map { .certificate($0) }, privateKey: .privateKey(privateKey))
app.middleware.use(GRPCMiddleware(services: [SomeGRPCService()]))
app.group("graphql") { group in
group.post { req in
try await server.httpHandler(req: req, context: { ... })
}
}
} I haven't tried either approach but those 2 will be the approaches I would give a shot. I think the best issue in general is that gRPC is using HTTP/2 and making REST and GraphQL work with HTTP/2 is going to be difficult |
For |
It was on my todo a while back. I stopped only due to that I ran into a roadblock with how I would be able to handle both HTTP and WebSocket requests using 1 I made a repo for the integration/adapter which should at some point hold the library itself while I am still experimenting with it, and before I added into this package a https://github.com/d-exclaimation/pioneer-hummingbird I can't make a promise that I would be able to get something within the next 1-2 weeks as I am still relatively occupied. After 2 weeks or so, I might be able to get a working adapter but it would pretty experimental with bugs and not so polish DX yet. If you need this urgently, you can also go have a shot on creating a simple integration for it. I made a guide on this here, and if you do, feel free to ask me questions about it and I'll try my best helping. |
Update on this, the package does technically work although it's very bare-bone at the moment and is missing GraphQL over WebSocket |
Hi, I want to use gRPC to communicate microservices but leave GraphQL over http as api for the client. I added gRPC support in Vapor from this article, but then http stops working. Could you please tell me how to make GraphQL via http work together with gRPC? This article describes how to use rest together with GRPC, maybe it is possible to make GraphQL work too?
The text was updated successfully, but these errors were encountered: