Giter Club home page Giter Club logo

aws-appsync-chat's Introduction

Chatt

Real-Time Offline Ready Chat App written with GraphQL, AWS AppSync, & AWS Amplify

Features

  • User management
  • Routing (React Router)
  • Real-time
  • Offline ready (conflict resolution handled for you when user comes back online)

Technologies

  • AWS AppSync
  • AWS Amplify
  • GraphQL
  • MobX
  • React Router
  • React Apollo
  • Glamor

Screens

Building the App (automated)

This project contains an Amplify project (/amplify) already configured & ready to be deployed. Deploying this project will create the following resources in your account: an authentication configuration using Amazon Cognito, an AWS AppSync GraphQL API, & a DynamoDB table.

  1. Make sure you are on the newest version of the AWS Amplify CLI
npm install -g @aws-amplify/cli

You must also have the CLI configured with a user from your AWS account (amplify configure). For a walkthrough of how to do this, check out this video.

  1. Clone Chatt
git clone https://github.com/aws-samples/aws-appsync-chat.git
  1. Install dependencies
npm install
  1. Initialize the amplify project
amplify init
  • Enter a name for the environment master
  1. Push the new resources to the cloud
amplify push
  1. Run the project
npm start
  1. Deleting the project resources

If you'd like to tear down the project & delete all of the resources created by this project, run the delete command.

amplify delete

Building the App (manually)

You can also manually set up your resources if you would like. If you would like to manually create & configure the resources for this project, follow these steps:

  1. Install & configure the Amplify CLI
npm install -g @aws-amplify

amplify configure
  1. Clone Chatt
git clone https://github.com/aws-samples/aws-appsync-chat.git
  1. Install dependencies
npm install
  1. Delete the amplify folder

  2. Initialize a new Amplify project

amplify init
  1. Add authentication
amplify add auth

Here, either choose the default security choice or configure your own.

  1. Add the api
amplify add api

Choose Cognito User Pools as the authentication type. When prompted for the GraphQL schema, use the following schema:

type User 
  @model 
  @auth(rules: [{ allow: owner, ownerField: "id", queries: null }]) {
  id: ID!
  username: String!
  conversations: [ConvoLink] @connection(name: "UserLinks")
  messages: [Message] @connection(name: "UserMessages")
	createdAt: String
	updatedAt: String
}

type Conversation
  @model(
    mutations: { create: "createConvo" }
    queries: { get: "getConvo" }
    subscriptions: null
  )
  @auth(rules: [{ allow: owner, ownerField: "members" }]) {
  id: ID!
  messages: [Message] @connection(name: "ConvoMsgs", sortField: "createdAt")
  associated: [ConvoLink] @connection(name: "AssociatedLinks")
  name: String!
  members: [String!]!
	createdAt: String
	updatedAt: String
}

type Message 
  @model(subscriptions: null, queries: null) 
  @auth(rules: [{ allow: owner, ownerField: "authorId" }]) {
  id: ID!
  author: User @connection(name: "UserMessages", keyField: "authorId")
  authorId: String
  content: String!
  conversation: Conversation! @connection(name: "ConvoMsgs")
  messageConversationId: ID!
	createdAt: String
	updatedAt: String
}

type ConvoLink 
  @model(
    mutations: { create: "createConvoLink", update: "updateConvoLink" }
    queries: null
    subscriptions: null
  ) {
  id: ID!
  user: User! @connection(name: "UserLinks")
  convoLinkUserId: ID
  conversation: Conversation! @connection(name: "AssociatedLinks")
  convoLinkConversationId: ID!
	createdAt: String
	updatedAt: String
}

type Subscription {
  onCreateConvoLink(convoLinkUserId: ID!): ConvoLink
    @aws_subscribe(mutations: ["createConvoLink"])
  onCreateMessage(messageConversationId: ID!): Message
    @aws_subscribe(mutations: ["createMessage"])
}
  1. Run the push command to create the resources in your account:
amplify push
  1. Run the project
npm start
  1. Deleting the project resources

If you'd like to tear down the project & delete all of the resources created by this project, run the delete command.

amplify delete

Hosting with the AWS Amplify Console

The AWS Amplify Console provides continuous deployment and hosting for modern web apps (single page apps and static site generators) with serverless backends. Continuous deployment allows developers to deploy updates to either the frontend or backend (Lambda functions, GraphQL resolvers) on every code commit to the Git repository.

  1. Push your code to a Git repository of your choice.
  2. Login to the AWS Amplify Console and choose Connect app
  3. Connect your repository and branch.
  4. Accept the default build settings.
  5. Give the Amplify Console permission to deploy backend resources with your frontend. This will allow the Console to detect changes to your backend on every code commit. If you do not have a service role, follow the prompts to create one.
  6. Review your changes and then choose Save and deploy. You app will now be available at https://master.unique-id.amplifyapp.com.

About

Schema

This application utilizes 4 database tables:

  • User table (stores user's identity information)
  • Conversation table (stores conversations)
  • Messages table (stores messages)
  • ConvoLinkTable (stores relations between conversations & users)

License

This library is licensed under the Apache 2.0 License.

aws-appsync-chat's People

Contributors

dabit3 avatar jpeddicord avatar swaminator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-appsync-chat's Issues

Chat Mobile Push Notification

Thanks for your example.
I'm making an attempt to build a mobile Chat app and prefer AWS AppSync. For chat app, one of the basic requirements is Push Notification when user is not using the app, but I haven't found any tutorial or article that points out how to accomplish a completed AppSync chat app supporting Push Notification.
It will be very much appreciated if any suggestion to guide to get Push Notification (APNS/FCM) worked with AppSync successfully.

Unhandled GraphQL subscription error Error: Error during subscription handshake

Hi folks!

Just trying this project out for the first time and running it in localhost and i get this error:

index.js:1446 Unhandled GraphQL subscription error Error: Error during subscription handshake
    at new ApolloError (ApolloError.js:58)
    at subscription-handshake-link.js:288
    at new Subscription (Observable.js:212)
    at Observable.subscribe (Observable.js:290)

Not sure what the actual real cause of the error is, but figured I would report it.

I debugged and logged out the operation in question:

image

Conversations not rendering properly

Updated schema.graphql to reflect recent pull requests made to the source code's schema.graphql -- the subscription error handshake is gone and thus debugging the app isn't producing any errors.

However, when loading a conversation, what's published shows from the current user, yet doesn't display for the subscriber. Additionally, if the subscriber replies with its own pub, that message/conversation loads in one frame, then rerenders as if the received conversation did not exist.

Addendum: Running on Node 10.x, Node 8.x seems to be deprecated and will deny amplify push without updating Amplify settings to Node 10.x. Not sure if this part of the issue in creating inconsistencies with chat features.

amplify push error

Hello,
I was following the tutorial and the amplify push don't work on this project, I have an error.
Here is a screenshot
image
Does someone have the same error ?

amplify push results in error

Followed the instructions for building the app in the automated way and when I did amplify push I got this error:

Cannot read property 'defaultAuthentication' of undefined
An error occured during the push operation: Cannot read property 'defaultAuthentication' of undefined

How to map two users using Conversation Id

How to maintain the same conversation Id between two users for chat application using "AWS Appsync"
Ex:- If "user A" sends a message to "user B" for the first time a conversation Id will create, if "user B" pings back to "user A", that should happen in the same conversation Id.
My question is how would "user B" will know the conversation Id of "User A". And also how to maintain multiple conversation Id for "user A" (If more users C, D, E get logged in)

Question mutation resolver

Hello... how can I do to use on a mutation condition a prop of the schema I'm trying to update?

Example: update an user when the role is admin and role is an AWSJSON prop on type User itself.

Like a groupsCanAccess

Asking for documentation

Hello there!
I was looking for the documentation of these directives in schema.graphql
@auth,@model
I didn't find any thing in Appsync documentation and AppSync API reference
please can you provide full documentation for how to use them

how to identify number of active subscribers by subscription in appsync

Need to keep count of how many subscribers are connected with each subscription.

For UserA, UserB are connected with SubscriptionA : then 2 is the total subscribers
For UserA are connected with SubscriptionB : then 1 is the total subscribers

Can i know when UserA unsubscribes , subscribes, disconnects, reconnects from AppSync ?

API is not returning all messages in conversation

when calling getConvo, the messages returned are filtered with author==currentUser
Thus once we close the conversation and re-open later, we can only see our own messages.

Issue is due to the @auth in the graphql schema filtering the "type Message"
I would suggest to leave the read open as there are no direct query on Message, always thru connections

type Message 
  @model(subscriptions: null, queries: null) 
  @auth(rules: [{ allow: owner, ownerField: "authorId", operations: [create, update, delete]}]) {
  id: ID!
  author: User @connection(name: "UserMessages", keyField: "authorId")
  authorId: String
  content: String!
  conversation: Conversation! @connection(name: "ConvoMsgs")
  messageConversationId: ID!
	createdAt: String
	updatedAt: String
}

npm install fails on Node.js 12.16.1

npm install fails on Node.js 12.16.1 but runs without issues on Node.js 10.19.0

Host OS version: macOS Catalina 10.15.3
npm version: 6.14.2

I think it would be nice to mention latest supported/working version of node in the README or maybe fix the sample to work with latest LTS Node.js.

I installed both Node.js and npm through MacPorts.

Node.js 12.16.1 fails with the following message:

$ npm install

> [email protected] install /Users/matyas/dev/aws-appsync-chat/node_modules/chokidar/node_modules/fsevents
> node-gyp rebuild

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node

> [email protected] install /Users/matyas/dev/aws-appsync-chat/node_modules/fsevents
> node install

node-pre-gyp WARN Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.4/fse-v1.2.4-node-v72-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
Traceback (most recent call last):
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 50, in <module>
    sys.exit(gyp.script_main())
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 554, in script_main
    return main(sys.argv[1:])
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 547, in main
    return gyp_main(args)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 532, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2215, in GenerateOutput
    part_of_all=qualified_target in needed_targets)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 802, in Write
    self.WriteCopies(spec['copies'], extra_outputs, part_of_all)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1145, in WriteCopies
    env = self.GetSortedXcodeEnv()
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1885, in GetSortedXcodeEnv
    additional_settings)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1616, in GetSortedXcodeEnv
    additional_settings)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1527, in _GetXcodeEnv
    if XcodeVersion() >= '0500' and not env.get('SDKROOT'):
TypeError: '>=' not supported between instances of 'tuple' and 'str'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 19.3.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node" "--module_name=fse" "--module_path=/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64" "--napi_version=5" "--node_abi_napi=napi"
gyp ERR! cwd /Users/matyas/dev/aws-appsync-chat/node_modules/fsevents
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node --module_name=fse --module_path=/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64 --napi_version=5 --node_abi_napi=napi' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
node-pre-gyp ERR! System Darwin 19.3.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/matyas/dev/aws-appsync-chat/node_modules/fsevents
node-pre-gyp ERR! node -v v12.16.1
node-pre-gyp ERR! node-pre-gyp -v v0.10.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node --module_name=fse --module_path=/Users/matyas/dev/aws-appsync-chat/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64 --napi_version=5 --node_abi_napi=napi' (1)

> [email protected] postinstall /Users/matyas/dev/aws-appsync-chat/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node install`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

added 2109 packages from 883 contributors and audited 40112 packages in 27.228s

29 packages are looking for funding
  run `npm fund` for details

found 71 vulnerabilities (63 low, 2 moderate, 6 high)
  run `npm audit fix` to fix them, or `npm audit` for details

Differences in specifying connection between conversations and messages

In this sample app, in order to display the messages of a conversation, a "getConvo" query is used, which returns the conversation and its messages.

type Conversation 
  @model (mutations: { create: "createConvo" }, queries: { get: "getConvo" }, subscriptions: null) {
  id: ID!
  messages: [Message] @connection(name: "ConvoMsgs", sortField: "createdAt")
  ...
}
type Message @model(subscriptions: null, queries: null) {
  id: ID!
  conversation: Conversation! @connection(name: "ConvoMsgs")
  messageConversationId: ID!
  ...
}
type Subscription {
  onCreateMessage(messageConversationId: ID!): Message
    @aws_subscribe(mutations: ["createMessage"])
}

However, in many of the sample apps from @dabit3 , like conference app in a box, he uses a different style of getting messages, with a "listMessagesByConversationId" query, and a keyfield on the connection between conversations and messages

type Conversation @model {
  id: ID!
  messages: [Message] @connection(name: "ConvoMsgs", keyfield: "messageConversationId")
  ...
}
type Message @model {
  id: ID!
  conversation: Conversation! @connection(name: "ConvoMsgs", sortField: "createdAt", keyfield: "messageConversationId")
  messageConversationId: ID!
  ...
}
type Query {
  listMessagesByConversationId(messageConversationId: ID!): ModelMessageConnection
}
type Subscription {
  onCreateMessageWithId(messageConversationId: ID!): Message
		@aws_subscribe(mutations: ["createMessage"])
}

Is one method more efficient than the other in cost or speed, or are they very similar?

Attempted to redefine property 'micText'

Attempted to redefine property 'micText'
Attempted to redefine property 'micText'

no stack
no stack

"aws-amplify": "^1.1.19",
"aws-amplify-react": "^2.3.0",
"aws-amplify-react-native": "^2.1.7",
"aws-appsync": "^1.7.1",
"aws-appsync-react": "^1.2.6",
"glamor": "^2.20.40",
"graphql-tag": "^2.10.1",
"mobx": "^5.9.0",
"mobx-react": "^5.4.3",
"react": "^16.8.3",
"react-apollo": "^2.5.1",
"react-dom": "^16.8.3",
"react-icons": "^3.4.0",
"react-native": "0.58.5",
"react-router-dom": "^4.3.1"

npm : 6.4.1

6835477730630310640

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.