From 451204bd4bf748316544f06a7345d6237c4eae69 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Thu, 5 Sep 2024 09:24:59 -0400 Subject: [PATCH] feat: use recommened accept header --- src/layers/5_core/core.ts | 11 ++++++++--- src/lib/http.ts | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/layers/5_core/core.ts b/src/layers/5_core/core.ts index 4a2ceb839..04fa62c7b 100644 --- a/src/layers/5_core/core.ts +++ b/src/layers/5_core/core.ts @@ -3,7 +3,12 @@ import { print } from 'graphql' import { Anyware } from '../../lib/anyware/__.js' import { type StandardScalarVariables } from '../../lib/graphql.js' import { parseExecutionResult } from '../../lib/graphqlHTTP.js' -import { CONTENT_TYPE_GQL, CONTENT_TYPE_JSON, mergeHeadersInit } from '../../lib/http.js' +import { + CONTENT_TYPE_GQL, + CONTENT_TYPE_GQL_OVER_HTTP_REC, + CONTENT_TYPE_JSON, + mergeHeadersInit, +} from '../../lib/http.js' import { casesExhausted } from '../../lib/prelude.js' import { execute } from '../0_functions/execute.js' import type { Schema } from '../1_Schema/__.js' @@ -206,6 +211,7 @@ export const anyware = Anyware.create({ return input } case `http`: { + // todo support GET // TODO thrown error here is swallowed in examples. const request: RequestInput = { url: input.url, @@ -214,8 +220,7 @@ export const anyware = Anyware.create({ method: `POST`, ...mergeRequestInputOptions(input.context.config.requestInputOptions, { headers: mergeHeadersInit(input.headers, { - // @see https://graphql.github.io/graphql-over-http/draft/#sec-Accept - accept: CONTENT_TYPE_GQL, + accept: CONTENT_TYPE_GQL_OVER_HTTP_REC, // todo if body is something else, say upload extension turns it into a FormData, then fetch will automatically set the content-type header. // ... however we should not rely on that behavior, and instead error here if there is no content type header and we cannot infer it here? ...(typeof input.body === `string` diff --git a/src/lib/http.ts b/src/lib/http.ts index a0012971b..ed0422d0b 100644 --- a/src/lib/http.ts +++ b/src/lib/http.ts @@ -2,6 +2,10 @@ export const ACCEPT_HEADER = `Accept` export const CONTENT_TYPE_HEADER = `Content-Type` export const CONTENT_TYPE_JSON = `application/json` export const CONTENT_TYPE_GQL = `application/graphql-response+json` +/** + * @see https://graphql.github.io/graphql-over-http/draft/#sec-Legacy-Watershed + */ +export const CONTENT_TYPE_GQL_OVER_HTTP_REC = `${CONTENT_TYPE_GQL}; charset=utf-8, ${CONTENT_TYPE_JSON}; charset=utf-8` export const statusCodes = { success: 200, }