type Customer {
id: ID!
email: String!
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enable SSR support in Amplify app | |
| Amplify.configure({ ...config, ssr: true }) | |
| // Library usage in SSR or API routes | |
| import { withSSRContext } from 'aws-amplify' | |
| const { Auth, API } = withSSRContext({ req }) | |
| // Get user session | |
| const user = await Auth.currentAuthenticatedUser() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useEffect } from 'react'; | |
| import { API, Auth } from 'aws-amplify' | |
| import { listPosts } from './graphql/queries' | |
| const initialState = { | |
| formState: 'signUp', username: '', password: '', email: '', authCode: '' | |
| } | |
| export default function App() { | |
| const [posts, setPosts] = useState([]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # query | |
| curl \ | |
| -X POST \ | |
| -H "x-api-key: xxx-xxxx" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ "query": "query { listUsers { name } }" }' \ | |
| https://app-id.appsync-api.us-east-1.amazonaws.com/graphql | |
| # mutation with variables | |
| curl \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useEffect } from 'react'; | |
| import { List, message, Avatar, Spin } from 'antd'; | |
| import reqwest from 'reqwest'; | |
| import InfiniteScroll from 'react-infinite-scroller'; | |
| const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo'; | |
| const InfiniteListExample = () => { | |
| let [data, setData] = useState([]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useEffect, useState } from 'react'; | |
| import Auth from 'aws-amplify' | |
| import { css } from 'emotion'; | |
| import { useRouter } from 'next/router' | |
| const primaryColor = "rgba(0,118,255,0.9)" | |
| const intitialFormState = { | |
| username: '', | |
| email: '', | |
| password: '', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Public and owner access | |
| type Post @model | |
| @auth( | |
| { allow: owner }, | |
| { allow: public, operations: [read] } | |
| ) | |
| { | |
| id: ID! | |
| content: String! | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AWS = require('aws-sdk') | |
| const docClient = new AWS.DynamoDB.DocumentClient() | |
| async function createUser(user) { | |
| const params = { | |
| TableName: "AppSyncUserTable", | |
| Item: user | |
| } | |
| // user should look like this: user = { id: "3", name: "Chris", location: "Canada" } | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Address | |
| @model | |
| @key(name: "byJob", fields: ["jobId", "addressLine1"]) | |
| @auth( | |
| rules: [ | |
| { allow: groups, groups: ["Admin"], queries: [get, list], mutations: [update, delete] } | |
| { allow: public, operations: [read], queries: [get, list], mutations: [create] } | |
| { allow: private, operations: [read], mutations: [create] } | |
| ] | |
| ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Imports from CDK */ | |
| import * as appsync from '@aws-cdk/aws-appsync'; | |
| import * as db from '@aws-cdk/aws-dynamodb'; | |
| /* Creating the API */ | |
| const api = new appsync.GraphQLApi(this, 'Api', { | |
| name: 'my-chat-app', // API name | |
| schemaDefinition: appsync.SchemaDefinition.FILE, // Type of schema | |
| schemaDefinitionFile: './schema.graphql', // location of schema | |
| authorizationConfig: { // authorization config |