{"id":13515981,"url":"https://github.com/thebigredgeek/apollo-errors","last_synced_at":"2025-05-14T10:09:32.246Z","repository":{"id":13051215,"uuid":"73427404","full_name":"thebigredgeek/apollo-errors","owner":"thebigredgeek","description":"Machine-readable custom errors for Apollostack's GraphQL server","archived":false,"fork":false,"pushed_at":"2025-03-21T22:46:59.000Z","size":91,"stargazers_count":407,"open_issues_count":15,"forks_count":27,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-31T15:32:21.227Z","etag":null,"topics":["apollo-client","apollo-server","apollostack-graphql-server","graphql"],"latest_commit_sha":null,"homepage":"","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/thebigredgeek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-11-10T22:48:51.000Z","updated_at":"2024-11-16T13:00:57.000Z","dependencies_parsed_at":"2024-05-17T22:30:51.167Z","dependency_job_id":"ec7cf154-0ac8-4341-8dda-44c6d4cd44d4","html_url":"https://github.com/thebigredgeek/apollo-errors","commit_stats":{"total_commits":70,"total_committers":11,"mean_commits":6.363636363636363,"dds":0.6571428571428571,"last_synced_commit":"5e7e23a5b288819b1efca085b1b74911e2604963"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thebigredgeek%2Fapollo-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thebigredgeek%2Fapollo-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thebigredgeek%2Fapollo-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thebigredgeek%2Fapollo-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thebigredgeek","download_url":"https://codeload.github.com/thebigredgeek/apollo-errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411267,"owners_count":20934650,"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":["apollo-client","apollo-server","apollostack-graphql-server","graphql"],"created_at":"2024-08-01T05:01:18.049Z","updated_at":"2025-04-11T03:34:57.754Z","avatar_url":"https://github.com/thebigredgeek.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Libraries"],"sub_categories":["JavaScript Libraries"],"readme":"# apollo-errors\nMachine-readable custom errors for Apollostack's GraphQL server\n\n[![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/apollo-errors/)\n\n[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master)\n\n## Example from Apollo Day\n\n[![Authentication and Error Handling in GraphQL](https://img.youtube.com/vi/xaorvBjCE7A/0.jpg)](https://www.youtube.com/watch?v=xaorvBjCE7A)\n\n## Installation and usage\n\nInstall the package:\n\n```bash\nnpm install apollo-errors\n```\n\nCreate some errors:\n\n```javascript\nimport { createError } from 'apollo-errors';\n\nexport const FooError = createError('FooError', {\n  message: 'A foo error has occurred'\n});\n```\n\nHook up formatting:\n\n```javascript\nimport express from 'express';\nimport bodyParser from 'body-parser';\nimport { formatError } from 'apollo-errors';\nimport { graphqlExpress } from 'apollo-server-express';\nimport schema from './schema';\n\nconst app = express();\n\napp.use('/graphql',\n  bodyParser.json(),\n  graphqlExpress({\n    formatError,\n    schema\n  })\n);\n\napp.listen(8080)\n```\n\nThrow some errors:\n\n```javascript\nimport { FooError } from './errors';\n\nconst resolverThatThrowsError = (root, params, context) =\u003e {\n  throw new FooError({\n    data: {\n      something: 'important'\n    },\n    internalData: {\n      error: `The SQL server died.`\n    }\n  });\n}\n```\n\nWitness glorious simplicity:\n\n`POST /graphql (200)`\n\n```json\n{\n  \"data\": {},\n  \"errors\": [\n    {\n      \"message\":\"A foo error has occurred\",\n      \"name\":\"FooError\",\n      \"time_thrown\":\"2016-11-11T00:40:50.954Z\",\n      \"data\":{\n        \"something\": \"important\"\n      }\n    }\n  ]\n}\n```\n\nThe `internalData` property is meant for data you want to store on the error object (e.g. for logging), but not send out to your end users.\nYou can utilize this data for logging purposes.\n\n```js\nimport { isInstance as isApolloErrorInstance, formatError as formatApolloError } from 'apollo-errors';\n\nfunction formatError(error) {\n  const { originalError } = error;\n  if (isApolloErrorInstance(originalError)) {\n    // log internalData to stdout but not include it in the formattedError\n    console.log(JSON.stringify({\n      type: `error`,\n      data: originalError.data,\n      internalData: originalError.internalData\n    }));\n  }\n  return formatApolloError(error)\n}\n\n``` \n\n## API\n\n### ApolloError ({ [time_thrown: String, data: Object, internalData: object, message: String ]})\n\nCreates a new ApolloError object.  Note that `ApolloError` in this context refers\nto an error class created and returned by `createError` documented below.  Error can be\ninitialized with a custom `time_thrown` ISODate (default is current ISODate), `data` object (which will be merged with data specified through `createError`, if it exists), `internalData` object (which will be merged with internalData specified trough `createError`) and `message` (which will override the message specified through `createError`).\n\n\n### createError(name, {message: String, [data: Object, internalData: object, options: Object]}): ApolloError\n\nCreates and returns an error class with the given `name` and `message`, optionally initialized with the given `data`, `internalData` and `options`.  `data` and `internalData` passed to `createError` will later be merged with any data passed to the constructor.\n\n#### Options (default):\n\n - `showPath` *(false)*: Preserve the GraphQLError `path` data.\n - `showLocations` *(false)*:  Preserve the GraphQLError `locations` data.\n\n### formatError (error, strict = false): ApolloError|Error|null\nIf the error is a known ApolloError, returns the serialized form of said error.\n\n**Otherwise**, *if strict is not truthy*, returns the original error passed into formatError.\n\n**Otherwise**, *if strict is truthy*, returns null.\n\n### isInstance (error): Boolean\nReturns true if the error is an instance of an ApolloError.  Otherwise, returns false\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthebigredgeek%2Fapollo-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthebigredgeek%2Fapollo-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthebigredgeek%2Fapollo-errors/lists"}