{"id":47986,"library":"graphql.js","title":"graphql.js","description":"A lightweight, dependency-free GraphQL client for JavaScript (version 0.6.8, last updated in 2017). It supports both browser and Node.js environments, providing a simple API for executing queries and mutations with fragment management. Key differentiators: <4kB gzipped, zero dependencies, isomorphic, query merging, and no requirement for React or Relay. However, it is outdated and lacks TypeScript support, modern ESM, and subscription support. Development appears to be stagnant with no recent releases.","status":"deprecated","version":"0.6.8","language":"javascript","source_language":"en","source_url":"https://github.com/f/graphql-client","tags":["javascript","graphql","graphql-client","jquery","relay","graphql-rails"],"install":[{"cmd":"npm install graphql.js","lang":"bash","label":"npm"},{"cmd":"yarn add graphql.js","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql.js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single default function. Named import pattern is incorrect.","wrong":"import { graphql } from 'graphql.js'","symbol":"default","correct":"import graphql from 'graphql.js'"},{"note":"CommonJS require yields the default export as a function. Destructuring will fail.","wrong":"const { graphql } = require('graphql.js')","symbol":"require","correct":"const graphql = require('graphql.js')"},{"note":"In browser, the library sets a global `graphql` function. No import needed.","wrong":"","symbol":"graphql (global)","correct":"<script src='graphql.min.js'></script>"}],"quickstart":{"code":"import graphql from 'graphql.js';\n\nconst graph = graphql('/graphql', {\n  method: 'POST',\n  headers: {\n    'Authorization': 'Bearer ' + (process.env.GRAPHQL_TOKEN ?? '')\n  },\n  fragments: {\n    user: 'on User { id, name }'\n  }\n});\n\nconst allUsers = graph(`query { allUsers { ...user } }`);\n\nconst createUser = graph(`mutation (@autodeclare) {\n  createUser($firstName, $lastName) { ...user }\n}`);\n\nasync function main() {\n  const newUser = await createUser({ firstName: 'John', lastName: 'Doe' });\n  console.log('Created:', newUser);\n  const users = await allUsers();\n  console.log('All users:', users);\n}\n\nmain().catch(console.error);","lang":"javascript","description":"Shows connection setup with token, fragment definition, and execution of both a mutation and a query."},"warnings":[{"fix":"Migrate to a maintained GraphQL client such as graphql-request.","message":"Package is no longer actively maintained. Last release was in 2017. Use modern alternatives like graphql-request or Apollo Client.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Always call the prepared function: const result = await graph(query)(variables);","message":"Query preparation returns a function that must be called to execute. Forgetting to invoke results in a Promise-like object that is not thenable.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use `@autodeclare` in mutation/query string or explicitly declare variables (e.g., `$email: String!`).","message":"The library uses `@autodeclare` directive to automatically declare variables. If omitted, variables must be manually defined in the query string.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Manually check for errors in the response or use a try-catch around the call.","message":"The `graph` function returns the raw `data` object from the GraphQL response on success and the `errors` object on failure. There is no built-in error handling for network issues.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.6.8':12 '2017':16 '4kb':38 'api':27 'appear':66 'browser':20 'client':8,78 'depend':5,41 'dependency-fre':4 'develop':65 'differenti':37 'environ':23 'esm':61 'execut':29 'fragment':34 'free':6 'graphql':7,75,77,82 'graphql-client':76 'graphql-rail':81 'graphql.js':1 'gzip':39 'howev':52 'isomorph':42 'javascript':10,74 'jqueri':79 'key':36 'lack':57 'last':13 'lightweight':3 'manag':35 'merg':44 'modern':60 'mutat':32 'node.js':22 'outdat':55 'provid':24 'queri':30,43 'rail':83 'react':49 'recent':72 'relay':51,80 'releas':73 'requir':47 'simpl':26 'stagnant':69 'subscript':63 'support':18,59,64 'typescript':58 'updat':14 'version':11 'zero':40","created_at":"2026-06-07T16:54:21.537955+00:00","updated_at":"2026-06-07T16:54:21.537955+00:00","problems":[{"fix":"Use `import graphql from 'graphql.js'` or `const graphql = require('graphql.js')`.","cause":"Importing the library incorrectly, e.g., using named import instead of default.","error":"Uncaught TypeError: graph is not a function"},{"fix":"First call `graph(queryString)` to prepare a query, then call the returned function with variables: `const exec = graph('query...'); exec(variables)`.","cause":"Calling the `graph` function without passing a query string first. The initial call configures and returns a query executer.","error":"TypeError: graph(...) is not a function"},{"fix":"Check the GraphQL endpoint URL and ensure it returns valid JSON with `{ data: ... }`. Add error handling for network failures.","cause":"The server returned a non-200 status or the response format is unexpected. The library expects a JSON response with a `data` field.","error":"Cannot read property 'data' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/f/graphql-client#readme","github":"https://github.com/f/graphql-client","docs":null,"changelog":null,"pypi":null,"npm":"graphql.js","openapi_spec":null,"status_page":null,"smithery":null,"categories":["api-client"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}