@lwce/apollo-client
Advanced tools
Comparing version
@@ -10,2 +10,3 @@ /* | ||
export { useMutation } from './mutation'; | ||
export { getErrorString } from './error-helpers'; | ||
//# sourceMappingURL=index.js.map |
@@ -10,20 +10,2 @@ /* | ||
export const useQuery = Symbol('apollo-use-query'); | ||
function errorString(error) { | ||
if (error) { | ||
if (Array.isArray(error)) { | ||
let s = ""; | ||
for (let i of error) { | ||
if (s) | ||
s += "\n"; | ||
s += errorString(i); | ||
} | ||
return s; | ||
} | ||
if (typeof error !== 'string') { | ||
error = error.toString(); | ||
} | ||
return error; | ||
} | ||
return undefined; | ||
} | ||
register(useQuery, (eventTarget) => { | ||
@@ -58,3 +40,3 @@ let connected, apolloOptions, observableQuery, subscription, pendingResult = { | ||
data, | ||
error: errorString(errors), | ||
error: errors, | ||
initialized: true | ||
@@ -69,3 +51,3 @@ }); | ||
data: undefined, | ||
error: errorString(error), | ||
error, | ||
initialized: true | ||
@@ -72,0 +54,0 @@ }); |
export { getClient, setClient } from './client'; | ||
export { useQuery } from './query'; | ||
export { useMutation } from './mutation'; | ||
export { getErrorString } from './error-helpers'; |
{ | ||
"name": "@lwce/apollo-client", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Apollo client integration for Lightning Web Components", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -227,1 +227,21 @@ # @lwce/apollo-client | ||
The options are a merge between the global options defined at the `@wire` level, and the ones passed to the `mutate` method (the later overrides the former). | ||
### Error Helpers | ||
Easily convert GraphQL error responses into a human readable string: | ||
```js | ||
import { getErrorString } from '@lwce/apollo-client'; | ||
@wire(useQuery, { query: QUERY, lazy: false, variables: '$variables'}) | ||
update(response) { | ||
if (response.initialized) { | ||
if (response.error) { | ||
console.error(getErrorString(response.error)); | ||
} else { | ||
this.data = response.data; | ||
} | ||
} | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23241
4.5%18
28.57%229
1.33%246
8.37%3
50%