{"id":42816838,"url":"https://github.com/mantir/best-graphql-client","last_synced_at":"2026-01-30T06:40:04.771Z","repository":{"id":40714765,"uuid":"276629405","full_name":"mantir/best-graphql-client","owner":"mantir","description":"This client is best for you, if you like it short and elegant. It uses the ApolloClient in the background.","archived":false,"fork":false,"pushed_at":"2023-08-16T14:35:50.000Z","size":140,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-11-13T17:31:58.506Z","etag":null,"topics":["browser","client","graphql","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","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/mantir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-02T11:33:03.000Z","updated_at":"2023-04-11T15:30:27.000Z","dependencies_parsed_at":"2023-01-30T04:30:49.925Z","dependency_job_id":null,"html_url":"https://github.com/mantir/best-graphql-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/mantir/best-graphql-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mantir%2Fbest-graphql-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mantir%2Fbest-graphql-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mantir%2Fbest-graphql-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mantir%2Fbest-graphql-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mantir","download_url":"https://codeload.github.com/mantir/best-graphql-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mantir%2Fbest-graphql-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28906724,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T04:02:34.702Z","status":"ssl_error","status_checked_at":"2026-01-30T04:02:33.562Z","response_time":66,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["browser","client","graphql","javascript","nodejs"],"created_at":"2026-01-30T06:40:04.225Z","updated_at":"2026-01-30T06:40:04.722Z","avatar_url":"https://github.com/mantir.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Best Javascript GraphQL Client for the Browser and Node.js\n\nJust provide the url of any GraphQL endpoint to generate the information the client needs and be ready to write queries like this:\n\n```javascript\nbgc.get('posts', {where: {title: \"Your title\"}}, [\"author\", {comments: [\"user\"]}])\n```\n\nIf you care about overfetching and don't need all the fields, just use GraphQL-syntax as you already now it:\n\n```javascript\nbgc.get('posts', {where: {title: \"Your title\"}}, 'text author{ name } comments{ text user{ id name } }');\n```\n\nOr put in a whole GraphQL-query. It's up to you:\n\n```javascript\nbgc.get('query { posts { text author{ name } comments{ text user{ id name } } } }');\n```\n\nBy the way: The client supports subscriptions out of the box:\n\n```javascript\nbgc.subscribe(function(data) { console.log(data); }, 'notification', {where: {user: {id: 1}}});\n```\n\nThis client is the best for you, if you like it short and elegant. It uses the ApolloClient in the background. \n\n## Installation\n\n### Add this repo to your package.json:\n\n_*dependencies:*_\n\n- \"best-graphql-client\": \"git+https://github.com/mantir/best-graphl-client.git\"\n\n### Add this script to your package.json: \n\n_*scripts:*_\n\n- \"generate\": \"FOLDER=\\`pwd\\` npm run --prefix node_modules/best-graphql-client generate\"\n\n```bash\nnpm install\n```\n\n### Generate definitions for endpoint:\n```bash\nENDPOINT=https://url-to-endpoint npm run generate\nENDPOINT=https://url-to-endpoint NAME=definitions-filename npm run generate\n```\nThis will create definitions.js which must be included when initializing the client.\n\n```javascript\nconst endpoint = 'http://url-to-endpoint'; //Url to endpoint\nconst definitions = require('./definitions');\nvar bgc = require('best-graphql-client/browser')(endpoint, definitions);\n/* OR */\nvar bgc = require('best-graphql-client/nodejs')(endpoint, definitions);\n```\n\n## Functions\n\nThe following functions can be used to query a GraphlQL endpoint. \n\n### get(_string_ name [, _object_ parameters [, _array_ includes] [, _string_ fields] [, _object_ options]])\n_Graphql-Query_: \n`query do(parameters) { name(parameters) { fields + includes } }`\n\nIf 3 parameters are given: If the 3rd is a string, it is used as the `fields`.\nIf `fields` are empty, all fields are returned.\n`includes` can also be ['*'], then all connected objects are returned. (See Example-Usage)\n\n### mutate(_string_ name [, _object_ parameters [, _array_ includes] [, _string_ fields] [, _object_ options]])\n_Graphql-Mutation_: (Same as `get`, just as `mutation`)\n\n\n### subscribe(_function_ callback, _string_ name [, _object_ parameters [, _array_ includes] [, _string_ fields] [, _object_ options]])\n_Graphql-Mutation_: (Same as `get`, just as `subscription`)\n- `options?: Object` : optional, object to modify default ApolloClient behavior\n  * `timeout?: number` : how long the client should wait in ms for a keep-alive message from the server (default 30000 ms), this parameter is ignored if the server does not send keep-alive messages. This will also be used to calculate the max connection time per connect/reconnect\n  * `lazy?: boolean` : use to set lazy mode - connects only when first subscription created, and delay the socket initialization\n  * `connectionParams?: Object | Function | Promise\u003cObject\u003e` : object that will be available as first argument of `onConnect` (in server side), if passed a function - it will call it and send the return value, if function returns as promise - it will wait until it resolves and send the resolved value.\n  * `reconnect?: boolean` : automatic reconnect in case of connection error\n  * `reconnectionAttempts?: number` : how much reconnect attempts\n  * `connectionCallback?: (error) =\u003e {}` : optional, callback that called after the first init message, with the error (if there is one)\n  * `inactivityTimeout?: number` : how long the client should wait in ms, when there are no active subscriptions, before disconnecting from the server. Set to 0 to disable this behavior. (default 0)\n\n### fragment(_string_ name, _array_ includes, _string_ query)\n_Fragment for Graphql-Query_\n\n### getMulti(_array_ queries, _object_ options = { _int_ chunkSize = 100, _function_ onError(_object_ result, _int_ errorCount), _function_ progressCallback(_float_ percent between 0 and 1) })\nExecutes multiple queries at once. The `queries` array contains arrays of the parameters for the `get` function. E.g.: queries = [['elements', { where: { date: '01.01.2022' } }, ['includes'], 'field1 field2'], ['elements', { where: { date: '02.01.2022' } }, ...], ...]. \n`chunkSize` indicates how many queries are submitted per request. \n`onError` is a custom function executed if a request fails. The can return 'REPEAT', then the request will be tried again. The max number of repetitions is 10.\n`progressCallback` is a custom function which receives the ratio of requests sent and total requests to be sent.\n\n### mutateMulti(_array_ queries, _object_ options = { _int_ chunkSize = 100, _function_ onError(_object_ result, _int_ errorCount), _function_ progressCallback(_float_ percent between 0 and 1) })\nSame as `getMulti`, just for the `mutate` function.\n\n\n## Includes\n\nTo pass parameters to includes, e.g. to get the comments of only one user: \n```\n{ comments: { $: {user_id: 1} }}\n``` \nparameters can be passed with `$` as key. \n\nIf an include should have another name in the result it can be passed as `$name`, e.g. \n```\n{ comments: { $name: \"userComments\", $: {user_id: 1} }}\n```\n\n\n## Example-Usage\n\n```javascript\nconst endpoint = 'http://url-to-endpoint.com'; //Url to endpoint\nconst definitions = require('./definitions');\n/* For usage in browser environment */\nvar bgc = require('best-graphql-client/browser')(endpoint, definitions);\n/* For usage in nodejs environment */\nvar bgc = require('best-graphql-client/nodejs')(endpoint, definitions);\n\n/* All tags with all fields but without connected objects */\nvar stations = await bgc.get('tags');\n\n/* All tags with parameters, all fields but without connected objects */\nvar tags = await bgc.get('tags', {orderBy: 'name_ASC'});\n\n/* All tags with only field 'name' and connected object 'tagCategory' */\nvar tags = await bgc.get('tags', {orderBy: 'name_ASC'}, ['tagCategory'], 'name');\n/* Same as */\nvar tags = await bgc.get('tags', {orderBy: 'name_ASC'}, 'name tagCategory { allFields }');\n\n/* All tags with the field 'name' but without connected objects */\nvar tags = await bgc.get('tags', {}, 'name');\n\n/* All tags with all fields and all connected objects with all their fields */\nvar tags = await bgc.get('tags', {orderBy: 'name_ASC'}, ['*'])\n\n/* All tags with all fields and all connected objects (except movies) with all their fields */\nvar tags = await bgc.get('tags', {orderBy: 'name_ASC'}, ['*', '!movies'])\n\n/* posts: includes the fields of all connected objects and for the comments it includes also all the fields of the user */\nvar posts = await bgc.get('posts', {where: {title: \"Your title\"}}, [\"*\", {comments: [\"user\"]}])\n\n/* posts: includes the fields of all connected objects and for the comments, which contain \"hello\", it includes also all the fields of the user */\nvar posts = await bgc.get('posts', {where: {title: \"Your title\"}}, [\"*\", {comments: {$: {where: {content_contains: \"hello\"} }, user: true}])\n\n/* The same but as fragments */\nvar posts = await bgc.get('posts', {where: {title: \"Your title\"}}, [\"*|fragment\", {\"comments|fragment\": [\"user\"]}])\n\n/* Create tag */\nvar res = await bgc.mutate('createTag', {data: { name: \"TESTING\" }})\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmantir%2Fbest-graphql-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmantir%2Fbest-graphql-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmantir%2Fbest-graphql-client/lists"}