{"id":13725269,"url":"https://github.com/relay-tools/fetch-multipart-graphql","last_synced_at":"2025-04-05T20:01:50.643Z","repository":{"id":32827573,"uuid":"143744863","full_name":"relay-tools/fetch-multipart-graphql","owner":"relay-tools","description":"Cross browser function to fetch and parse streaming multipart graphql responses","archived":false,"fork":false,"pushed_at":"2025-03-17T18:03:18.000Z","size":542,"stargazers_count":50,"open_issues_count":7,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T19:01:08.987Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/relay-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-06T15:04:09.000Z","updated_at":"2025-03-21T13:27:45.000Z","dependencies_parsed_at":"2024-06-18T18:39:16.731Z","dependency_job_id":"ff5f4049-4021-4b92-ad5e-7c4cdba0a2a2","html_url":"https://github.com/relay-tools/fetch-multipart-graphql","commit_stats":{"total_commits":72,"total_committers":10,"mean_commits":7.2,"dds":"0.29166666666666663","last_synced_commit":"fe82243c97bd6d9c4ed70f18a8c5017c027a8af2"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relay-tools%2Ffetch-multipart-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relay-tools%2Ffetch-multipart-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relay-tools%2Ffetch-multipart-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relay-tools%2Ffetch-multipart-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/relay-tools","download_url":"https://codeload.github.com/relay-tools/fetch-multipart-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393545,"owners_count":20931811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:02:17.802Z","updated_at":"2025-04-05T20:01:50.606Z","avatar_url":"https://github.com/relay-tools.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# fetch-multipart-graphql\n\nCross-browser function to fetch and parse streaming multipart graphql responses.\n\nThis allows you to efficiently fetch streamed GraphQL responses that use the @defer directive as supported by [Apollo Server](https://blog.apollographql.com/introducing-defer-in-apollo-server-f6797c4e9d6e). It can be easily used in a Relay Modern network layer to support deferred queries.\n\n## Usage\n\nIn a Relay Network Layer:\n\n```javascript\nimport fetchMultipart from 'fetch-multipart-graphql';\nimport { Observable } from 'relay-runtime';\n\nfunction fetchQuery(operation, variables) {\n    return Observable.create(sink =\u003e {\n        fetchMultipart('/graphql', {\n            method: 'POST',\n            headers: {\n                'content-type': 'application/json',\n            },\n            body: JSON.stringify({\n                query: operation.text,\n                variables,\n            }),\n            credentials: 'same-origin',\n            onNext: parts =\u003e sink.next(parts),\n            onError: err =\u003e sink.error(err),\n            onComplete: () =\u003e sink.complete(),\n        });\n    });\n}\n```\n\n#### Handling cookies and other auth headers\n\nThe `credentials` param is passed to [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters). For XHR requests, [`XMLHttpRequest.withCredentials`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials) is mapped to true when `credentials: 'include'`.\n\n#### Handling additional request settings\n\nWhen `fetch` is not available requests are sent through XHR, which supports standard `method`, `headers`, `credentials` and `body` settings; as seen in the code example above. \nWhen requests are sent through `fetch` we can also set, in addition to the properties already mentioned, all the [options supported by fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options).\n\n## Browser Support\n\nTested in the latest Chrome, Firefox, Safari, Edge, and Internet Explorer 11. Requires a polyfill for TextEncoder/Decoder. Since only utf-8 encoding is required, it's recommended to use [text-encoding-utf-8](https://www.npmjs.com/package/text-encoding-utf-8) to minimize impact on bundle size.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelay-tools%2Ffetch-multipart-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frelay-tools%2Ffetch-multipart-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelay-tools%2Ffetch-multipart-graphql/lists"}