Skip to content

Instantly share code, notes, and snippets.

View dabit3's full-sized avatar
🎡
probably nothing

Nader Dabit dabit3

🎡
probably nothing
View GitHub Profile
@dabit3
dabit3 / queries.graphql
Created October 11, 2019 16:27
Miscellaneious GraphQL queries for demo
mutation createCategory {
__typename
createCategory(input: {name: "shoes"}) {
id
name
}
}
mutation createProduct {
__typename
@dabit3
dabit3 / index.js
Last active October 11, 2019 17:44
Basic example of Lambda function that accepts both GraphQL & API gateway requests
exports.handler = function (event, context) { //eslint-disable-line
const taxTable = {
NY: 8.49, CA: 8.56, OK: 8.92, FL: 7.05,
IL: 8.74, PA: 6.34, WA: 9.17, TX: 8.19
}
let price
let taxRate
if (event.arguments) {
// graphql request
@dabit3
dabit3 / schema.graphql
Last active October 11, 2019 19:59
E Commerce Schema with function resolver
type Category @model
@auth(rules: [
{ allow: groups, groups: ["Admin"], operations: [create, update, delete] },
{ allow: private, operations: [read] }
])
{
id: ID!
name: String!
products: [Product] @connection
}
@dabit3
dabit3 / App.js
Created October 11, 2019 16:11
Basic template for image uploads in Amplify with React for demo
import React, { useState } from 'react';
import './App.css';
import { withAuthenticator } from 'aws-amplify-react'
import { Storage } from 'aws-amplify'
function App() {
const [image, updateImage] = useState({key: null, signedUrl: null})
async function getImage() {
@dabit3
dabit3 / policy.json
Created October 3, 2019 09:08
Se bucket policy for public images
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::gqlimages6c6fev-dev/public/images/thumbnails/*"
}
]
@dabit3
dabit3 / appsync.md
Created September 26, 2019 13:36
Examples of dynamic authorization with GraphQL Transform

Using the following schema:

type Post @model
@auth(rules: [{allow: groups, groupsField: "groups"}]) {
  id: ID!
  title: String
  groups: [String]
}
readFile = async (filePath) => {
return new Promise((res, reject) => {
var request = new XMLHttpRequest();
request.open("GET", filePath, true);
request.responseType = "arraybuffer";
request.onload = _event => { res(request.response) }
request.onerror = err => { reject(err); };
request.send(null);
});
}
@dabit3
dabit3 / Amplify-Modularization.md
Created September 9, 2019 18:37
Amplify-Modularization

Usage

First install the modular import you would like to use:

npm install @aws-amplify/auth

When using modular imports, import a library module:

@dabit3
dabit3 / Local-Development.md
Last active September 9, 2019 18:36
Local-Development

Other tips

After cloning & running yarn bootstrap / yarn build of the whole package, the best way to develop locally is to link the individual package you’re working on and run lerna in watch mode.

For example if you clone Amplify and you want to make some changes for a PR, you’ll have a sample project and then link it:

# Run watch mode while editing (auth for example):
npx lerna exec --scope @aws-amplify/auth yarn link
npx lerna exec --scope @aws-amplify/auth tsc -- --watch
@dabit3
dabit3 / files.js
Last active September 10, 2019 21:30
Various changes to fix Predictions category for AWS Amplify React Native
// Utils.js
// new util for RN File Source
export async function fileToRNArrayBuffer(uri) {
return new Promise((res, reject) => {
var request = new XMLHttpRequest();
request.open("GET", uri, true);
request.responseType = "arraybuffer";
request.onload = _event => { res(request.response) }
request.onerror = err => { reject(err); };
request.send(null);