#
Migrating to v1
One of the big goal of v1 is to bring fully bring a stable release of Pioneer with all the features and changes added in the past year, and allow Pioneer to be more customisable, and more compatible with more server-side Swift frameworks and libraries.
#
Decoupling from Vapor
Pioneer also now no longer a Vapor-only library and exposes more of its internal functions, structs, protocols, and classes which will allow integrations with other web frameworks.
#
Middleware
Pioneer will no longer add routes to a Vapor Application with the .applyMiddleware
function.
Instead, Pioneer will have a Vapor integration module that extends Pioneer with VaporGraphQLMiddleware which can be use like a regular Vapor middleware.
let app = try Application(.detect())
let server = Pioneer(
schema: schema,
resolver: resolver
)
app.middleware.use(server.vaporMiddleware())
let app = try Application(.detect())
let server = Pioneer(
schema: schema,
resolver: resolver
)
server.applyMiddleware(on: app)
#
Context Builder
Alongside being a middleware, all context builder and guard functions are passed into the middleware instead of directly to Pioneer. This allow Pioneer be decoupled from Vapor but still allow integration with Vapor's Request
and Response
in the context builder.
let server = Pioneer(
schema: schema,
resolver: resolver
)
app.middleware.use(
server.vaporMiddleware(
context: { req, res in
...
},
websocketContext: { req, payload, gql in
...
}
)
)
let server = Pioneer(
schema: schema,
resolver: resolver,
contextBuilder: { req, res in
...
},
websocketContextBuilder: { req, params, gql in
...
}
)
server.applyMiddleware(on: app)
#
WebSocket Guard
Pioneer now properly implement a WebSocket initialisation guard, which will fire for each new GraphQL over WebSocket connection that initialise properly. This allow user configured authorization of each WebSocket connection.
let server = Pioneer(
schema: schema,
resolver: resolver
)
app.middleware.use(
server.vaporMiddleware(
context: { req, res in
...
},
websocketContext: { req, payload, gql in
...
},
websocketGuard: { req, payload in
...
}
)
)
#
Same path for all
Pioneer v0 uses 3 different paths for GraphQL over HTTP, GraphQL over WebSocket, and GraphQL IDE hosting.
In v1, Pioneer will use the same path for all of those, and will instead determine from the request whether is a GraphQL over HTTP request, a GraphQL over WebSocket upgrade request, or a GraphQL IDE request.
#
Standalone server
Pioneer will also now include option to run standalone.
let server = Pioneer(
schema: schema,
resolver: resolver
)
try server.standaloneServer(
context: { req, res in
...
},
websocketContext: { req, payload, gql in
...
},
websocketGuard: { req, payload in
...
}
)
Under the hood, the standalone server uses the Vapor integration.
#
Other changes
#
New defaults
Pioneer will now defaults to
- .csrfPrevention for its HTTPStrategy
- .sandbox for its WebSocket Protocol
30
seconds for the keep alive interval for GraphQL over WebSocket
#
WebSocket callbacks
Some WebSocket callbacks are now exposed as functions in Pioneer. These can be used to add a custom WebSocket layer.
- .receiveMessage
- Callback to be called for each WebSocket message
- .initialiseClient
- Callback after getting a GraphQL over WebSocket initialisation message according to the given protocol
- .executeLongOperation
- Callback to run long running operation using Pioneer
- .executeShortOperation
- Callback to run short lived operation using Pioneer
#
Pioneer capabilities
Some other capabilities of Pioneer is now exposed:
.allowed, Check if a GraphQL request is allowed given the allowed list of operations
.csrfVulnerable, Check if the headers given show signs of CSRF and XS-Search vulnerability
.executeHTTPGraphQLRequest, Execute an operation for a given HTTPGraphQLRequest and returns HTTPGraphQLResponse
#
ConnectionParams to Payload
The type ConnectionParams
is renamed to Payload
typealias Payload = [String: Map]?
#
Brief summary
These are simplified list of things that changed
- Vapor integration module
- Vapor GraphQL middleware using Pioneer
- Manually HTTP operation, IDE service, WebSocket upgrade, and WebSocket callbacks
- Manually perform CSRF vulnerability checks and HTTP Strategy check
- Uses 1 path for all types of operations
- Open opportunity for other web framework integrations
- Changed defaults to .csrfPrevention for HTTP strategy, .graphqlWs for WebSocket protocol, and .sandbox for GraphQL IDE.
- For Vapor integration, must be applied as a middleware at
Application
level (no nesting) - Removed
Configuration