@graphql-tools/links
Version: 
A set of utils for faster development of GraphQL tools
25 lines (24 loc) • 1.06 kB
JavaScript
var _a;
import * as apolloImport from '@apollo/client';
import { createUploadLink, formDataAppendFile, isExtractableFile } from 'apollo-upload-client';
import FormData from 'form-data';
import fetch from 'node-fetch';
import { AwaitVariablesLink } from './AwaitVariablesLink.js';
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
export const createServerHttpLink = (options) => apollo.concat(new AwaitVariablesLink(), createUploadLink({
    ...options,
    fetch,
    FormData,
    isExtractableFile: (value) => isExtractableFile(value) || (value === null || value === void 0 ? void 0 : value.createReadStream),
    formDataAppendFile: (form, index, file) => {
        if (file.createReadStream != null) {
            form.append(index, file.createReadStream(), {
                filename: file.filename,
                contentType: file.mimetype,
            });
        }
        else {
            formDataAppendFile(form, index, file);
        }
    },
}));