aws-samples / aws-mobile-appsync-chat-starter-angular

GraphQL starter progressive web application (PWA) with Realtime and Offline functionality using AWS AppSync
https://aws.amazon.com/appsync/
Apache License 2.0
518 stars 161 forks source link

[ts] Cannot find module 'aws-appsync' #14

Closed pablitodeveloper closed 6 years ago

pablitodeveloper commented 6 years ago

Hi,

I'm tried this demo without auth and I have an problem with appsync. The message is [ts] Cannot find module 'aws-appsync'

import { Injectable } from '@angular/core';

import AWSAppSyncClient from 'aws-appsync';
import { environment } from '../../../environments/environment';

@Injectable()
export class TodoService {
  client: AWSAppSyncClient;
  hc;

  constructor() {
    this.hc = this.hydratedClient;
  }

  hydratedClient() {
    return new Promise((resolve) => {
      this.client = this.client || this.newClient();
      resolve(this.client.hydated());
    });
  }

  private newClient() {
    return new AWSAppSyncClient({
      environment
    });
  }

}

my environment

export const environment = {
  production: false,
  appsync: {
    url: '*******my-graphqlEndpoint**********',
    region: '*******my-region*********',
    auth: {
      authenticationType: 'API_KEY',
      apiKey: '******my-apiKey********'
    }
  }
};

later I added one typing definition for 'aws-appsync'

declare var module: NodeModule;
interface NodeModule {
  id: string;
}

declare module 'aws-appsync' {
  export default interface AWSAppSyncClient{
    hydated
  }
}

and I had other problem with the message "[ts] 'AWSAppSyncClient' only refers to a type, but is being used as a value here." in this part

  private newClient() {
    return new AWSAppSyncClient({
      environment
    });
  }

Package

{
  "name": "aws-appsync-ng",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || ng serve; ng serve",
    "build": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || ng build --prod; ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@angular/service-worker": "^5.2.0",
    "add": "^2.0.6",
    "apollo-angular": "^1.0.1",
    "apollo-angular-link-http": "^1.0.2",
    "apollo-cache-inmemory": "^1.1.12",
    "apollo-client": "^2.2.8",
    "aws-amplify": "0.3.2",
    "aws-amplify-angular": "^0.1.0",
    "aws-appsync": "1.0.16",
    "core-js": "^2.4.1",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.8.0",
    "rxjs": "^5.5.6",
    "yarn": "^1.6.0",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "1.6.5",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^9.6.6",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}

Do you have any suggestions for this?

KoldBrewEd commented 6 years ago

This chat app needs authentication with Cognito to feed the user's table. I also noticed you're calling your service TodoService. What are you trying to do exactly?

pablitodeveloper commented 6 years ago

Hi Ed,

I just want charge data from appsync but without auth

KoldBrewEd commented 6 years ago

So this is not really an issue as you're modifying our implementation and you're adding a to-do service that sounds like from another sample. Suggest you look at the syntax and make sure you're pointing to the right file.