├── .npmignore ├── .gitignore ├── packages ├── react-relay-auth-iam │ ├── .gitignore │ ├── .npmignore │ ├── src │ │ ├── index.ts │ │ ├── middleware-auth-iam.ts │ │ └── signer.ts │ ├── tsconfig.json │ ├── README.md │ ├── package.json │ ├── LICENSE │ └── yarn.lock └── react-relay-upload-s3 │ ├── .gitignore │ ├── .npmignore │ ├── src │ ├── index.ts │ └── middleware-upload-s3.ts │ ├── tsconfig.json │ ├── package.json │ ├── LICENSE │ ├── README.md │ └── package-lock.json ├── website ├── .gitignore ├── static │ ├── img │ │ ├── favicon.ico │ │ ├── oss_logo.png │ │ ├── undraw_tweetstorm.svg │ │ ├── undraw_note_list.svg │ │ ├── undraw_open_source.svg │ │ ├── undraw_code_review.svg │ │ ├── undraw_react.svg │ │ ├── undraw_online.svg │ │ ├── undraw_youtube_tutorial.svg │ │ └── undraw_monitor.svg │ ├── css │ │ └── custom.css │ └── index.html ├── sidebars.json ├── package.json ├── i18n │ └── en.json ├── siteConfig.js └── core │ └── Footer.js ├── docs ├── RelayAppsync-Introduction.md ├── RelayAppsync-AuthIam.md └── RelayAppsync-UploadS3.md ├── README.md └── LICENSE /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | *.tgz 3 | tsconfig.json 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | *.tgz 4 | .DS_STORE -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | *.tgz 4 | -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | *.tgz 3 | tsconfig.json 4 | -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | *.tgz 4 | -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | *.tgz 3 | tsconfig.json 4 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | *.tgz 4 | lerna-debug.log 5 | .npmrc 6 | build -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/src/index.ts: -------------------------------------------------------------------------------- 1 | export {default as authIAMMiddleware} from "./middleware-auth-iam"; 2 | -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/src/index.ts: -------------------------------------------------------------------------------- 1 | export {default as uploadS3Middleware} from "./middleware-upload-s3"; 2 | -------------------------------------------------------------------------------- /website/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/morrys/react-relay-appsync/HEAD/website/static/img/favicon.ico -------------------------------------------------------------------------------- /website/static/img/oss_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/morrys/react-relay-appsync/HEAD/website/static/img/oss_logo.png -------------------------------------------------------------------------------- /website/sidebars.json: -------------------------------------------------------------------------------- 1 | { 2 | "docs": { 3 | "React Relay AppSync": [ 4 | "react-relay-appsync" 5 | ], 6 | "React Relay Auth IAM": [ 7 | "react-relay-auth-iam" 8 | ], 9 | "React Relay Upload S3": [ 10 | "react-relay-upload-s3" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "repository": "morrys/react-relay-appsync", 3 | "license": "MIT", 4 | "private": true, 5 | "scripts": { 6 | "start": "docusaurus-start", 7 | "build": "docusaurus-build", 8 | "docpub": "docusaurus-publish" 9 | }, 10 | "dependencies": { 11 | "docusaurus": "1.12.0" 12 | } 13 | } -------------------------------------------------------------------------------- /website/static/css/custom.css: -------------------------------------------------------------------------------- 1 | /* your custom css */ 2 | 3 | @media only screen and (min-device-width: 360px) and (max-device-width: 736px) { 4 | } 5 | 6 | @media only screen and (min-width: 1024px) { 7 | } 8 | 9 | @media only screen and (max-width: 1023px) { 10 | } 11 | 12 | @media only screen and (min-width: 1400px) { 13 | } 14 | 15 | @media only screen and (min-width: 1500px) { 16 | } -------------------------------------------------------------------------------- /docs/RelayAppsync-Introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: react-relay-appsync 3 | title: Getting Started 4 | --- 5 | 6 | AppSync for Relay 7 | 8 | ## Offline capabilities 9 | 10 | [React Relay Offline](https://morrys.github.io/react-relay-offline/docs/react-relay-offline) 11 | 12 | 13 | ## TODO 14 | 15 | Document how to use urlMiddleware and authMiddleware in the context of AWS 16 | 17 | Implementation of Delta Sync -------------------------------------------------------------------------------- /website/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | Your Site Title Here 10 | 11 | 12 | If you are not redirected automatically, follow this link. 13 | 14 | -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "lib", 4 | "rootDir": "src", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "moduleResolution": "node", 8 | "noEmitOnError": true, 9 | "declaration": true, 10 | "lib": [ 11 | "dom", 12 | "es6", 13 | "esnext.asynciterable", 14 | "es2017.object" 15 | ], 16 | "jsx": "react", 17 | "skipLibCheck": true 18 | }, 19 | "exclude": [ 20 | "lib", 21 | "__tests__" 22 | ], 23 | "compileOnSave": true 24 | } -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "lib", 4 | "rootDir": "src", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "moduleResolution": "node", 8 | "noEmitOnError": true, 9 | "declaration": true, 10 | "lib": [ 11 | "dom", 12 | "es6", 13 | "esnext.asynciterable", 14 | "es2017.object" 15 | ], 16 | "jsx": "react", 17 | "skipLibCheck": true 18 | }, 19 | "exclude": [ 20 | "lib", 21 | "__tests__" 22 | ], 23 | "compileOnSave": true 24 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [React Relay AppSync](https://github.com/morrys/react-relay-upload-s3) 2 | AppSync for Relay 3 | 4 | ## Offline capabilities 5 | 6 | [React Relay Offline](https://github.com/morrys/react-relay-offline#readme) 7 | 8 | ## Usage React Relay Upload S3 9 | 10 | [See README.md](./packages/react-relay-upload-s3/README.md) 11 | 12 | ## Usage React Relay Authentication AWS IAM 13 | 14 | [See README.md](./packages/react-relay-auth-iam/README.md) 15 | 16 | ## TODO 17 | 18 | Document how to use urlMiddleware and authMiddleware in the context of AWS 19 | 20 | Implementation of Delta Sync 21 | 22 | 23 | ## License 24 | 25 | React Relay AppSync is [MIT licensed](./LICENSE). 26 | 27 | -------------------------------------------------------------------------------- /docs/RelayAppsync-AuthIam.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: react-relay-auth-iam 3 | title: React Relay Auth IAM 4 | --- 5 | 6 | # [React Relay Authentication AWS IAM](https://github.com/morrys/react-relay-appsync) 7 | Middleware for Relay Modern Network Layer for authentication to AWS IAM 8 | 9 | ## Installation 10 | 11 | Install react-relay-auth-iam using yarn or npm: 12 | 13 | ``` 14 | yarn add react-relay-auth-iam 15 | ``` 16 | 17 | ## Usage 18 | 19 | How to create the RelayNetworkLayer 20 | 21 | ```typescript 22 | import {authIAMMiddleware} from 'react-relay-auth-iam'; 23 | ``` 24 | 25 | ```typescript 26 | const network = new RelayNetworkLayer( 27 | [ 28 | urlMiddleware(...), 29 | authIAMMiddleware({credentials: iamCredentials, region: region}), 30 | ], 31 | {} 32 | ); 33 | ``` -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/README.md: -------------------------------------------------------------------------------- 1 | # [React Relay Authentication AWS IAM](https://github.com/morrys/react-relay-appsync) 2 | Middleware for Relay Modern Network Layer for authentication to AWS IAM 3 | 4 | ## Installation 5 | 6 | Install react-relay-auth-iam using yarn or npm: 7 | 8 | ``` 9 | yarn add react-relay-auth-iam 10 | ``` 11 | 12 | ## Usage 13 | 14 | How to create the RelayNetworkLayer 15 | 16 | ```typescript 17 | import {authIAMMiddleware} from 'react-relay-auth-iam'; 18 | ``` 19 | 20 | ```typescript 21 | const network = new RelayNetworkLayer( 22 | [ 23 | urlMiddleware(...), 24 | authIAMMiddleware({credentials: iamCredentials, region: region}), 25 | ], 26 | {} 27 | ); 28 | ``` 29 | 30 | ## License 31 | 32 | React Relay Authentication AWS IAM is [MIT licensed](./LICENSE). 33 | 34 | -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-relay-upload-s3", 3 | "version": "0.0.2", 4 | "keywords": [ 5 | "graphql", 6 | "relay", 7 | "upload", 8 | "react", 9 | "aws", 10 | "appsync", 11 | "s3" 12 | ], 13 | "main": "lib/index.js", 14 | "license": "MIT", 15 | "description": "React Relay Middleware Upload S3", 16 | "author": { 17 | "name": "morrys" 18 | }, 19 | "homepage": "https://github.com/morrys/react-relay-appsync#readme", 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/morrys/react-relay-appsync" 23 | }, 24 | "scripts": { 25 | "prepare": "tsc" 26 | }, 27 | "dependencies": {}, 28 | "peerDependencies": { 29 | "react-relay": ">=1.4.0" 30 | }, 31 | "devDependencies": { 32 | "typescript": "3.1.1", 33 | "aws-sdk": "^2.449.0", 34 | "react-relay-network-modern": "^2.5.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-relay-auth-iam", 3 | "version": "0.0.2", 4 | "keywords": [ 5 | "graphql", 6 | "relay", 7 | "auth", 8 | "react", 9 | "aws", 10 | "appsync", 11 | "iam" 12 | ], 13 | "main": "lib/index.js", 14 | "license": "MIT", 15 | "description": "React Relay Middleware Authentication AWS IAM", 16 | "author": { 17 | "name": "morrys" 18 | }, 19 | "homepage": "https://github.com/morrys/react-relay-appsync#readme", 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/morrys/react-relay-appsync" 23 | }, 24 | "scripts": { 25 | "prepare": "tsc" 26 | }, 27 | "dependencies": { 28 | "url": "^0.11.0" 29 | }, 30 | "peerDependencies": { 31 | "react-relay": ">=1.4.0" 32 | }, 33 | "devDependencies": { 34 | "typescript": "3.1.1", 35 | "@types/node": "^8.10.48", 36 | "aws-sdk": "^2.449.0", 37 | "react-relay-network-modern": "^2.5.1" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Lorenzo Di Giacomo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Lorenzo Di Giacomo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /website/i18n/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "_comment": "This file is auto-generated by write-translations.js", 3 | "localized-strings": { 4 | "next": "Next", 5 | "previous": "Previous", 6 | "tagline": "Collection of libraries usable for the web, react and react-native.", 7 | "docs": { 8 | "react-relay-auth-iam": { 9 | "title": "React Relay Auth IAM" 10 | }, 11 | "react-relay-appsync": { 12 | "title": "Getting Started" 13 | }, 14 | "react-relay-upload-s3": { 15 | "title": "React Relay Upload S3" 16 | } 17 | }, 18 | "links": { 19 | "Docs": "Docs", 20 | "GitHub": "GitHub" 21 | }, 22 | "categories": { 23 | "React Relay AppSync": "React Relay AppSync", 24 | "React Relay Auth IAM": "React Relay Auth IAM", 25 | "React Relay Upload S3": "React Relay Upload S3" 26 | } 27 | }, 28 | "pages-strings": { 29 | "Help Translate|recruit community translators for your project": "Help Translate", 30 | "Edit this Doc|recruitment message asking to edit the doc source": "Edit", 31 | "Translate this Doc|recruitment message asking to translate the docs": "Translate" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Lorenzo Di Giacomo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/RelayAppsync-UploadS3.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: react-relay-upload-s3 3 | title: React Relay Upload S3 4 | --- 5 | 6 | # [React Relay Upload S3](https://github.com/morrys/react-relay-appsync) 7 | Middleware for Relay Modern Network Layer for upload file to AWS S3 8 | 9 | ## Installation 10 | 11 | Install react-relay-upload-s3 using yarn or npm: 12 | 13 | ``` 14 | yarn add react-relay-upload-s3 15 | ``` 16 | 17 | ## Usage 18 | 19 | How to create the RelayNetworkLayer 20 | 21 | ```typescript 22 | import {uploadS3Middleware} from 'react-relay-upload-s3'; 23 | ``` 24 | 25 | ```typescript 26 | const network = new RelayNetworkLayer( 27 | [ 28 | urlMiddleware(...), 29 | uploadS3Middleware({credentials: complexObjectsCredentials}), 30 | authMiddleware(...), 31 | ], 32 | {} 33 | ); 34 | ``` 35 | 36 | How to use in commitMutation 37 | 38 | ```typescript 39 | 40 | //single file 41 | const file:any = { 42 | bucket: bucket, 43 | key: key, 44 | region: region, 45 | file: selectedFile 46 | }; 47 | 48 | commitMutation( 49 | ... 50 | uploadables: { 51 | file 52 | }, 53 | ); 54 | 55 | //multiple files 56 | const file1:any = { 57 | bucket: bucket, 58 | key: key1, 59 | region: region, 60 | file: selectedFile1 61 | }; 62 | 63 | const file2:any = { 64 | bucket: bucket, 65 | key: key2, 66 | region: region, 67 | file: selectedFile2 68 | }; 69 | 70 | commitMutation( 71 | ... 72 | uploadables: { 73 | file1, 74 | file2 75 | }, 76 | ); 77 | ``` 78 | 79 | -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/README.md: -------------------------------------------------------------------------------- 1 | # [React Relay Upload S3](https://github.com/morrys/react-relay-appsync) 2 | Middleware for Relay Modern Network Layer for upload file to AWS S3 3 | 4 | ## Installation 5 | 6 | Install react-relay-upload-s3 using yarn or npm: 7 | 8 | ``` 9 | yarn add react-relay-upload-s3 10 | ``` 11 | 12 | ## Usage 13 | 14 | How to create the RelayNetworkLayer 15 | 16 | ```typescript 17 | import {uploadS3Middleware} from 'react-relay-upload-s3'; 18 | ``` 19 | 20 | ```typescript 21 | const network = new RelayNetworkLayer( 22 | [ 23 | urlMiddleware(...), 24 | uploadS3Middleware({credentials: complexObjectsCredentials}), 25 | authMiddleware(...), 26 | ], 27 | {} 28 | ); 29 | ``` 30 | 31 | How to use in commitMutation 32 | 33 | ```typescript 34 | 35 | //single file 36 | const file:any = { 37 | bucket: bucket, 38 | key: key, 39 | region: region, 40 | file: selectedFile 41 | }; 42 | 43 | commitMutation( 44 | ... 45 | uploadables: { 46 | file 47 | }, 48 | ); 49 | 50 | //multiple files 51 | const file1:any = { 52 | bucket: bucket, 53 | key: key1, 54 | region: region, 55 | file: selectedFile1 56 | }; 57 | 58 | const file2:any = { 59 | bucket: bucket, 60 | key: key2, 61 | region: region, 62 | file: selectedFile2 63 | }; 64 | 65 | commitMutation( 66 | ... 67 | uploadables: { 68 | file1, 69 | file2 70 | }, 71 | ); 72 | ``` 73 | 74 | ## TODO 75 | 76 | Document how to use urlMiddleware and authMiddleware in the context of AWS 77 | 78 | ## License 79 | 80 | React Relay Upload S3 is [MIT licensed](./LICENSE). 81 | 82 | -------------------------------------------------------------------------------- /packages/react-relay-auth-iam/src/middleware-auth-iam.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Middleware, 3 | RelayNetworkLayerRequest 4 | } from "react-relay-network-modern/lib/definition"; 5 | import { Credentials, CredentialsOptions } from "aws-sdk/lib/credentials"; 6 | import { Signer } from "./signer"; 7 | import * as Url from "url"; 8 | const SERVICE = "appsync"; 9 | 10 | type CredentialsGetter = () => 11 | | ( 12 | | Credentials 13 | | CredentialsOptions 14 | | Promise 15 | | Promise 16 | | null 17 | ) 18 | | Credentials 19 | | CredentialsOptions 20 | | Promise 21 | | Promise 22 | | null; 23 | 24 | export type AuthIAMMiddlewareOpts = { 25 | credentials: CredentialsGetter; 26 | region: string; 27 | }; 28 | 29 | export default function authIAMMiddleware( 30 | opts: AuthIAMMiddlewareOpts 31 | ): Middleware { 32 | const { credentials, region } = opts; 33 | return next => async (req: RelayNetworkLayerRequest) => { 34 | const service = SERVICE; 35 | const url = req.fetchOpts.url; 36 | 37 | let creds = 38 | typeof credentials === "function" 39 | ? (credentials as any).call() 40 | : credentials || {}; 41 | 42 | if (creds && typeof creds.getPromise === "function") { 43 | await creds.getPromise(); 44 | } 45 | 46 | const { accessKeyId, secretAccessKey, sessionToken } = await creds; 47 | 48 | const { host, path } = Url.parse(url); 49 | 50 | const formatted = { 51 | ...formatAsRequest(req), 52 | service, 53 | region, 54 | url, 55 | host, 56 | path 57 | }; 58 | 59 | const { headers } = Signer.sign(formatted, { 60 | access_key: accessKeyId, 61 | secret_key: secretAccessKey, 62 | session_token: sessionToken 63 | }); 64 | req.fetchOpts.headers = { 65 | ...req.fetchOpts.headers, 66 | ...headers 67 | }; 68 | return next(req); 69 | }; 70 | } 71 | 72 | // Accept Content-Type 73 | const formatAsRequest = ({ fetchOpts }) => { 74 | return { 75 | body: fetchOpts.body, 76 | method: fetchOpts.method, 77 | headers: { 78 | Accept: "*/*", 79 | "Content-Type": "application/json; charset=UTF-8", 80 | ...fetchOpts.headers 81 | } 82 | }; 83 | }; 84 | -------------------------------------------------------------------------------- /packages/react-relay-upload-s3/src/middleware-upload-s3.ts: -------------------------------------------------------------------------------- 1 | import { Middleware, RelayNetworkLayerRequest } from 'react-relay-network-modern/lib/definition'; 2 | import { Credentials, CredentialsOptions } from 'aws-sdk/lib/credentials'; 3 | import * as S3 from 'aws-sdk/clients/s3'; 4 | 5 | type CredentialsGetter = () => (Credentials | CredentialsOptions | Promise | Promise | null) | Credentials | CredentialsOptions | Promise | Promise | null; 6 | 7 | export type UploadS3MiddlewareOpts = { 8 | credentials: CredentialsGetter 9 | }; 10 | 11 | export interface FileS3Type { 12 | bucket: string 13 | key: string 14 | region: string 15 | file: File | Blob 16 | } 17 | 18 | export interface UploadableS3 { 19 | [key: string]: FileS3Type; 20 | } 21 | 22 | function upload(fileField: FileS3Type, { credentials }) { 23 | const Body = fileField.file; 24 | const { type: ContentType } = Body; 25 | 26 | const { 27 | bucket: Bucket, 28 | key: Key, 29 | region, 30 | } = fileField; 31 | const s3 = new S3({ 32 | credentials, 33 | region, 34 | }); 35 | 36 | return s3.upload({ 37 | Bucket, 38 | Key, 39 | Body, 40 | ContentType, 41 | }).promise(); 42 | }; 43 | 44 | export default function uploadS3Middleware(opts: UploadS3MiddlewareOpts): Middleware { 45 | const { 46 | credentials, 47 | } = opts; 48 | return (next) => async (req: RelayNetworkLayerRequest) => { 49 | const uploadables: UploadableS3 = req.uploadables; 50 | if (uploadables) { 51 | const uploadCredentials = typeof credentials === 'function' ? (credentials as any).call() : credentials; 52 | const uploadPromise = Promise.resolve(uploadCredentials) 53 | .then(credentials => { 54 | const uploadPromises = Object.entries(uploadables).map(([_, fileUpload]) => upload(fileUpload, { credentials })); 55 | return Promise.all([...uploadPromises] as Promise[]); 56 | }).then(() => { 57 | delete req.uploadables; 58 | req.fetchOpts.body = req.prepareBody(); 59 | return next(req) 60 | }) 61 | return uploadPromise; 62 | } else { 63 | return next(req) 64 | } 65 | }; 66 | } -------------------------------------------------------------------------------- /website/siteConfig.js: -------------------------------------------------------------------------------- 1 | const siteConfig = { 2 | title: 'Morrys Repositories', 3 | tagline: 'Collection of libraries usable for the web, react and react-native.', 4 | url: 'https://morrys.github.io', 5 | baseUrl: '/react-relay-appsync/', 6 | projectName: 'react-relay-appsync', 7 | organizationName: 'morrys', 8 | headerLinks: [ 9 | { doc: 'react-relay-appsync', label: 'Docs' }, 10 | { 11 | href: 'https://github.com/morrys/react-relay-appsync', 12 | label: 'GitHub', 13 | }, 14 | { languages: false }, 15 | ], 16 | 17 | /* path to images for header/footer */ 18 | headerIcon: 'img/favicon.ico', 19 | footerIcon: 'img/favicon.ico', 20 | favicon: 'img/favicon.ico', 21 | colors: { 22 | primaryColor: '#008ed8', 23 | secondaryColor: '#17afff', 24 | }, 25 | 26 | /* Custom fonts for website */ 27 | /* 28 | fonts: { 29 | myFont: [ 30 | "Times New Roman", 31 | "Serif" 32 | ], 33 | myOtherFont: [ 34 | "-apple-system", 35 | "system-ui" 36 | ] 37 | }, 38 | */ 39 | 40 | // This copyright info is used in /core/Footer.js and blog RSS/Atom feeds. 41 | copyright: `Copyright © ${new Date().getFullYear()} Lorenzo Di Giacomo`, 42 | 43 | highlight: { 44 | // Highlight.js theme to use for syntax highlighting in code blocks. 45 | theme: 'default', 46 | }, 47 | 48 | // Add custom scripts here that would be placed in