Skip to content

Instantly share code, notes, and snippets.

@rafbgarcia
Created February 5, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafbgarcia/857d74fc57b67522eb0bd325697035a1 to your computer and use it in GitHub Desktop.
Save rafbgarcia/857d74fc57b67522eb0bd325697035a1 to your computer and use it in GitHub Desktop.
import { BrowserModule } from '@angular/platform-browser'
import { ErrorHandler, NgModule } from '@angular/core'
import { HttpClientModule } from '@angular/common/http'
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'
import { IonicStorageModule } from '@ionic/storage'
import { StatusBar } from '@ionic-native/status-bar'
import { SplashScreen } from '@ionic-native/splash-screen'
import { OneSignal } from '@ionic-native/onesignal'
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { ApolloModule, Apollo } from 'apollo-angular'
import { HttpLinkModule, HttpLink } from 'apollo-angular-link-http'
import { TextMaskModule } from 'angular2-text-mask'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { HttpHeaders } from '@angular/common/http'
import { setContext } from 'apollo-link-context'
import { MyApp } from './app.component'
import HomePage from '../pages/home/home'
import LoginPage from '../pages/login/login'
import VerifyCodePage from '../pages/login/verify_code'
import Motoboy from '../services/motoboy'
import { MyErrorHandler } from './error_handler'
@NgModule({
declarations: [
MyApp,
HomePage,
LoginPage,
VerifyCodePage,
],
imports: [
HttpClientModule,
ApolloModule,
HttpLinkModule,
BrowserModule,
TextMaskModule,
IonicStorageModule.forRoot(),
IonicModule.forRoot(MyApp),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
LoginPage,
VerifyCodePage,
],
providers: [
Motoboy,
OneSignal,
InAppBrowser,
StatusBar,
SplashScreen,
IonicErrorHandler,
{provide: ErrorHandler, useClass: MyErrorHandler}
]
})
export class AppModule {
constructor(
apollo: Apollo,
httpLink: HttpLink,
motoboy: Motoboy,
) {
const auth = setContext(async (_operation, _prevContext) => {
const {token} = await motoboy.current()
if (token) {
return {
headers: new HttpHeaders().set('authorization', `Bearer ${token}`),
}
}
return {}
})
const myHttpLink = httpLink.create({
// uri: 'http://192.168.1.15:4000/motoboy',
uri: 'https://myapp.com/motoboy',
})
const link = auth.concat(myHttpLink)
apollo.create({
link,
cache: new InMemoryCache(),
// @docs for defaultOptions
// https://www.apollographql.com/docs/angular/basics/setup.html
defaultOptions: {
watchQuery: {
fetchPolicy: "network-only",
errorPolicy: 'ignore',
},
query: {
fetchPolicy: "network-only",
errorPolicy: 'ignore',
},
},
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment