UNPKG

@graphql-tools/links

Version:

A set of utils for faster development of GraphQL tools

24 lines (23 loc) 913 B
import { createUploadLink, formDataAppendFile, isExtractableFile } from 'apollo-upload-client'; import FormData from 'form-data'; import fetch from 'node-fetch'; import * as apolloImport from '@apollo/client'; import { AwaitVariablesLink } from './AwaitVariablesLink.js'; const apollo = apolloImport?.default ?? apolloImport; export const createServerHttpLink = (options) => apollo.concat(new AwaitVariablesLink(), createUploadLink({ ...options, fetch, FormData, isExtractableFile: (value) => isExtractableFile(value) || 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); } }, }));