Skip to content

Commit 12b578e

Browse files
felamaslenardatan
andauthored
fix(http-executor): don't force application/json content type (#5825)
* fix(http-executor): don't force application/json content type * test(executors): regression test on setting custom introspection header * chore: added changeset for http-executor fix * chore: removed nock dependency * fix: removed unused dependency * chore: unnecessary JSON stringify * chore: reset yarn lock * test: assert on number of assertions * Apply suggestions from code review --------- Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
1 parent 829d020 commit 12b578e

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

.changeset/swift-suits-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/executor-http': patch
3+
---
4+
5+
Fixed http executor to allow custom content-type header

packages/executors/http/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export function buildHTTPExecutor(
200200
),
201201
)
202202
.then(body => {
203-
if (typeof body === 'string') {
203+
if (typeof body === 'string' && !headers['content-type']) {
204204
headers['content-type'] = 'application/json';
205205
}
206206
const fetchOptions: RequestInit = {

packages/executors/http/tests/buildHTTPExecutor.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,37 @@ describe('buildHTTPExecutor', () => {
144144
}
145145
`);
146146
});
147+
148+
it('should allow setting a custom content-type header in introspection', async () => {
149+
expect.assertions(2);
150+
151+
const executor = buildHTTPExecutor({
152+
endpoint: 'https://my.schema/graphql',
153+
fetch(_url, options) {
154+
expect(options?.headers?.['content-type']).toBe('application/vnd.api+json');
155+
return Response.json({ data: { hello: 'world' } });
156+
},
157+
headers: { 'content-type': 'application/vnd.api+json' },
158+
});
159+
const result = (await executor({
160+
document: parse(/* GraphQL */ `
161+
query IntrospectionQuery {
162+
__schema {
163+
queryType {
164+
name
165+
}
166+
mutationType {
167+
name
168+
}
169+
subscriptionType {
170+
name
171+
}
172+
}
173+
}
174+
`),
175+
context: {},
176+
})) as ExecutionResult;
177+
178+
expect(result.errors).toBeUndefined();
179+
});
147180
});

0 commit comments

Comments
 (0)