@ttoss/relay-amplify 0.2.0
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/dist/esm/index.js +33 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +53 -0
- package/package.json +35 -0
- package/src/index.ts +29 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { API, graphqlOperation } from "aws-amplify";
|
|
5
|
+
import {
|
|
6
|
+
Environment,
|
|
7
|
+
Network,
|
|
8
|
+
RecordSource,
|
|
9
|
+
Store
|
|
10
|
+
} from "relay-runtime";
|
|
11
|
+
var fetchQuery = async (operation, variables) => {
|
|
12
|
+
try {
|
|
13
|
+
const response = await API.graphql(
|
|
14
|
+
graphqlOperation(operation.text, variables)
|
|
15
|
+
);
|
|
16
|
+
return response;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error.errors && error.errors.length > 0) {
|
|
19
|
+
throw error.errors[0];
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var createEnvironment = ({ storeOptions }) => {
|
|
25
|
+
return new Environment({
|
|
26
|
+
network: Network.create(fetchQuery),
|
|
27
|
+
store: new Store(new RecordSource(), storeOptions)
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
createEnvironment,
|
|
32
|
+
fetchQuery
|
|
33
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
createEnvironment: () => createEnvironment,
|
|
25
|
+
fetchQuery: () => fetchQuery
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_aws_amplify = require("aws-amplify");
|
|
29
|
+
var import_relay_runtime = require("relay-runtime");
|
|
30
|
+
var fetchQuery = async (operation, variables) => {
|
|
31
|
+
try {
|
|
32
|
+
const response = await import_aws_amplify.API.graphql(
|
|
33
|
+
(0, import_aws_amplify.graphqlOperation)(operation.text, variables)
|
|
34
|
+
);
|
|
35
|
+
return response;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error.errors && error.errors.length > 0) {
|
|
38
|
+
throw error.errors[0];
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var createEnvironment = ({ storeOptions }) => {
|
|
44
|
+
return new import_relay_runtime.Environment({
|
|
45
|
+
network: import_relay_runtime.Network.create(fetchQuery),
|
|
46
|
+
store: new import_relay_runtime.Store(new import_relay_runtime.RecordSource(), storeOptions)
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
createEnvironment,
|
|
52
|
+
fetchQuery
|
|
53
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ttoss/relay-amplify",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"author": "ttoss",
|
|
7
|
+
"contributors": [
|
|
8
|
+
"Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"
|
|
9
|
+
],
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"module": "dist/esm/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"src"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"test": "jest"
|
|
19
|
+
},
|
|
20
|
+
"typings": "dist/index.d.ts",
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"aws-amplify": "^5.0.7",
|
|
23
|
+
"relay-runtime": "^14.1.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@ttoss/config": "^1.26.0",
|
|
27
|
+
"aws-amplify": "^5.0.7",
|
|
28
|
+
"relay-runtime": "^14.1.0"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "98cf227311c2f28ab73520c793bfe0bf0df27530"
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { API, graphqlOperation } from 'aws-amplify';
|
|
2
|
+
import {
|
|
3
|
+
Environment,
|
|
4
|
+
FetchFunction,
|
|
5
|
+
Network,
|
|
6
|
+
RecordSource,
|
|
7
|
+
Store,
|
|
8
|
+
} from 'relay-runtime';
|
|
9
|
+
|
|
10
|
+
export const fetchQuery: FetchFunction = async (operation, variables) => {
|
|
11
|
+
try {
|
|
12
|
+
const response = await API.graphql(
|
|
13
|
+
graphqlOperation(operation.text, variables)
|
|
14
|
+
);
|
|
15
|
+
return response as any;
|
|
16
|
+
} catch (error: any) {
|
|
17
|
+
if (error.errors && error.errors.length > 0) {
|
|
18
|
+
throw error.errors[0];
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const createEnvironment = ({ storeOptions }: { storeOptions?: any }) => {
|
|
25
|
+
return new Environment({
|
|
26
|
+
network: Network.create(fetchQuery),
|
|
27
|
+
store: new Store(new RecordSource(), storeOptions),
|
|
28
|
+
});
|
|
29
|
+
};
|