How to use extract-files - 8 common examples

To help you get started, we’ve selected a few extract-files examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jaydenseric / apollo-upload-client / src / network-interface.js View on Github external
fetchFromRemoteEndpoint({ request, options }) {
    // Continue if uploads are possible
    if (typeof FormData !== 'undefined') {
      // Extract any files from the request variables
      const files = extractFiles(request.variables, 'variables')

      // Continue if there are files to upload
      if (files.length) {
        // Convert query AST to string for transport
        request.query = printAST(request.query)

        // Construct a multipart form
        const formData = new FormData()
        formData.append('operations', JSON.stringify(request))
        files.forEach(({ path, file }) => formData.append(path, file))

        // Send request
        return fetch(this._uri, {
          method: 'POST',
          body: formData,
          ...options
github drejohnson / sapper-graphql-firebase / src / svql / createClient.js View on Github external
function getFetchOptions(operation) {
    const fetchOptions = {
      method: 'POST',
      headers: {
        ...opts.headers,
      },
      ...opts.fetchOptions,
    }

    const { clone, files } = extractFiles(operation)
    const operationJSON = JSON.stringify(clone)

    if (files.size) {
      // See the GraphQL multipart request spec:
      // https://github.com/jaydenseric/graphql-multipart-request-spec

      const form = new FormData()

      form.append('operations', operationJSON)

      const map = {}
      let i = 0
      files.forEach(paths => {
        map[++i] = paths
      })
      form.append('map', JSON.stringify(map))
github jaydenseric / apollo-upload-client / src / index.js View on Github external
headers: {
        // Client awareness headers are context overridable.
        ...(name && { 'apollographql-client-name': name }),
        ...(version && { 'apollographql-client-version': version }),
        ...headers
      }
    }

    const { options, body } = selectHttpOptionsAndBody(
      operation,
      fallbackHttpConfig,
      linkConfig,
      contextConfig
    )

    const { clone, files } = extractFiles(body)
    const payload = serializeFetchParameter(clone, 'Payload')

    if (files.size) {
      // Automatically set by fetch when the body is a FormData instance.
      delete options.headers['content-type']

      // GraphQL multipart request spec:
      // https://github.com/jaydenseric/graphql-multipart-request-spec

      const form = new FormData()

      form.append('operations', payload)

      const map = {}
      let i = 0
      files.forEach(paths => {
github nearform / graphql-hooks / packages / graphql-hooks / src / GraphQLClient.js View on Github external
getFetchOptions(operation, fetchOptionsOverrides = {}) {
    const fetchOptions = {
      method: 'POST',
      headers: {
        ...this.headers
      },
      ...this.fetchOptions,
      ...fetchOptionsOverrides
    }

    if (fetchOptions.method === 'GET') {
      return fetchOptions
    }

    const { clone, files } = extractFiles(
      operation,
      '',
      isExtractableFileEnhanced
    )
    const operationJSON = JSON.stringify(clone)

    if (files.size) {
      // See the GraphQL multipart request spec:
      // https://github.com/jaydenseric/graphql-multipart-request-spec

      if (!this.FormData) {
        throw new Error(
          'GraphQLClient: FormData must be polyfilled or passed in new GraphQLClient({ FormData })'
        )
      }
github HarenBroog / ember-graph-data / addon / apollo-client / network-interface.js View on Github external
fetchFromRemoteEndpoint({ request, options }) {
    // Continue if uploads are possible
    if (typeof FormData !== 'undefined') {
      // Extract any files from the request variables

      const files = extractFiles(request.variables, 'variables')

      // Continue if there are files to upload
      if (files.length) {
        // Convert query AST to string for transport
        request.query = printAST(request.query)

        // Construct a multipart form
        const formData = new FormData()
        // formData.append('operations', JSON.stringify(request))
        formData.append('query', request.query)
        formData.append('operationName', request.operationName)
        files.forEach(({ path, file }) => {
          formData.append(path, file)
          request.variables[path.replace("variables.", "")] = path
        })
        formData.append('variables', JSON.stringify(request.variables))
github WorkSight / rewire / packages / rewire-graphql / src / client.ts View on Github external
export function uploadMiddleware(query: IQuery, request: RequestInit, next: () => void) {
  if (!query || !query.variables || !request.headers) return next();
  const { clone, files } = extractFiles({variables: query.variables});
  if (files.size === 0) return next();

  delete request.headers['content-type'];

  // GraphQL multipart request spec:
  // https://github.com/jaydenseric/graphql-multipart-request-spec
  const form = new FormData();
  form.append('operations', BSON.stringify({query: (isGQL(query.query)) ? query.query.loc.source.body : query.query, variables: clone.variables}));

  const map = {};
  let i     = 0;
  files.forEach((paths: string) => {
    map[++i] = paths;
  });
  form.append('map', JSON.stringify(map));
github jaydenseric / apollo-upload-client / src / batched-network-interface.js View on Github external
(files, request, index) =>
          files.concat(extractFiles(request.variables, `${index}.variables`)),
        []
github sysgears / apollo-universal-starter-kit / modules / upload / client-react / netLink.js View on Github external
    ({ variables }) => extractFiles(cloneDeep(variables)).length > 0,
    createUploadLink({ uri, credentials: 'include' }),

extract-files

A function to recursively extract files and their object paths within a value, replacing them with null in a deep clone without mutating the original value. FileList instances are treated as File instance arrays. Files are typically File and Blob instance

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Popular extract-files functions