File tree Expand file tree Collapse file tree
Tests/GraphQLHummingbirdTests Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments