import { GraphQLParams } from "@benzene/core" ; import { HTTPRequest } from "./types" ; param request export function getGraphQLParams ( { query , body , } ) { return { query : body ?. query || query ?. query , variables : body ?. variables || ( query ?. variables && JSON . parse ( query . variables as string ) ) , operationName : body ?. operationName || ( query ?. operationName as string | null | undefined ) , extensions : body ?. extensions || ( query ?. extensions && JSON . parse ( query . extensions as string ) ) , } ; } param rawBody param oCtype see https export function parseGraphQLBody ( rawBody , oCtype = "" ) { const semiIndex = oCtype . indexOf ( ";" ) ; const ctype = ( semiIndex !== - 1 ? oCtype . substring ( 0 , semiIndex ) : oCtype ) . trim ( ) ; switch ( ctype ) { case "application/graphql+json" : try { return JSON . parse ( rawBody ) ; } catch ( e ) { throw new Error ( "POST body sent invalid JSON." ) ; } case "application/json" : try { return JSON . parse ( rawBody ) ; } catch ( e ) { throw new Error ( "POST body sent invalid JSON." ) ; } case "application/graphql" : return { query : rawBody } ; default : return null ; } }