@graphitation/apollo-react-relay-duct-tape 0.7.11 → 0.7.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/lib/hooks.d.ts +187 -0
- package/lib/hooks.d.ts.map +1 -0
- package/lib/hooks.js +109 -0
- package/lib/hooks.mjs +95 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +18 -0
- package/lib/index.mjs +3 -0
- package/lib/types.d.ts +33 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +15 -0
- package/lib/types.mjs +0 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Change Log - @graphitation/apollo-react-relay-duct-tape
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 20 Jun 2022 10:02:00 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.7.12
|
|
8
|
+
|
|
9
|
+
Mon, 20 Jun 2022 10:02:00 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Bump @graphitation/apollo-mock-client to v0.10.10
|
|
14
|
+
- Bump @graphitation/graphql-js-operation-payload-generator to v0.10.3
|
|
15
|
+
|
|
7
16
|
## 0.7.11
|
|
8
17
|
|
|
9
|
-
Fri, 17 Jun 2022 09:48:
|
|
18
|
+
Fri, 17 Jun 2022 09:48:20 GMT
|
|
10
19
|
|
|
11
20
|
### Patches
|
|
12
21
|
|
package/lib/hooks.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { DocumentNode } from "graphql";
|
|
2
|
+
import { KeyType, KeyTypeData, OperationType } from "./types";
|
|
3
|
+
export declare type GraphQLTaggedNode = DocumentNode;
|
|
4
|
+
/**
|
|
5
|
+
* Executes a GraphQL query.
|
|
6
|
+
*
|
|
7
|
+
* This hook is called 'lazy' as it is used to fetch a GraphQL query _during_ render. This hook can trigger multiple
|
|
8
|
+
* round trips, one for loading and one for resolving.
|
|
9
|
+
*
|
|
10
|
+
* @see {useFragment} This function largely follows the documentation of `useFragment`, except that this is a root of a
|
|
11
|
+
* GraphQL operation and thus does not take in any props such as opaque fragment references.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
```typescript
|
|
15
|
+
import { graphql, useLazyLoadQuery } from "@nova-facade/react-graphql";
|
|
16
|
+
import { SomeReactComponent, fragment as SomeReactComponent_someGraphQLType } from "./SomeReactComponent";
|
|
17
|
+
import { SomeRootReactComponentQuery } from "./__generated__/SomeRootReactComponentQuery.graphql";
|
|
18
|
+
|
|
19
|
+
const query = graphql`
|
|
20
|
+
query SomeRootReactComponentQuery {
|
|
21
|
+
someGraphQLType {
|
|
22
|
+
...SomeReactComponent_someGraphQLType
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
${SomeReactComponent_someGraphQLType}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
export const SomeRootReactComponent: React.FC = () => {
|
|
29
|
+
const result = useLazyLoadQuery<SomeRootReactComponentQuery>(query);
|
|
30
|
+
if (result.error) {
|
|
31
|
+
throw result.error;
|
|
32
|
+
} else if (!result.data) {
|
|
33
|
+
// Loading
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<SomeReactComponent someGraphQLType={result.data.someGraphQLType} />
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
*
|
|
43
|
+
* @param query The query operation to perform.
|
|
44
|
+
* @param variables Object containing the variable values to fetch the query. These variables need to match GraphQL
|
|
45
|
+
* variables declared inside the query.
|
|
46
|
+
* @param options Options passed on to the underlying implementation.
|
|
47
|
+
* @returns An object with either an error, the result data, or neither while loading.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useLazyLoadQuery<TQuery extends OperationType>(query: GraphQLTaggedNode, variables: TQuery["variables"], options?: {
|
|
50
|
+
fetchPolicy: "cache-first";
|
|
51
|
+
}): {
|
|
52
|
+
error?: Error;
|
|
53
|
+
data?: TQuery["response"];
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A first-class way for an individual component to express its direct data requirements using GraphQL. The fragment
|
|
57
|
+
* should select all the fields that the component directly uses in its rendering or needs to pass to external
|
|
58
|
+
* functions. It should *not* select data that its children need, unless those children are intended to remain their
|
|
59
|
+
* pure React props as data inputs.
|
|
60
|
+
*
|
|
61
|
+
* For children that *do* have their own data requirements expressed using GraphQL, the fragment should ensure to
|
|
62
|
+
* spread in the child's fragment.
|
|
63
|
+
*
|
|
64
|
+
* For each fragment defined using the `graphql` tagged template function, the Nova graphql-compiler will emit
|
|
65
|
+
* TypeScript typings that correspond to the selected fields and referenced child component fragments. These typings
|
|
66
|
+
* live in files in the sibling `./__generated__/` directory and are called after the fragment name. The compiler will
|
|
67
|
+
* enforce some constraints about the fragment name, such that it starts with the name of the file it is defined in
|
|
68
|
+
* (i.e. the name of the component) and ends with the name of the fragment reference prop that this component takes in
|
|
69
|
+
* (which typically will be named after the GraphQL type that the fragment is defined on).
|
|
70
|
+
*
|
|
71
|
+
* The typing that has a `$key` suffix is meant to be used for the opaque fragment reference prop, whereas the typing
|
|
72
|
+
* without a suffix describes the actual data and is only meant for usage internally to the file. When the opaque
|
|
73
|
+
* fragment reference prop is passed to a `useFragment` call, the returned data will be unmasked and be typed according
|
|
74
|
+
* to the typing without a suffix. As such, the unmasked typing is only ever needed when extracting pieces of the
|
|
75
|
+
* component to the file scope. For functions extracted to different files, however, you should type those separately
|
|
76
|
+
* and *not* use the emitted typings.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
```typescript
|
|
80
|
+
import { graphql, useFragment } from "@nova-facade/react-graphql";
|
|
81
|
+
import { SomeChildReactComponent, fragment as SomeChildReactComponent_someGraphQLType } from "./SomeChildReactComponent";
|
|
82
|
+
import { SomeReactComponent_someGraphQLType$key } from "./__generated__/SomeReactComponent_someGraphQLType.graphql";
|
|
83
|
+
|
|
84
|
+
export const fragment = graphql`
|
|
85
|
+
fragment SomeReactComponent_someGraphQLType on SomeGraphQLType {
|
|
86
|
+
someDataThatThisComponentNeeds
|
|
87
|
+
...SomeChildReactComponent_someGraphQLType
|
|
88
|
+
}
|
|
89
|
+
${SomeChildReactComponent_someGraphQLType}
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
export interface SomeReactComponentProps {
|
|
93
|
+
someGraphQLType: SomeReactComponent_someGraphQLType$key;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const SomeReactComponent: React.FunctionComponent<SomeReactComponentProps> = props => {
|
|
97
|
+
const someGraphQLType = useFragment(fragment, props.someGraphQLType);
|
|
98
|
+
return (
|
|
99
|
+
<div>
|
|
100
|
+
<span>{someGraphQLType.someDataThatThisComponentNeeds}</span>
|
|
101
|
+
<SomeChildReactComponent someGraphQLType={someGraphQLType} />
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
*
|
|
107
|
+
* @note For now, the fragment objects should be exported such that parent's can interpolate them into their own
|
|
108
|
+
* GraphQL documents. This may change in the future when/if we entirely switch to static compilation and will
|
|
109
|
+
* allow us to also move the usage of the graphql tagged template function inline at the `useFragment` call-site.
|
|
110
|
+
*
|
|
111
|
+
* @todo 1613321: Connect useFragment hooks directly to a GraphQL client store for targeted updates. Currently the data
|
|
112
|
+
* is simply unmasked at compile-time but otherwise passed through from the parent at run-time.
|
|
113
|
+
*
|
|
114
|
+
* @param _fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.
|
|
115
|
+
* @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's
|
|
116
|
+
* fragment.
|
|
117
|
+
* @returns The data corresponding to the field selections.
|
|
118
|
+
*/
|
|
119
|
+
export declare function useFragment<TKey extends KeyType>(_fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): KeyTypeData<TKey>;
|
|
120
|
+
interface GraphQLSubscriptionConfig<TSubscriptionPayload extends OperationType> {
|
|
121
|
+
subscription: GraphQLTaggedNode;
|
|
122
|
+
variables: TSubscriptionPayload["variables"];
|
|
123
|
+
/**
|
|
124
|
+
* Should response be nullable?
|
|
125
|
+
*/
|
|
126
|
+
onNext?: (response: TSubscriptionPayload["response"]) => void;
|
|
127
|
+
onError?: (error: Error) => void;
|
|
128
|
+
}
|
|
129
|
+
export declare function useSubscription<TSubscriptionPayload extends OperationType>(config: GraphQLSubscriptionConfig<TSubscriptionPayload>): void;
|
|
130
|
+
interface IMutationCommitterOptions<TMutationPayload extends OperationType> {
|
|
131
|
+
variables: TMutationPayload["variables"];
|
|
132
|
+
optimisticResponse?: Partial<TMutationPayload["response"]> | null;
|
|
133
|
+
}
|
|
134
|
+
declare type MutationCommiter<TMutationPayload extends OperationType> = (options: IMutationCommitterOptions<TMutationPayload>) => Promise<{
|
|
135
|
+
errors?: Error[];
|
|
136
|
+
data?: TMutationPayload["response"];
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* Declare use of a mutation within component. Returns an array of a function and loading state boolean.
|
|
140
|
+
*
|
|
141
|
+
* Returned function can be called to perform the actual mutation with provided variables.
|
|
142
|
+
*
|
|
143
|
+
* @param mutation Mutation document
|
|
144
|
+
* @returns [commitMutationFn, isInFlight]
|
|
145
|
+
*
|
|
146
|
+
* commitMutationFn
|
|
147
|
+
* @param options.variables map of variables to pass to mutation
|
|
148
|
+
* @param options.optimisticResponse proposed response to apply to the store while mutation is in flight
|
|
149
|
+
* @returns A Promise to an object with either errors or/and the result data
|
|
150
|
+
*
|
|
151
|
+
* Example
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
const mutation = graphql`
|
|
155
|
+
mutation SomeReactComponentMutation($newName: String!) {
|
|
156
|
+
someMutation(newName: $newName) {
|
|
157
|
+
__typeName
|
|
158
|
+
id
|
|
159
|
+
newName
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
`
|
|
163
|
+
|
|
164
|
+
export const SomeReactComponent: React.FunctionComponent<SomeReactComponentProps> = props => {
|
|
165
|
+
const [commitMutation, isInFlight] = useMutation(mutation);
|
|
166
|
+
return (
|
|
167
|
+
<div>
|
|
168
|
+
<button onClick={() => commitMutation({
|
|
169
|
+
variables: {
|
|
170
|
+
newName: "foo"
|
|
171
|
+
},
|
|
172
|
+
optimisticResponse: {
|
|
173
|
+
someMutation: {
|
|
174
|
+
__typename: "SomeMutationPayload",
|
|
175
|
+
id: "1",
|
|
176
|
+
newName: "foo",
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
})} disabled={isInFlight}/>
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
*/
|
|
185
|
+
export declare function useMutation<TMutationPayload extends OperationType>(mutation: GraphQLTaggedNode): [MutationCommiter<TMutationPayload>, boolean];
|
|
186
|
+
export {};
|
|
187
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAa,MAAM,SAAS,CAAC;AAEzE,oBAAY,iBAAiB,GAAG,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,SAAS,aAAa,EAC3D,KAAK,EAAE,iBAAiB,EACxB,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE;IAAE,WAAW,EAAE,aAAa,CAAA;CAAE,GACvC;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;CAAE,CAE9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,OAAO,EAC9C,cAAc,EAAE,iBAAiB,EACjC,WAAW,EAAE,IAAI,GAChB,WAAW,CAAC,IAAI,CAAC,CAEnB;AAGD,UAAU,yBAAyB,CACjC,oBAAoB,SAAS,aAAa;IAE1C,YAAY,EAAE,iBAAiB,CAAC;IAChC,SAAS,EAAE,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAC7C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,eAAe,CAAC,oBAAoB,SAAS,aAAa,EACxE,MAAM,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,GACtD,IAAI,CAwBN;AAED,UAAU,yBAAyB,CAAC,gBAAgB,SAAS,aAAa;IACxE,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,kBAAkB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC;CACnE;AAED,aAAK,gBAAgB,CAAC,gBAAgB,SAAS,aAAa,IAAI,CAC9D,OAAO,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,KACjD,OAAO,CAAC;IAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAA;CAAE,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,WAAW,CAAC,gBAAgB,SAAS,aAAa,EAChE,QAAQ,EAAE,iBAAiB,GAC1B,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAuB/C"}
|
package/lib/hooks.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var __async = (__this, __arguments, generator) => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
var fulfilled = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.next(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var rejected = (value) => {
|
|
45
|
+
try {
|
|
46
|
+
step(generator.throw(value));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
52
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var hooks_exports = {};
|
|
56
|
+
__export(hooks_exports, {
|
|
57
|
+
useFragment: () => useFragment,
|
|
58
|
+
useLazyLoadQuery: () => useLazyLoadQuery,
|
|
59
|
+
useMutation: () => useMutation,
|
|
60
|
+
useSubscription: () => useSubscription
|
|
61
|
+
});
|
|
62
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
63
|
+
var import_invariant = __toESM(require("invariant"));
|
|
64
|
+
var import_client = require("@apollo/client");
|
|
65
|
+
function useLazyLoadQuery(query, variables, options) {
|
|
66
|
+
return (0, import_client.useQuery)(query, __spreadValues({ variables }, options));
|
|
67
|
+
}
|
|
68
|
+
function useFragment(_fragmentInput, fragmentRef) {
|
|
69
|
+
return fragmentRef;
|
|
70
|
+
}
|
|
71
|
+
function useSubscription(config) {
|
|
72
|
+
const { error } = (0, import_client.useSubscription)(config.subscription, {
|
|
73
|
+
variables: config.variables,
|
|
74
|
+
onSubscriptionData: ({ subscriptionData }) => {
|
|
75
|
+
(0, import_invariant.default)(!subscriptionData.error, "Did not expect to receive an error here");
|
|
76
|
+
if (subscriptionData.data && config.onNext) {
|
|
77
|
+
config.onNext(subscriptionData.data);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (error) {
|
|
82
|
+
if (config.onError) {
|
|
83
|
+
config.onError(error);
|
|
84
|
+
} else {
|
|
85
|
+
console.warn(`An unhandled GraphQL subscription error occurred: ${error.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function useMutation(mutation) {
|
|
90
|
+
const [apolloUpdater, { loading: mutationLoading }] = (0, import_client.useMutation)(mutation);
|
|
91
|
+
return [
|
|
92
|
+
(options) => __async(this, null, function* () {
|
|
93
|
+
const apolloResult = yield apolloUpdater({
|
|
94
|
+
variables: options.variables || {},
|
|
95
|
+
optimisticResponse: options.optimisticResponse
|
|
96
|
+
});
|
|
97
|
+
if (apolloResult.errors) {
|
|
98
|
+
return {
|
|
99
|
+
errors: Array.from(Object.values(apolloResult.errors)),
|
|
100
|
+
data: apolloResult.data
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
data: apolloResult.data
|
|
105
|
+
};
|
|
106
|
+
}),
|
|
107
|
+
mutationLoading
|
|
108
|
+
];
|
|
109
|
+
}
|
package/lib/hooks.mjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/hooks.ts
|
|
39
|
+
import invariant from "invariant";
|
|
40
|
+
import {
|
|
41
|
+
useSubscription as useApolloSubscription,
|
|
42
|
+
useQuery as useApolloQuery,
|
|
43
|
+
useMutation as useApolloMutation
|
|
44
|
+
} from "@apollo/client";
|
|
45
|
+
function useLazyLoadQuery(query, variables, options) {
|
|
46
|
+
return useApolloQuery(query, __spreadValues({ variables }, options));
|
|
47
|
+
}
|
|
48
|
+
function useFragment(_fragmentInput, fragmentRef) {
|
|
49
|
+
return fragmentRef;
|
|
50
|
+
}
|
|
51
|
+
function useSubscription(config) {
|
|
52
|
+
const { error } = useApolloSubscription(config.subscription, {
|
|
53
|
+
variables: config.variables,
|
|
54
|
+
onSubscriptionData: ({ subscriptionData }) => {
|
|
55
|
+
invariant(!subscriptionData.error, "Did not expect to receive an error here");
|
|
56
|
+
if (subscriptionData.data && config.onNext) {
|
|
57
|
+
config.onNext(subscriptionData.data);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (error) {
|
|
62
|
+
if (config.onError) {
|
|
63
|
+
config.onError(error);
|
|
64
|
+
} else {
|
|
65
|
+
console.warn(`An unhandled GraphQL subscription error occurred: ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function useMutation(mutation) {
|
|
70
|
+
const [apolloUpdater, { loading: mutationLoading }] = useApolloMutation(mutation);
|
|
71
|
+
return [
|
|
72
|
+
(options) => __async(this, null, function* () {
|
|
73
|
+
const apolloResult = yield apolloUpdater({
|
|
74
|
+
variables: options.variables || {},
|
|
75
|
+
optimisticResponse: options.optimisticResponse
|
|
76
|
+
});
|
|
77
|
+
if (apolloResult.errors) {
|
|
78
|
+
return {
|
|
79
|
+
errors: Array.from(Object.values(apolloResult.errors)),
|
|
80
|
+
data: apolloResult.data
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
data: apolloResult.data
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
mutationLoading
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
useFragment,
|
|
92
|
+
useLazyLoadQuery,
|
|
93
|
+
useMutation,
|
|
94
|
+
useSubscription
|
|
95
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./hooks"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./types"), module.exports);
|
package/lib/index.mjs
ADDED
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Variables {
|
|
2
|
+
[name: string]: any;
|
|
3
|
+
}
|
|
4
|
+
export interface OperationType {
|
|
5
|
+
readonly variables: Variables;
|
|
6
|
+
readonly response: unknown;
|
|
7
|
+
readonly rawResponse?: unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* relay-compiler-language-typescript support for fragment references
|
|
11
|
+
*/
|
|
12
|
+
export interface _RefType<Ref extends string> {
|
|
13
|
+
" $refType": Ref;
|
|
14
|
+
}
|
|
15
|
+
export interface _FragmentRefs<Refs extends string> {
|
|
16
|
+
" $fragmentRefs": FragmentRefs<Refs>;
|
|
17
|
+
}
|
|
18
|
+
export declare type FragmentRefs<Refs extends string> = {
|
|
19
|
+
[ref in Refs]: true;
|
|
20
|
+
};
|
|
21
|
+
export declare type FragmentRef<Fragment> = Fragment extends _RefType<infer U> ? _FragmentRefs<U> : never;
|
|
22
|
+
/**
|
|
23
|
+
* react-relay DT
|
|
24
|
+
*/
|
|
25
|
+
export declare type FragmentReference = unknown;
|
|
26
|
+
export declare type KeyType<TData = unknown> = Readonly<{
|
|
27
|
+
" $data"?: TData;
|
|
28
|
+
" $fragmentRefs": FragmentReference;
|
|
29
|
+
}>;
|
|
30
|
+
export declare type KeyTypeData<TKey extends KeyType<TData>, TData = unknown> = Required<TKey>[" $data"];
|
|
31
|
+
export declare type ArrayKeyType<TData = unknown> = ReadonlyArray<KeyType<ReadonlyArray<TData>> | null>;
|
|
32
|
+
export declare type ArrayKeyTypeData<TKey extends ArrayKeyType<TData>, TData = unknown> = KeyTypeData<NonNullable<TKey[number]>>;
|
|
33
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AAEH,MAAM,WAAW,QAAQ,CAAC,GAAG,SAAS,MAAM;IAC1C,WAAW,EAAE,GAAG,CAAC;CAClB;AAED,MAAM,WAAW,aAAa,CAAC,IAAI,SAAS,MAAM;IAChD,gBAAgB,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;CACtC;AAGD,oBAAY,YAAY,CAAC,IAAI,SAAS,MAAM,IAAI;KAC7C,GAAG,IAAI,IAAI,GAAG,IAAI;CACpB,CAAC;AAGF,oBAAY,WAAW,CAAC,QAAQ,IAAI,QAAQ,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GAClE,aAAa,CAAC,CAAC,CAAC,GAChB,KAAK,CAAC;AAEV;;GAEG;AAEH,oBAAY,iBAAiB,GAAG,OAAO,CAAC;AAExC,oBAAY,OAAO,CAAC,KAAK,GAAG,OAAO,IAAI,QAAQ,CAAC;IAC9C,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,gBAAgB,EAAE,iBAAiB,CAAC;CACrC,CAAC,CAAC;AAEH,oBAAY,WAAW,CACrB,IAAI,SAAS,OAAO,CAAC,KAAK,CAAC,EAC3B,KAAK,GAAG,OAAO,IACb,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;AAE7B,oBAAY,YAAY,CAAC,KAAK,GAAG,OAAO,IAAI,aAAa,CAAC,OAAO,CAC/D,aAAa,CAAC,KAAK,CAAC,CACrB,GAAG,IAAI,CAAC,CAAC;AACV,oBAAY,gBAAgB,CAC1B,IAAI,SAAS,YAAY,CAAC,KAAK,CAAC,EAChC,KAAK,GAAG,OAAO,IACb,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC"}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
package/lib/types.mjs
ADDED
|
File without changes
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphitation/apollo-react-relay-duct-tape",
|
|
3
3
|
"description": "A compatibility wrapper that provides the react-relay API on top of Apollo Client.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.12",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/microsoft/graphitation.git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@apollo/client": "^3.3.15",
|
|
22
|
-
"@graphitation/apollo-mock-client": "^0.10.
|
|
23
|
-
"@graphitation/graphql-js-operation-payload-generator": "^0.10.
|
|
22
|
+
"@graphitation/apollo-mock-client": "^0.10.10",
|
|
23
|
+
"@graphitation/graphql-js-operation-payload-generator": "^0.10.3",
|
|
24
24
|
"@graphitation/graphql-js-tag": "^0.9.0",
|
|
25
25
|
"@types/jest": "^26.0.22",
|
|
26
26
|
"@types/react": "^17.0.3",
|