Skip to content

Commit 9893bb7

Browse files
test: Validate request JSON support
Specifically, we allow `application/json` `Content-Type` support
1 parent e75e80a commit 9893bb7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Tests/GraphQLHummingbirdTests/HTTPTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,33 @@ struct HTTPTests {
153153
}
154154
}
155155

156+
@Test func jsonContentTypeHeader() async throws {
157+
let router = Router()
158+
router.graphql(schema: helloWorldSchema) { _, _ in
159+
EmptyContext()
160+
}
161+
let app = Application(router: router)
162+
163+
try await app.test(.router) { client in
164+
try await client.execute(
165+
uri: "/graphql",
166+
method: .post,
167+
headers: [
168+
.accept: MediaType.applicationJsonGraphQL.description,
169+
.contentType: MediaType.applicationJson.description,
170+
],
171+
body: .init(data: JSONEncoder().encode(GraphQLRequest(query: "{ hello }")))
172+
) { response in
173+
#expect(response.status == .ok)
174+
#expect(response.headers[.contentType] == "application/graphql-response+json; charset=utf-8")
175+
176+
let result = try JSONDecoder().decode(GraphQLResult.self, from: response.body)
177+
#expect(result.data?["hello"] == "World")
178+
#expect(result.errors.isEmpty)
179+
}
180+
}
181+
}
182+
156183
@Test func noAcceptHeader() async throws {
157184
let router = Router()
158185
router.graphql(schema: helloWorldSchema) { _, _ in

0 commit comments

Comments
 (0)