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 / schema.graphql
Created June 28, 2020 21:09
Attendee Event Connection
type User @model
@key(name: "byUserIdIndex", fields: ["userId"], queryField: "userById")
@auth(
rules: [
{ allow: owner, ownerField: "userId" }
]) {
id: ID!
userId: ID!
type: String!
events: [EventLink] @connection(keyName: "EventUserIndex", fields: ["userId"])
@dabit3
dabit3 / schema.graphql
Last active May 17, 2020 03:53
Single table idea for Amplify GraphQL Transform
type Base @model("BaseDB") {
id: ID!
}
type Post @db("BaseDB") {
...Base
name: String!
}
type Comment @db("BaseDB") {
@dabit3
dabit3 / schema.graphql
Created May 15, 2020 16:26
Products ordered by date
type Product @model
@key(name: "productSortedIndex", fields: ["baseType", "createdAt"], queryField: "productsSorted") {
id: ID
name: String
price: Float
createdAt: String
baseType: String
}
@dabit3
dabit3 / upvote.vtl
Created May 8, 2020 20:55
DynamoDB update expression in VTL
{
"version": "2018-05-29",
"operation": "UpdateItem",
"key" : {
"id" : $util.dynamodb.toDynamoDBJson($context.arguments.id)
},
"update": {
"expression" : "set #upvotes = #upvotes + :updateValue",
"expressionNames" : {
"#upvotes" : "upvotes"
@dabit3
dabit3 / schema.graphql
Last active May 14, 2020 00:13
Amplify GraphQL Schema with different access patterns
type Product @model
@key(name: "productInventoryAmountIndex", fields: ["baseType", "inventory"], queryField: "productsByInventoryAmount")
@key(name: "productInventoryPriceIndex", fields: ["baseType", "price"], queryField: "productsByPrice")
@key(name: "productNameSearchIndex", fields: ["baseType", "name"], queryField: "productSearchByName")
@key(name: "productCategorySearchIndex", fields: ["baseType", "category"], queryField: "productSearchByCategory")
@key(name: "productCategoryIndex", fields: ["category", "createdAt"], queryField: "productsByCategory")
@key(name: "productByCategoryAndNameIndex", fields: ["category", "name"], queryField: "productsByCategoryAndName")
@key(name: "productByCategoryAndInventoryIndex", fields: ["category", "inventory"], queryField: "productsByCategoryAndInventory")
@key(name: "productByCategoryAndPriceIndex", fields: ["category", "price"], queryField: "productsByCategoryAndPrice")
{
@dabit3
dabit3 / main.js
Created April 14, 2020 23:08
Serverless Lambda API with Python
/* This file contains two files */
/* index.py */
import json
def handler(event, context):
body = {
"message": "Hello from Lambda!"
}
@dabit3
dabit3 / App.js
Created March 20, 2020 19:47
Expo + Amplify DataStore App
import Amplify from '@aws-amplify/core'
import config from './aws-exports'
Amplify.configure(config)
import React, { useState, useEffect } from 'react'
import { Text, View, TextInput, Button } from 'react-native'
import { DataStore } from '@aws-amplify/datastore'
import { Message} from './src/models'
const initialState = { color: 'black', title: '' }
@dabit3
dabit3 / App.js
Last active February 15, 2023 09:56
Amplify DataStore App
import React, { useState, useEffect } from 'react'
import { SketchPicker } from 'react-color'
import { Input, Button } from 'antd'
import { DataStore } from '@aws-amplify/datastore'
import { Message} from './models'
const initialState = { color: '#000000', title: '', }
function App() {
const [formState, updateFormState] = useState(initialState)
@dabit3
dabit3 / schema.graphql
Created March 9, 2020 14:47
Fine grained access control
type Post @model
@auth(rules: [
# Owner can create, update, delete
{ allow: owner },
# Authorize group-based access control
{ allow: groups, groups: ["Admin"] }
]) {
id: ID!
title: String!
content: String
@dabit3
dabit3 / datastore.md
Last active December 10, 2023 03:52
Building offline apps with Amplify DataStore

Building offline apps with Amplify DataStore

To view and deploy the app covered in this chapter, check out this repo.

So far in this book we've worked with both REST APIs and GraphQL APIs. When working with the GraphQL APIs so far, we've used the API class to directly call mutations and queries against the API.

Amplify also supports another type of API for interacting with AppSync, Amplify DataStore. DataStore has a different approach than a traditional GraphQL API.

Instead of interacting with the GraphQL API itself using queries and mutations, DataStore introduces a client-side SDK that persists the data locally using the local storage engine of the platform you are working with (i.e. IndexDB for web, SQLLite for native iOS and Android). DataStore then automatically syncs the local data to the GraphQL backend for you as updates are made both locally and remotely.