{"id":24143358,"url":"https://github.com/little-core-labs/gqlr","last_synced_at":"2025-08-10T03:04:42.823Z","repository":{"id":36977380,"uuid":"270010245","full_name":"little-core-labs/gqlr","owner":"little-core-labs","description":"(g)raph(ql)-(r)equest.  A simplified fork of graphql-request","archived":false,"fork":false,"pushed_at":"2023-02-27T05:01:55.000Z","size":110,"stargazers_count":6,"open_issues_count":10,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-26T11:54:27.780Z","etag":null,"topics":["esm","gqlr","graphql","graphql-request"],"latest_commit_sha":null,"homepage":"http://npmjs.com/gqlr","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/little-core-labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2020-06-06T14:45:14.000Z","updated_at":"2024-07-05T02:13:00.000Z","dependencies_parsed_at":"2025-01-12T05:15:23.413Z","dependency_job_id":"b265d1f2-c85d-4d03-b5f0-f4ffa11569e6","html_url":"https://github.com/little-core-labs/gqlr","commit_stats":{"total_commits":85,"total_committers":4,"mean_commits":21.25,"dds":"0.43529411764705883","last_synced_commit":"30133896547da130fc8b58234bd5256644e66e41"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/little-core-labs/gqlr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fgqlr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fgqlr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fgqlr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fgqlr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/little-core-labs","download_url":"https://codeload.github.com/little-core-labs/gqlr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Fgqlr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269668187,"owners_count":24456495,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["esm","gqlr","graphql","graphql-request"],"created_at":"2025-01-12T05:15:19.186Z","updated_at":"2025-08-10T03:04:42.795Z","avatar_url":"https://github.com/little-core-labs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gqlr\n![tests](https://github.com/little-core-labs/gqlr/workflows/tests/badge.svg)\n\nMinimaler Fork of the Minimal GraphQL client [graphql-request](https://ghub.io/graphql-request).\n\n## Features\n\n- Even simpler than graphql-request! Needlessly duplicated code removed.\n- Same Promise-based API (works with `async` / `await`).\n- No Typescript.\n- Actually Isomorphic (works with Node / browsers). Ships a real ESM module, instead of the fake one TS generates.\n\n## Why?\n\ngraphql-request was causing problems downstream due to the fake ESM module it ships, making it incompatible with **both** browser esm and node.js esm.  Additionally, many people are using graphql-request already, so making some simple breaking changes would cause a headache for everyone involved.\n\n## Install\n\n```sh\nnpm add gqlr\n```\n\n## Quickstart\n\nSend a GraphQL query with a single line of code. ▶️ [Try it out](https://runkit.com/593130bdfad7120012472003/593130bdfad7120012472004).\n\n```js\nimport { request } from 'gqlr'\n\nconst query = `{\n  Movie(title: \"Inception\") {\n    releaseDate\n    actors {\n      name\n    }\n  }\n}`\n\nrequest('https://api.graph.cool/simple/v1/movies', query).then((data) =\u003e console.log(data))\n```\n\nor directly in the browser with native ESM:\n\n```js\nimport { request } from 'https://unpkg.com/gqlr@^1?module'\n\nconst query = `{\n  Movie(title: \"Inception\") {\n    releaseDate\n    actors {\n      name\n    }\n  }\n}`\n\nrequest('https://api.graph.cool/simple/v1/movies', query).then((data) =\u003e console.log(data))\n```\n\n## Usage\n\n```js\nimport { request, GraphQLClient } from 'gqlr' // Works with real Node.js ESM\n\n// Run GraphQL queries/mutations using a static function\nrequest(endpoint, query, variables).then((data) =\u003e console.log(data))\n\n// ... or create a GraphQL client instance to send requests\nconst client = new GraphQLClient(endpoint, { headers: {} })\nclient.request(query, variables).then((data) =\u003e console.log(data))\n```\n\n## API\n\n### `import { GraphQLClient, request, rawRequest } from 'gqlr'`\n\nImport the `GraphQLClient` class, `request` and `rawRequest` from `gqlr`.\n\n### `client = new GraphQLClient(url, [opts])`\n\nCreate a new `client` instance of `GraphQLClient` for a given `url` with the following default `opts` passed the [`node-fetch`](https://ghub.io/node-fetch) internally:\n\n```js\n{\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json' },\n}\n````\n\nAny `opts.headers` are mixed in with the default headers, and any other properties on `opts` are passed as `fetch` options.\n\n### `{ headers, status, ...result } = await client.rawRequest(query, [variables])`\n\nMake a `query` request with a `client` including the optional `variables` object, returning extra response properties like `extensions`.\n\n### `data = await client.request(query, [variables])`\n\nMake a `query` request with a `client` including the optional `variables` object, returning just the `data` field.\n\n### `data = await client.stringRequest(body)`\n\nMake a request with a `body` string to the configured GQL endpoint.  The body should be in the form of:\n\n\n```js\nconst body = JSON.stringify({\n  query: '{ viewer { id } }',\n  variables: {}\n})\n```\n\nUseful with tools like [SWR](https://github.com/vercel/swr), where you usually stringify a query and variables object into a cache key that gets passed to your fetcher function.  With `stringRequest`, you can avoid double `JSON.stringify` problems, or complex variable scope passing.\n\n### `client = client.setHeaders(headers)`\n\nPass a `headers` object to a client to customize the headers.\n\n### `client = client.setHeader(key, value)`\n\nSet a specific header by a key and a value.\n\n### `{ headers, status, ...result } = rawRequest(url, query, [variables], [opts])`\n\nConvenience function to instantiate a client and make a request in a single function call, returning the extended properties of the graphql request.\n\n### `data = request(url, query, [variables], [opts])`\n\nConvenience function to instantiate a client and make a request in a single function call.\n\n### `data = stringRequest(url, body, [opts])`\n\nConvenience function to instantiate a client and make a `stringRequest` in a single function call.\n\n## Examples\n\n### Authentication via HTTP header\n\n```js\nimport { GraphQLClient } from 'gqlr'\n\nasync function main() {\n  const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'\n\n  const graphQLClient = new GraphQLClient(endpoint, {\n    headers: {\n      authorization: 'Bearer MY_TOKEN',\n    },\n  })\n\n  const query = /* GraphQL */ `\n    {\n      Movie(title: \"Inception\") {\n        releaseDate\n        actors {\n          name\n        }\n      }\n    }\n  `\n\n  const data = await graphQLClient.request(query)\n  console.log(JSON.stringify(data, undefined, 2))\n}\n\nmain().catch((error) =\u003e console.error(error))\n```\n\n[Example File](examples/authentication-via-http-header.js)\n\n### Passing more options to fetch\n\n```js\nimport { GraphQLClient } from 'gqlr'\n\nasync function main() {\n  const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'\n\n  const graphQLClient = new GraphQLClient(endpoint, {\n    credentials: 'include',\n    mode: 'cors',\n  })\n\n  const query = /* GraphQL */ `\n    {\n      Movie(title: \"Inception\") {\n        releaseDate\n        actors {\n          name\n        }\n      }\n    }\n  `\n\n  const data = await graphQLClient.request(query)\n  console.log(JSON.stringify(data, undefined, 2))\n}\n\nmain().catch((error) =\u003e console.error(error))\n```\n\n[Example](examples/passing-more-options-to-fetch.js)\n\n### Using variables\n\n```js\nimport { request } from 'gqlr'\n\nasync function main() {\n  const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'\n\n  const query = /* GraphQL */ `\n    query getMovie($title: String!) {\n      Movie(title: $title) {\n        releaseDate\n        actors {\n          name\n        }\n      }\n    }\n  `\n\n  const variables = {\n    title: 'Inception',\n  }\n\n  const data = await request(endpoint, query, variables)\n  console.log(JSON.stringify(data, undefined, 2))\n}\n\nmain().catch((error) =\u003e console.error(error))\n```\n\n[Example](examples/using-variables.js)\n\n### Error handling\n\n```js\nimport { request } from 'gqlr'\n\nasync function main() {\n  const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'\n\n  const query = /* GraphQL */ `\n    {\n      Movie(title: \"Inception\") {\n        releaseDate\n        actors {\n          fullname # \"Cannot query field 'fullname' on type 'Actor'. Did you mean 'name'?\"\n        }\n      }\n    }\n  `\n\n  try {\n    const data = await request(endpoint, query)\n    console.log(JSON.stringify(data, undefined, 2))\n  } catch (error) {\n    console.error(JSON.stringify(error, undefined, 2))\n    process.exit(1)\n  }\n}\n\nmain().catch((error) =\u003e console.error(error))\n```\n\n[Example](examples/error-handling.js)\n\n### Using `require` instead of `import`\n\n```js\nconst { request } = require('gqlr')\n\nasync function main() {\n  const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'\n\n  const query = /* GraphQL */ `\n    {\n      Movie(title: \"Inception\") {\n        releaseDate\n        actors {\n          name\n        }\n      }\n    }\n  `\n\n  const data = await request(endpoint, query)\n  console.log(JSON.stringify(data, undefined, 2))\n}\n\nmain().catch((error) =\u003e console.error(error))\n```\n\n### Cookie support for `node`\n\n```sh\nnpm install fetch-cookie\n```\n\n```js\n// This probably only works in CJS environments.\nrequire('fetch-cookie/node-fetch')(require('node-fetch'))\n\nrequire { GraphQLClient } = require('gqlr')\n\nasync function main() {\n  const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'\n\n  const graphQLClient = new GraphQLClient(endpoint, {\n    headers: {\n      authorization: 'Bearer MY_TOKEN',\n    },\n  })\n\n  const query = /* GraphQL */ `\n    {\n      Movie(title: \"Inception\") {\n        releaseDate\n        actors {\n          name\n        }\n      }\n    }\n  `\n\n  const data = await graphQLClient.rawRequest(query)\n  console.log(JSON.stringify(data, undefined, 2))\n}\n\nmain().catch((error) =\u003e console.error(error))\n```\n\n[Example](examples/cookie-support-for-node.js)\n\n### Receiving a raw response\n\nThe `request` method will return the `data` or `errors` key from the response.\nIf you need to access the `extensions` key you can use the `rawRequest` method:\n\n```js\nimport { rawRequest } from 'gqlr'\n\nasync function main() {\n  const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'\n\n  const query = /* GraphQL */ `\n    {\n      Movie(title: \"Inception\") {\n        releaseDate\n        actors {\n          name\n        }\n      }\n    }\n  `\n\n  const { data, errors, extensions, headers, status } = await rawRequest(endpoint, query)\n  console.log(JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2))\n}\n\nmain().catch((error) =\u003e console.error(error))\n```\n\n[Example](examples/receiving-a-raw-response.js)\n\n## FAQ\n\n### What's the difference between `gqlr` and `graphql-request`?\n\n`gqlr` is a minimal, mostly drop-in replacement of `graphql-request` aimed at:\n\n- shipping artifacts with working esm exports.\n- work in the browser without a bundler (even more minimal)\n- work with Node.js \"type\": \"module\".\n- further reducing library size (remove unnecessarily duplicated code)\n- removing the project overhead of Typescript syntax, Typescript tooling, and Typescript bugs.\n- Clarify undocumented methods and edge-cases.\n\nBreaking changes include:\n\n- No fake 'default' export.  If you use this, switch to importing named exports.\n- Imports node-fetch.  This might break react native, not sure.\n\n\n### This is too simple, to use the power of graphql you must use...\n\n- This module pairs really well with [swr](https://swr.now.sh) and other similar ideas.  If you need caching, react hooks and any other party tricks, just use that.  Orthogonal concerns ftw.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittle-core-labs%2Fgqlr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flittle-core-labs%2Fgqlr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittle-core-labs%2Fgqlr/lists"}