-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use order-preserving JSON encoder in graphql-server
This uses the GraphQLJSONEncoder when converting a GraphQLResult to a Response to return the query results in the order that the were specified in the request.
- Loading branch information
1 parent
a16b97b
commit 7063636
Showing
3 changed files
with
19 additions
and
6 deletions.
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
graphql-server/Sources/App/GraphQL/GraphQL+HBResponseGenerator.swift
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
graphql-server/Sources/App/GraphQL/GraphQL+ResponseGenerator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import GraphQL | ||
import HTTPTypes | ||
import Hummingbird | ||
|
||
extension GraphQLResult: ResponseGenerator { | ||
public func response(from _: Request, context _: some RequestContext) throws -> Response { | ||
let encoder = GraphQLJSONEncoder() | ||
let data = try encoder.encode(self) | ||
return Response( | ||
status: .ok, | ||
headers: [ | ||
.contentType: "application/json; charset=utf-8", | ||
.contentLength: "\(data.count)", | ||
], | ||
body: .init(byteBuffer: ByteBuffer(data: data)) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters