Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1x 1x 5x 5x 5x 5x | import {DocumentNode} from 'graphql/language/ast'
import {print} from 'graphql/language/printer'
import {FlexibleRequestBody, GraphQLRequestPayload} from '../../types'
export default function formatRequestBody(
body: FlexibleRequestBody
): GraphQLRequestPayload {
// string
Iif (typeof body === 'string') return {query: body}
// DocumentNode
else Iif ('kind' in body) return {query: print(body)}
// FlexibleRequestBody w/ {query: string}
else if ('query' in body && typeof body.query === 'string')
return body as GraphQLRequestPayload
// FlexibleRequestBody w/ {query:DocumentNode}
else Eif ('query' in body && 'kind' in (body.query as DocumentNode))
return {...body, query: print(body.query as DocumentNode)}
else throw new Error('The format of the request is malformed')
}
|