Giter VIP home page Giter VIP logo

kamilkisiela / apollo-angular Goto Github PK

View Code? Open in Web Editor NEW
1.5K 70.0 309.0 17.07 MB

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁

Home Page: https://apollo-angular.com

License: MIT License

TypeScript 23.79% JavaScript 1.24% Dockerfile 0.37% Shell 1.27% HTML 0.03% SCSS 0.07% MDX 73.23%
apollo-client angular apollographql graphql graphql-client typescript the-guild

apollo-angular's Introduction

Angular

Apollo Angular allows you to fetch data from your GraphQL server and use it in building complex and reactive UIs using the Angular framework. Apollo Angular may be used in any context that Angular may be used. In the browser, in NativeScript, or in Node.js when you want to do server-side rendering.

Apollo Angular requires no complex build setup to get up and running. As long as you have a GraphQL server you can get started building out your application with Angular immediately. Apollo Angular works out of the box with both Angular CLI (ng add apollo-angular) and NativeScript with a single install.

Apollo Angular is:

  1. Incrementally adoptable, so that you can drop it into an existing JavaScript app and start using GraphQL for just part of your UI.
  2. Universally compatible, so that Apollo works with any build setup, any GraphQL server, and any GraphQL schema.
  3. Simple to get started with, so you can start loading data right away and learn about advanced features later.
  4. Inspectable and understandable, so that you can have great developer tools to understand exactly what is happening in your app.
  5. Built for interactive apps, so your users can make changes and see them reflected in the UI immediately.
  6. Small and flexible, so you don't get stuff you don't need. The core is under 12kb compressed.
  7. Community driven, because Apollo is driven by the community and serves a variety of use cases. Everything is planned and developed in the open.

Get started today on the app you’ve been dreaming of, and let Apollo Angular take you to the moon!

Installation

It is simple to install Apollo Angular and related libraries

# installing Apollo Angular in Angular CLI
ng add apollo-angular

# installing each piece independently
yarn add @apollo/client apollo-angular graphql

That’s it! You may now use Apollo Angular in any of your Angular environments.

For an amazing developer experience you may also install the Apollo Client Developer tools for Chrome which will give you inspectability into your Apollo Angular data.

  • If you are using Apollo-Client v3, please make sure to use apollo-angular@v3

    If you are using Apollo-Client v2, please make sure to use apollo-angular@v1 (and for Angular 10 support, make sure to use v1.10.0)

Usage

Now you may create components that are connected to your GraphQL API.

Finally, to demonstrate the power of Apollo Angular in building interactive UIs let us connect one of your components to your GraphQL server using the Apollo service:

import { Apollo, gql } from 'apollo-angular';
import { Component, OnInit } from '@angular/core';

const GET_DOGS = gql`
  {
    dogs {
      id
      breed
    }
  }
`;

@Component({
  selector: 'dogs',
  template: `
    <ul>
      <li *ngFor="let dog of dogs | async">
        {{ dog.breed }}
      </li>
    </ul>
  `,
})
export class DogsComponent implements OnInit {
  dogs: Observable<any>;

  constructor(private apollo: Apollo) {}

  ngOnInit() {
    this.dogs = this.apollo
      .watchQuery({
        query: GET_DOGS,
      })
      .valueChanges.pipe(map(result => result.data && result.data.dogs));
  }
}

To learn more about querying with Apollo Angular be sure to start reading the documentation article on queries.

Documentation

All the documentation for Apollo Angular including usage articles and helpful recipes lives on: https://www.apollo-angular.com/

Contributing

Read the Apollo Contributor Guidelines.

This project uses Lerna.

Bootstrapping:

yarn install

Running tests locally:

yarn test

Formatting code with prettier:

yarn prettier

This project uses TypeScript for static typing. You can get it built into your editor with no configuration by opening this project in Visual Studio Code, an open source IDE which is available for free on all platforms.

apollo-angular's People

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  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

apollo-angular's Issues

Dynamic gql queries without arguments, possible?

Is it possible to construct gql string variables with passed variables as such?:

getRules(model: string){
        
        var queryVar = gql`
		query HyperionSchemaQuery {
			rules {
				`+model+` {
				        rules
				}
			}
		}
	`;

	var rulesArray;

	this.apollo.watchQuery({
		query: queryVar
	}).subscribe(({data}) => {
		rulesArray = JSON.parse(data.rules[model].rules);
		console.log(rulesArray);
	});
}

this.getRules("Day"); gives error:

EXCEPTION: Error in ./ProjectMain class ProjectMain - inline template:191:108 caused by: Syntax Error GraphQL (4:7) Expected Name, found EOF

3: 				rules {
4: 						
         ^

A multiline string variable, without the "gql" logs the following:

var queryVar = `
	query HyperionSchemaQuery {
		rules {
				`+model+` {
			rules
			}
		}
	}
`;

logs:

query HyperionSchemaQuery {
	rules {
			Day {
		rules
		}
	}
}

Which would be how an accepted graphql-query would look like in my case. Is there some way I could construct such a variable and pass it as the query in my watchQuery()? Iv'e tested in many different ways (to construct the gql`` string) without success and can't find anything in the documentation or in the GitHunt example.

Angular2-Apollo Authorization Auth Guard - Expired Login

There is an sample for authorization (sign request with authorization header) on the docs.

However it is a little bit unclear to me, how to watch request for failed authorization,missing rights or login and handle accordingly?

  • Missing login --> redirect to login route and retry afterwards
  • Missing rights --> show error eg. through toast notification
  1. Is there any best practise for this?
  2. Is there a best practise for throwing auth errors with GraphQL Server?
  3. How to handle in angular 2? How can I catch errors returned from graphql on an network interface level eg. for redirecting to login screen.

Not working with Angular Universal

I'm using Universal-Starter. When the app is running in the client all is fine. When it runs on the server the following error is thrown in the apollo-client package.

 'Network error: fetch is not defined'

Correct usage with RxJS

According to the docs the watchQuery should return an Observable that can be used with RxJS. But if i try to subscribe to the ApolloQueryObservable i get Cannot read property subscribe of undefined. This happens because the ApolloQueryObservable has not such method.

I figured out that the following works:

    this.users = angularApollo.watchQuery({
      query: gql`
        query {
          users {
            username
            name
          }
        }
      `
    }).apollo;

    this.users.subscribe({
      next: ({data}) => {
        console.log(data);
      },
      error: (err) => {
        console.log(err);
      }
    });

But this won't work:

    this.users = angularApollo.watchQuery({
      query: gql`
        query {
          users {
            username
            name
          }
        }
      `
    });

    this.users.subscribe((user) => {
      console.log(user);
    });

How is this intended to work? Maybe i'm getting something wrong...

typescript transpiler errors

Is it anyhow possible to get rid of the typescript errors caused by Angular2Apollo?

ERROR in [default] /Users/.../app-angular2/node_modules/angular2-apollo/build/src/Angular2Apollo.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/angular2-apollo/build/src/Angular2Apollo.d.ts:5:35 
Cannot find module 'graphql'.

also apollo-client is throwing a lot of typescript transpilation errors:

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/ApolloClient.d.ts:1:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/actions.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/actions.d.ts:3:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/actions.d.ts:4:40 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/core/ObservableQuery.d.ts:1:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/core/QueryManager.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/core/QueryManager.d.ts:3:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/core/QueryManager.d.ts:8:25 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/core/watchQueryOptions.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/core/watchQueryOptions.d.ts:2:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/core/watchQueryOptions.d.ts:4:45 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/extensions.d.ts:1:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/mutationResults.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/mutationResults.d.ts:2:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/mutationResults.d.ts:4:40 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/readFromStore.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/readFromStore.d.ts:2:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/readFromStore.d.ts:3:25 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/scopeQuery.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/scopeQuery.d.ts:3:29 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/storeUtils.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/storeUtils.d.ts:2:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/storeUtils.d.ts:3:64 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/writeToStore.d.ts:1:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/writeToStore.d.ts:2:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/data/writeToStore.d.ts:4:39 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/errors/ApolloError.d.ts:2:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/errors/ApolloError.d.ts:3:29 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/fragments.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/fragments.d.ts:2:45 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/mutations/store.d.ts:1:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/mutations/store.d.ts:3:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/mutations/store.d.ts:5:29 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/queries/getFromAST.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/queries/getFromAST.d.ts:2:66 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/queries/store.d.ts:1:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/queries/store.d.ts:3:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/queries/store.d.ts:5:43 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/transport/batchedNetworkInterface.d.ts:2:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/transport/batchedNetworkInterface.d.ts:3:30 
Cannot find module 'graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/transport/networkInterface.d.ts:1:0 
Cannot find type definition file for 'typed-graphql'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/transport/networkInterface.d.ts:2:0 
Cannot find type definition file for 'chai'.

ERROR in [default] /Users/.../app-angular2/node_modules/apollo-client/transport/networkInterface.d.ts:5:40 
Cannot find module 'graphql'.

@Urigo wouldn't it make sense to include typed-graphql into angular2-apollo to avoid this errors?

Similar discussions are on apollo-client:

Refetch does not trigger subscribe

This is a question/possible bug about the refetch method documented here.

I noticed that refetch returns a promise that resolves the new data. However, I had expected that a subscription on the original query would be triggered when refetch is called. This is not the case, eg:

ngOnInit() {
  this.query = this.apollo.watchQuery({query: TestQuery});
  this.query.subscribe(({data}) => {
    console.log(data);
  });
}

refetch() {
  this.query.refetch();
}

I would expect the subscribe callback to be triggered again after refetch is executed. Could someone clarify why this does not happen?

Thanks

Problems with hello-world / getting started in general

I'm a angular2 beginner but Apollo looks exceptionally interesting and I'm really hoping to use it together with the excellent work you guys are doing.

Alas.. I just can't seem to get started. Error after error after error! I'm blocked by apollographql/apollo-client#207 in getting the main client working and with angular2-apollo hello-world project I just get more different errors.

(npm WARN @angular/[email protected] requires a peer of [email protected] but none was installed., followed by sh: meteor: command not found, not sure how that is related to angular2+apollo)

I feel like I'm in a parallel universe in which I forgot how to computer.

Please help! Apollo looks like exactly what my company needs!

Integrating angular2-apollo into the Angular2 quickstart project

node/npm/angular2 beginner here.

I did the Angular2 Tutorial at https://angular.io/docs/ts/latest/tutorial/
I am now trying to integrate angular2-apollo into this project.

Yet, the Angular2 setup (with SystemJS) does not seem to work with angular2-apollo.

I tried both "npm install angular2-apollo" and including it in my package.json.
The install was successful and I have all necessary files in my node_modules folder (.js etc).
But as soon as I my code has an import from angular2-apollo (or from apollo-client) I get a 404 on Client-side.
I tried including the angular2-apollo modules via SystemJS, but that just leads to further missing modules which lead to further missing modules, and so on.

Can somebody provide any help?

compilerOptions.lib on ionic

I have read this http://dev.apollodata.com/angular2/initialization.html#typescript-es2015

TypeScript 2.0 comes with a set of predefined type declarations.
If you’re using one of them that brings ES2015 (ES6) you should disable it, because @types/es6-shim will cause an issue with multiple types definitons.

It’s easy, just replace es6, es2015 or similar options from compilerOptions.lib for es5.

This only works if I have to do ionic build <platform> or ionic run <platform> . But will not work if I do ionic serve I will see the es6-shim issues and setting compilerOptions.lib back to es6, es2015 will fix it.
What is the reason? Is there a way around this? I have to modify tsconfig everytime.

Here is my ionic info

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.2
Ionic CLI Version: 2.1.8
Ionic App Lib Version: 2.1.4
Ionic App Scripts Version: 0.0.43
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.6.0
Xcode version: Not installed

Here is my tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es6"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

Here is my packages.json

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "build": "ionic-app-scripts build",
    "watch": "ionic-app-scripts watch",
    "serve:before": "watch",
    "emulate:before": "build",
    "deploy:before": "build",
    "build:before": "build",
    "run:before": "build"
  },
  "dependencies": {
    "@angular/common": "2.1.1",
    "@angular/compiler": "2.1.1",
    "@angular/compiler-cli": "2.1.1",
    "@angular/core": "2.1.1",
    "@angular/forms": "2.1.1",
    "@angular/http": "2.1.1",
    "@angular/platform-browser": "2.1.1",
    "@angular/platform-browser-dynamic": "2.1.1",
    "@angular/platform-server": "2.1.1",
    "@ionic/storage": "1.1.6",
    "angular2-apollo": "^0.8.0",
    "apollo-client": "^0.5.2",
    "graphql-tag": "^0.1.16",
    "ionic-angular": "2.0.0-rc.2",
    "ionic-native": "2.2.3",
    "ionicons": "3.0.0",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "0.6.21"
  },
  "devDependencies": {
    "@ionic/app-scripts": "0.0.43",
    "typescript": "2.0.9"
  },
  "description": "githubIonic: An Ionic project",
  "cordovaPlugins": [
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-whitelist",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": []
}

Query sent multiple times when binding to more than one async pipe

Hi

If I bind a .watchQuery result to multiple async pipes in a single view, then for each binding a new query is sent to the server.

It appears that each subscription to a given ApolloQueryObservable causes the query to be sent to the server, as multiple subscriptions to the observable returned by .watchQuery within a component class also initiates the call to the server for each new subscription.

It seems as though the underlying sequence needs something like an rx .shareReplay() adding, or maybe I am doing something wrong? I am just running a simple

this.meetings = this.apollo.watchQuery({
        query: meetingsQuery,
        notifyOnNetworkStatusChange: true,
        variables: {
            site: 'gdavies',
            meetingGroup: 'Board'
        }
    })

Should I be able to bind the this.meetings to mulitple async pipes in the view and only have the query execute once against the server?

Thanks
Glen

NativeScript support

I am about to start a new project with ng2. I plan on re-using a lot of my services/core logic from my ng2 app in a NativeScript app. Will angular2-apollo play nicely with NativeScript?

Hello World: angular2-compilers fails

Hi, while trying to run the example in Windows 10 I've found issues with this package.
I've had to use angular2-compilers@=0.6.0 to make it work.

Bug with watchQuery / ApolloQueryObservable

Hi, I Would like to report a bug i've just found in the Observable,
looking at ApolloQueryObservable (https://github.com/apollostack/angular2-apollo/blob/b887d17b6ef0a74fcfed1853ca8c9921fc706162/src/ApolloQueryObservable.ts#L9),
it is inherenting from Observable, and getting the observer creation cb as last parameter,
next, looking at watchQuery function (https://github.com/apollostack/angular2-apollo/blob/master/src/Angular2Apollo.ts#L26),
if there is no variables object next to the query, undefined will be passed there (https://github.com/apollostack/angular2-apollo/blob/master/src/Angular2Apollo.ts#L46)
So basiclly, we have a new observable that will call undefined upon subscription.

from what it looks like on variables flow, it looks like the intention is to use the watchQuery Observable (from apollo-client) in case variables are not used.


Also, i noted the observable doesn't send any values,
do i need to make any special implementation on the server side (Regular query is working)?

How to make requests to different URI's, using the same Client?

I need to send a mutation to another URL, but I cannot figure out, how to change it, while using the same ApolloClient. I cannot create another Client, because cookies can't be shared over Clients or at least I haven't figured out how to (it seems the 'Set-Cookie' header is restricted and only handled by the browser).

Typescript error using RxJs

The Apollo Angular 2 RxJs example code gives a Typescript error (but not a runtime error) for the following line...

 this.data = this.apollo.watchQuery({ query: FeedQuery })
        .map(({data}) => data.feed);
    }
[ts] Type 'Observable<any>' is not assignable to type 'ApolloQueryObservable<any>'.
       Property 'apollo' is missing in type 'Observable<any>'.

The return type of watchQuery is ApolloQueryObservable<any>. The type of the class property data is too. ?

Hello World: Error on app.component.ts ngOnInit

Related to #83, #84, #85 and #86.

I was getting the following error:

Type 'Observable<any>' is not assignable to type 'ApolloQueryObservable<any>'

I've had to cast the return of the map function in line 44 to ApolloQueryObservable<any>.

}).map(result => result.data.users) as ApolloQueryObservable<any>;

Can't serve app built by angular-cli using command `ng serve --aot`

Running ng serve --aot fails to run.

This is the console error:

* NG Live Development Server is running on http://localhost:4200. **
  0% compilingcan't resolve module apollo-client from /Users/Emil/Documents/Github/collab/collab/src/app/client.ts
can't find symbol undefined exported from module /Users/Emil/Documents/Github/collab/collab/node_modules/apollo-client/index.d.ts, resolving symbol AppModule in /Users/Emil/Documents/Github/collab/collab/src/app/app.module.ts, resolving symbol AppModule in /Users/Emil/Documents/Github/collab/collab/src/app/app.module.ts
Error: can't find symbol undefined exported from module /Users/Emil/Documents/Github/collab/collab/node_modules/apollo-client/index.d.ts, resolving symbol AppModule in /Users/Emil/Documents/Github/collab/collab/src/app/app.module.ts, resolving symbol AppModule in /Users/Emil/Documents/Github/collab/collab/src/app/app.module.ts
    at simplifyInContext (/Users/iminar/Dev/angular/modules/@angular/compiler-cli/src/static_reflector.ts:532:15)
    at StaticReflector.simplify (/Users/iminar/Dev/angular/modules/@angular/compiler-cli/src/static_reflector.ts:536:20)
    at StaticReflector.annotations (/Users/iminar/Dev/angular/modules/@angular/compiler-cli/src/static_reflector.ts:93:28)
    at NgModuleResolver.resolve (/Users/Emil/Documents/Github/collab/collab/node_modules/@angular/compiler/bundles/compiler.umd.js:14050:46)
    at CompileMetadataResolver.getNgModuleMetadata (/Users/Emil/Documents/Github/collab/collab/node_modules/@angular/compiler/bundles/compiler.umd.js:14296:49)
    at /Users/Emil/Documents/Github/collab/collab/node_modules/@angular/compiler/bundles/compiler.umd.js:13284:43
    at Array.forEach (native)
    at _extractModulesAndPipesOrDirectives (/Users/Emil/Documents/Github/collab/collab/node_modules/@angular/compiler/bundles/compiler.umd.js:13283:28)
    at analyzeNgModules (/Users/Emil/Documents/Github/collab/collab/node_modules/@angular/compiler/bundles/compiler.umd.js:13039:16)
    at OfflineCompiler.compileModules (/Users/Emil/Documents/Github/collab/collab/node_modules/@angular/compiler/bundles/compiler.umd.js:13115:20)
    at CodeGenerator.codegen (/Users/iminar/Dev/angular/modules/@angular/compiler-cli/src/codegen.ts:71:26)
    at AotPlugin._make (/Users/Emil/Documents/Github/collab/collab/node_modules/@ngtools/webpack/src/plugin.js:186:43)
    at Compiler.<anonymous> (/Users/Emil/Documents/Github/collab/collab/node_modules/@ngtools/webpack/src/plugin.js:151:75)
    at Compiler.applyPluginsParallel (/Users/Emil/Documents/Github/collab/collab/node_modules/tapable/lib/Tapable.js:156:14)
    at Compiler.<anonymous> (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:463:8)
    at Compiler.applyPluginsAsync (/Users/Emil/Documents/Github/collab/collab/node_modules/tapable/lib/Tapable.js:73:70)
    at Compiler.compile (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:456:7)
    at Watching.<anonymous> (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:46:17)
    at next (/Users/Emil/Documents/Github/collab/collab/node_modules/tapable/lib/Tapable.js:81:11)
    at Compiler.invalidAsyncPlugin (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack-dev-middleware/middleware.js:119:3)
    at next (/Users/Emil/Documents/Github/collab/collab/node_modules/tapable/lib/Tapable.js:83:14)
    at Compiler.<anonymous> (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/CachePlugin.js:31:4)
    at Compiler.applyPluginsAsync (/Users/Emil/Documents/Github/collab/collab/node_modules/tapable/lib/Tapable.js:85:13)
    at Watching._go (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:44:16)
    at Watching.<anonymous> (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:36:8)
    at Compiler.readRecords (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:367:10)
    at new Watching (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:33:16)
    at Compiler.watch (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack/lib/Compiler.js:204:17)
    at module.exports (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack-dev-middleware/middleware.js:146:27)
    at new Server (/Users/Emil/Documents/Github/collab/collab/node_modules/webpack-dev-server/lib/Server.js:43:20)
    at Class.run (/Users/Emil/Documents/Github/collab/collab/node_modules/angular-cli/tasks/serve-webpack.js:72:22)
    at /Users/Emil/Documents/Github/collab/collab/node_modules/angular-cli/commands/serve.js:92:26
    at process._tickCallback (internal/process/next_tick.js:103:7)

I'm not sure, but it might be related to angular/angular#11402

Help needed with graphQL and CORS

Hi,

I tried to add a middleware to the networkInterface to check if I can set up withCredentials flag there to support sending Cookies alongside a cross origin graphQL request.

I was following the documentation for Angular 2 here and Apollo Client here but TypeScript complains about this construct:

networkInterface.use({
  applyMiddleWare(req, next) => {
    console(req, next);
    next();
  }
});

I am also confused: why providing an object in which a method is called. Second question that came up: From where to import ApplyMiddleWare? I actually only found applyMiddleware (with lowercase a and w) when searching throughout the code. In the example page both variants are used.

I was wondering whether it would be possible to simply allow the withCredentials flag in the FetchOptions on which I found no dedicated documentation.

Help would be highly appreciated as I consider angular2-apollo just the right thing for a big Angular 2 application I am working on according to the descriptions.

Cheers

Can't call rxjs observable operators on object returned by watchQuery

Tried to write some code that did something like:

apolloClient.watchQuery(someQuery).map( (data) => data.stuff)

and was surprised to find map wasn't available even after I remembered to do the right rxjs import. It seems like this is something that would be desirable, but watchQuery doesn't return a real rxjs observable AFAICT. Am I doing it wrong or is this just not a thing? I can try to do a PR if this is something that's just not there yet.

Angular RC5 support

  • check if it breaks something
  • create NgModule
  • use NgModule in the HelloWorld example

Should the decorator use metadata?

One of the angular2 core devs mentioned in a slack that it was not recommended practice (in typescript) to have decorators that set methods or properties on the class. Instead, in angular2, decorators set metadata. Could the decorator in this project be re-written to use metadata somehow for the mutation methods instead of directly setting a method?

Options typings for Angular2Apollo service

To help development, typings on the options arguments in Angular2Apollo service methods could be added.

Angular2Apollo.watchQuery()

Link to source: Angular2Apollo.watchQuery()
Typedef: DeprecatedWatchQueryOptions

Angular2Apollo.query()

Link to source: Angular2Apollo.query()
Typedef: DeprecatedWatchQueryOptions

Angular2Apollo.mutate()

Link to source: Angular2Apollo.mutate()
Typedef: ApolloClient.mutate()

Angular2Apollo.subscribe()

Link to source: Angular2Apollo.subscribe()
Typedef: DeprecatedSubscriptionOptions

Cannot find module 'graphql'.

Hello,
I have the following error when executing ng serve Cannot find module 'graphql'.

[1] 165ms emitting
[1] Hash: f2607fb275930a4e8f84
[1] Version: webpack 2.1.0-beta.22
[1] Time: 24775ms
[1]            Asset       Size  Chunks             Chunk Names
[1]   main.bundle.js    3.52 MB    0, 2  [emitted]  main
[1] styles.bundle.js    10.2 kB    1, 2  [emitted]  styles
[1]        inline.js    5.53 kB       2  [emitted]  inline
[1]         main.map    3.75 MB    0, 2  [emitted]  main
[1]       styles.map    14.2 kB    1, 2  [emitted]  styles
[1]       inline.map    5.59 kB       2  [emitted]  inline
[1]       index.html  481 bytes          [emitted]  
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/QueryManager.d.ts:6:59 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/actions.d.ts:1:64 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/data/mutationResults.d.ts:2:64 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/data/readFromStore.d.ts:1:39 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/data/scopeQuery.d.ts:2:29 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/data/writeToStore.d.ts:2:39 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/errors.d.ts:1:29 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/index.d.ts:2:45 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/mutations/store.d.ts:2:29 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/networkInterface.d.ts:2:40 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/queries/getFromAST.d.ts:1:66 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/queries/queryTransform.d.ts:1:39 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/queries/store.d.ts:3:43 
[1] Cannot find module 'graphql'.
[1] 
[1] ERROR in [default] /Users/iguissouma/IdeaProjects/ng-boot/frontend/node_modules/apollo-client/watchQueryOptions.d.ts:1:45 
[1] Cannot find module 'graphql'.
[1] Child html-webpack-plugin for "index.html":
[1]          Asset     Size  Chunks       Chunk Names
[1]     index.html  2.82 kB       0       
[1] webpack: bundle is now VALID.

My frontend module is built with the latest version of angular-cli.
my package.json looks like below:

{
  "name": "frontend",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "concurrently \"npm run server\" \"npm run client\"",
    "client": "ng serve",
    "server": "nodemon api/index.js --watch api --exec babel-node",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "angular2-apollo": "^0.4.6",
    "apollo-client": "^0.4.15",
    "core-js": "^2.4.1",
    "graphql": "^0.7.0",
    "graphql-tag": "^0.1.14",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/isomorphic-fetch": "0.0.30",
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.38",
    "angular-cli": "1.0.0-beta.14",
    "apollo-server": "^0.2.8",
    "babel-cli": "^6.14.0",
    "babel-core": "^6.14.0",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-stage-2": "^6.13.0",
    "babel-register": "^6.14.0",
    "casual": "^1.5.5",
    "codelyzer": "~0.0.26",
    "concurrently": "^2.2.0",
    "cors": "^2.8.0",
    "express": "^4.14.0",
    "graphql": "^0.7.0",
    "graphql-tools": "^0.6.5",
    "graphql-typings": "0.0.1-beta-2",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "node-sass": "^3.8.0",
    "nodemon": "^1.10.2",
    "protractor": "4.0.5",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }
}

graphql module is present on node_modules, do yo have any idea what cause this error.
Thanks in advance.

Please bring back the decorator

Hey, could you please bring back the decorator? We have built a application using the decorator, but since you removed it, we can't upgrade to use the latest version of apollo...

The decorators are using the client but it's not injected

The client is an arg of the decorator but the anotation is outside the class, so the only way to use it is by actually importing the client. In Angular2 we do DI through the constructor of the app, so it would make more sense to have the annotation inside any of the class' member.

https://github.com/apollostack/angular2-apollo/blob/master/tests/apolloDecorator/queries.ts#L378

Unfortunately right now I don't have any suggestion to solve this, but at least it will be tracked.

Doesn't work with latest version of ngc compiler

So the latest version gives some warnings/errors when you try to use functions that return providers. The compiler isn't able to resolve that metadata.

Currently you import the module like: ApolloModule.withClient(client)
Which gives the error: UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function

Metadata is being dynamically created here: https://github.com/apollostack/angular2-apollo/blob/master/src/Angular2Apollo.ts#L17

Which would need to be changed to a FactoryProvider like you do with Http:

{
  provide: Http,
  deps: [XHRBackend, RequestOptions],
  useFactory: someFactory,
}

No way to get loading state of a query

In react-apollo, loading state of a query is extracted from the Redux store directly (I think - is this correct @jbaxleyiii?). This approach probably won't work with Angular 2.

So how can we make it accessible? Should we add an API to ApolloClient for this? Perhaps it should be in the results returned by the watchQuery observable?

Hello World: apollo-server module has been moved

In order to make the example work I've had to install apollo-server package and import apolloExpress from there and not apolloServer from graphql-tools as in the current code. If I didn't do this I would get some error stating that the apollo-server had been moved.

Invalid provider error (RC3)

Unsure if this is specific to Angular2 rc3, but I am getting an error:

Invalid provider - only instances of Provider and Type are allowed, got: [object Object]

This is using Webpack for what it is worth, but the code DID work in the past. The error is when bootstrapping the Apollo Client.

The redux way with ng2-redux

Could we implement a very similar version of the redux integration:
In the bootstrap

    let store = createStore(
        combineReducers(reducers),
        compose(
            applyMiddleware(apolloClient.middleware()),
            window.devToolsExtension ? window.devToolsExtension() : f => f
        )
    );

    let providers = [
        NgRedux,
        APOLLO_PROVIDERS,
        defaultApolloClient(apolloClient),
    ];

    enableProdMode();
    let ngComponentRef:ComponentRef = await bootstrap(App);
    let _ngRedux:NgRedux = ngComponentRef.injector.get(NgRedux);
    _ngRedux.provideStore(store);

In the component

@connect({
    mapStateToProps(state) {
         return {...};
    },
    mapQueryToProps() {
       return {...}
    }
})
@Component({...})
export class MyComponent {

}

Query's variables as Observables

import { Subject } from 'rxjs/Subject';

const name = new Subject();
const obs = client.watchQuery({
  query, 
  variables: {
    name
  }
});

obs.subscribe(result => {
  console.log(result);
});

name.next('Foo'); // rebuilds the query
name.next('Bar'); // rebuilds the query

Hello World: casual-browserify fails in Windows

I've been trying to run the example in Windows and I've had to change several things to make it work. I'm going to raise some issues in order to know if there's something that I'm missing or the repo has to be updated.

First problem that I have found is that casual-browserify seems to fail in Windows. I've submitted a PR in order to solve it.

Initialization docs recommend deprecated usage of createNetworkInterface as of client 0.5

Getting this error since updating: Passing the URI as the first argument to createNetworkInterface is deprecated as of Apollo Client 0.5. Please pass it as the "uri" property of the network interface options.

The docs reference a deprecated usage since client 0.5.0:

import ApolloClient, { createNetworkInterface } from 'apollo-client';

// by default, this client will send queries to `/graphql` (relative to the URL of your app)
const client = new ApolloClient({
  networkInterface: createNetworkInterface('http://my-api.grapql.com'),
});

Should be:

import ApolloClient, { createNetworkInterface } from 'apollo-client';

// by default, this client will send queries to `/graphql` (relative to the URL of your app)
const client = new ApolloClient({
  networkInterface: createNetworkInterface({
    uri: 'http://my-api.grapql.com'
  }),
});
```

Confusing import statement

First of all, great work with this initial draft of the apollo client! I look forward to using it as it matures. I started reading through the code today and I thought this import on the example page was a little confusing:
import {ApolloQueryPipe, APOLLO_ANGULAR2_PROVIDERS, ApolloAngular2} from "angular2-apollo";
It seems like APOLLO_ANGULAR2_PROVIDERS is being imported but not used, could you explain this to me or put in the README or the guide why it is important? I can see myself leaving it out if it is necessary. Also, I feel like the naming of ApolloAngular2 is a bit of a misnomer considering the package name is a slight inversion (ApolloAngular2 vs angular2-apollo). I think making these consistent by changing the import name or the package to apollo-angular2 would make using this package a little more intuitive.

Thanks and keep up the great work!

Hello World: schema needs to be of type GraphQLSchema

See #83, #84 and #85.

According to this changes I've got a new error stating that the schema had to be of type GraphQLSchema so I've changed the string into a valid GraphQL schema.

Note: I was tempted to do a PR with all this but I wasn't fully sure that this was a problem with the repo as I was under the impression that maybe there's something that I'm missing. Anyway, if you feel that a PR would be nice I would not have any problem with that.

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.