Skip to content

Angular integration for the Apollo Client

License

Notifications You must be signed in to change notification settings

bluecloudy/angular1-apollo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular1-apollo

npm version Get on Slack bitHound Overall Score

Use your GraphQL server data in your Angular 1.0 app, with the Apollo Client.

Install

npm install angular1-apollo apollo-client --save

API

angular.module('app', [
  'angular-apollo'
])

Default client

ApolloProvider.defaultClient

import ApolloClient from 'apollo-client';

angular.module('app', [
  'angular-apollo'
]).config((apolloProvider) => {
  const client = new ApolloClient();

  apolloProvider.defaultClient(client);
});

Queries

Apollo.query(options): Promise

See documentation

import gql from 'graphql-tag';

angular.module('app')
  .controller('AppCtrl', (apollo) => {
    apollo.query({
      query: gql`
        query getHeroes {
          heroes {
            name
            power
          }
        }
      `
    }).then(result => {
      console.log('got data', result);
    });
  });

Mutations

Apollo.mutate(options): Promise

See documentation

import gql from 'graphql-tag';

angular.module('app')
  .controller('AppCtrl', (apollo) => {
    apollo.mutate({
      mutation: gql`
        mutation newHero($name: String!) {
          addHero(name: $name) {
            power
          }
        }
      `,
      variables: {
        name: 'Batman'
      }
    }).then(result => {
      console.log('got data', result);
    });
  });

Development

This project uses TypeScript for static typing and TSLint for linting. You can get both of these 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.

About

Angular integration for the Apollo Client

Resources

License

Stars

Watchers

Forks

Packages

No packages published