Skip to content

Commit

Permalink
feat: use recommened accept header
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Sep 5, 2024
1 parent 065418a commit 451204b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/layers/5_core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -206,6 +211,7 @@ export const anyware = Anyware.create<HookSequence, HookMap, ExecutionResult>({
return input
}
case `http`: {
// todo support GET
// TODO thrown error here is swallowed in examples.
const request: RequestInput = {
url: input.url,
Expand All @@ -214,8 +220,7 @@ export const anyware = Anyware.create<HookSequence, HookMap, ExecutionResult>({
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`
Expand Down
4 changes: 4 additions & 0 deletions src/lib/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 451204b

Please sign in to comment.