Comments (4)
Update on this, the package does technically work although it's very bare-bone at the moment and is missing GraphQL over WebSocket
from pioneer.
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:
- The easiest approach is to just have 2 servers with a different port running on 1 Swift application, with one for gRPC and HTTP/2 and the other is serving GraphQL which can be HTTP/1.1 or HTTP/2. Swift version 5 or higher have
Task
to help achieve this by running each server on their onTask
. This is definitely not optimal but this is by far the easiest and simplest approach to it.
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)
}
)
}
- The later is to run them on a single server. Taking a look at this example of setting up Vapor with gRPC and also serving REST endpoints, the only part that is of interest is that gRPC adapter is basically just a middleware. Pioneer is also just a Vapor middleware but it can also be apply on the route like a normal endpoint, so you can have the gRPC as a middleware and either also apply Pioneer as middleware (as far as I can tell, it won't cause conflict) or apply it on individual routes like a normal REST endpoint. This is more optimal because it have them running on 1 Vapor application but it will force your app to be on HTTP/2 because gRPC require HTTP/2. REST and GraphQL is usually using HTTP/1.1 for normal requests.
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
from pioneer.
For Hummingbird
there is a library that adds grpc
support along with rest
and rest
seems to even work over HTTP/1.1
. Is there a pioneer planned for the Hummingbird
? I might be thinking about switching from Vapor
to Hummingbird
then 🙂
from pioneer.
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 "/graphql"
endpoint, mainly on upgrade WebSocket requests manually.
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.
from pioneer.
Related Issues (20)
- Public structs have no public initialisers
- After pausing the websocket connection from Apollo iOS, it can't reconnect. HOT 12
- Documentation search is pointing to incorrect path HOT 2
- Better typing for payload HOT 1
- Improvement to Test HOT 1
- Improvement to optional spec-compliant HOT 4
- Field Resolve Middleware HOT 1
- VaporMiddleware responding incorrectly to all paths HOT 7
- Plugins
- Error: 'ConcurrentResolve' is only available in macOS 12 or newer HOT 4
- TestConsumer Improvement
- subscription Precondition failed HOT 13
- Subscription via gateway HOT 3
- Improvement to spec-compliant HOT 1
- Value null in data on errors HOT 8
- Support for the new Swift Universal HTTP types
- Does Pioneer support multiplexing subscriptions over one WebSocket connection? HOT 6
- Does Pioneer support subscriptions via SSE? HOT 2
- `websocketOnInit` has not been implemented
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 pioneer.