{"id":22004560,"url":"https://github.com/slicknode/slicknode-client","last_synced_at":"2026-04-13T16:35:36.033Z","repository":{"id":32960142,"uuid":"99413835","full_name":"slicknode/slicknode-client","owner":"slicknode","description":"Lightweight GraphQL client for slicknode GraphQL servers","archived":false,"fork":false,"pushed_at":"2022-12-06T14:34:12.000Z","size":153,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-01-28T12:46:20.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/slicknode.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}},"created_at":"2017-08-05T09:44:50.000Z","updated_at":"2021-10-23T12:49:46.000Z","dependencies_parsed_at":"2023-01-14T22:50:32.650Z","dependency_job_id":null,"html_url":"https://github.com/slicknode/slicknode-client","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slicknode%2Fslicknode-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slicknode%2Fslicknode-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slicknode%2Fslicknode-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slicknode%2Fslicknode-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slicknode","download_url":"https://codeload.github.com/slicknode/slicknode-client/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245062936,"owners_count":20554828,"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-11-30T00:16:28.910Z","updated_at":"2026-04-13T16:35:31.008Z","avatar_url":"https://github.com/slicknode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slicknode GraphQL Client\n\n[![npm version](https://badge.fury.io/js/slicknode-client.svg)](https://badge.fury.io/js/slicknode-client) \n[![CircleCI](https://circleci.com/gh/slicknode/slicknode-client.svg?style=shield)](https://circleci.com/gh/slicknode/slicknode-client)\n\nA lightweight client to make requests to a slicknode GraphQL server. Sends GraphQL queries while automatically\nadding authentication headers, refreshing access tokens in the background on expiration and with support\nfor authenticators. \n\n**Note:** If you are looking for a client to build a frontend application, we recommend using [slicknode-apollo-link](https://github.com/slicknode/slicknode-apollo-link),\nthe Slicknode version of the [Apollo Client](https://www.apollographql.com/client) with auth support and recommended \ndefaults. \n\n\n## Installation\n\nThe client can be installed via npm (GraphQL is a peer dependency): \n\n    npm install -S slicknode-client graphql\n\n\n## Why Slicknode Client?\n\nWhile you can use any GraphQL client to send queries to a Slicknode GraphQL server, Slicknode client simplifies the management\nof auth tokens that you would otherwise have to manually set in your client. It keeps track of token expiration times\nand automatically refreshes them in the background without interruption. \n\n\n## Usage\n\nCreate a client by providing the slicknode GraphQL endpoint:\n\n```javascript\nimport Client from 'slicknode-client';\nimport gql from 'graphql-tag';\n\nconst client = new Client({\n  endpoint: 'http://myproject.slicknode.com/'\n});\n\n// Now you can start sending GraphQL queries\nconst variables = {};\nconst query = gql`query {\n  viewer {\n    user {\n      email\n    }\n  }\n}`;\n\nclient.fetch(query, variables)\n  .then(({data, errors}) =\u003e {\n    console.log('Data loaded', data);\n  })\n  .catch(err =\u003e {\n    console.log('Something went wrong: ', err.message);\n  });\n```\n\n## Authentication\n\nBy default, there are no authentication headers sent to the GraphQL server, so the\nclient is making requests as a guest. To determine which user accesses the API, Slicknode uses JSON Web Tokens \nthat need to be sent in the HTTP headers of each request. \n\nTo obtain an access token from your GraphQL server, a user needs to authenticate itself via a mutation that is \navailable on the Slicknode server (for example email / password). You can install one of the [available authentication\nmodules](#available-authentication-adapters) or build your own. \n\nThe access and refresh tokens with their expiration times that are returned by that mutation need to be \nset in the `slicknode-client` instance. (`client.setAuthTokenSet(myTokenSet)`)\n\nThis is simplified with the use of authenticators.\n\n\n### Authenticators\n\nAn authenticator is a function that loads the auth token set from the Slicknode API and passes it to the client. \nYou just have to install [the right authenticator](#available-authentication-adapters) and pass it to the authenticate method. \n\n**Example:**\n\n```javascript\nimport loginEmailPassword from 'slicknode-auth-email-password';\nimport Client from 'slicknode-client';\n\nconst email = 'info@slicknode.com';\nconst password = '12345xyz';\nconst client = new Client({\n  endpoint: 'http://myproject.slicknode.com/'\n});\nclient.authenticate(loginEmailPassword(email, password))\n  .then(() =\u003e {\n    console.log('Login was successful');\n  })\n  .catch(err =\u003e {\n    console.log('Login failed', err.message);\n  });\n\n\n// To log a user out\nclient.logout()\n  .then(() =\u003e {\n    console.log('Logout successful');\n  })\n  .catch(err =\u003e {\n    console.log('Something went wrong: ', err.message);\n  });\n```\n\nThe Slicknode client persists the auth tokens to localStorage or to an in memory storage if localStorage is\nnot available (NodeJS). The authentication headers are automatically added to each subsequent request. \n\nWhen the accessToken expires, Slicknode uses the stored refreshToken to obtain a new token set without interruption \nto the client. That way you can just fetch data and let the Slicknode client handle the authentication headers. \n\n\n### Available Authentication Adapters\n\nYou can use any of the following authentication adapters or build your own: \n\n- **[Email / Password](https://github.com/slicknode/slicknode-auth-email-password):** Authentication with\nemail address and password\n\nOnce a user is authenticated, the slicknode client automatically takes care of\nrefreshing the access token in the background.\n\nTo learn more about authentication and auth tokens for Slicknode servers, check out the section for authentication in\nthe Slicknode documentation. \n\n\n#### Custom authenticator\n\nAn authenticator has the following function signature: \n\n```typescript\nexport type AuthTokenSet = {\n  accessToken: string,\n  accessTokenLifetime: number,\n  refreshToken: string,\n  refreshTokenLifetime: number\n}\n\nexport type Authenticator = (client: Client) =\u003e Promise\u003cAuthTokenSet\u003e;\n```\n\nYou can use the instance of the client that is being passed to the authenticator to run mutations\non your GraphQL server and obtain the tokens. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslicknode%2Fslicknode-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslicknode%2Fslicknode-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslicknode%2Fslicknode-client/lists"}