All Projects → apollographql → Angular1 Apollo

apollographql / Angular1 Apollo

Licence: mit
AngularJS integration for the Apollo Client

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angular1 Apollo

Kikstart Graphql Client
🚀 Small NodeJS Wrapper around apollo-client that provides easy access to running queries, mutations and subscriptions.
Stars: ✭ 27 (-75%)
Mutual labels:  graphql, apollo-client, graphql-client
Apollo Client
🚀  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
Stars: ✭ 17,070 (+15705.56%)
Mutual labels:  graphql, apollo-client, graphql-client
Apollo Link
🔗 Interface for fetching and modifying control flow of GraphQL requests
Stars: ✭ 1,434 (+1227.78%)
Mutual labels:  graphql, apollo-client, graphql-client
Apollo Angular
A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
Stars: ✭ 1,058 (+879.63%)
Mutual labels:  graphql, apollo-client, graphql-client
Locksmith
Want to use GraphQL with Clojure/script but don't want keBab or snake_keys everywhere? Use locksmith to change all the keys!
Stars: ✭ 59 (-45.37%)
Mutual labels:  graphql, graphql-client
Guide To Graphql
A Frontend Developer's Guide to GraphQL (Fluent Conf 2018)
Stars: ✭ 59 (-45.37%)
Mutual labels:  graphql, apollo-client
Guide
📖 The GraphQL Guide website
Stars: ✭ 104 (-3.7%)
Mutual labels:  graphql, apollo-client
Artemis Dev Tool
An Apollo GraphQL Query Schema Testing Tool
Stars: ✭ 66 (-38.89%)
Mutual labels:  graphql, apollo-client
A Pop
🎶 HD Music Streaming and Sharing Web App
Stars: ✭ 55 (-49.07%)
Mutual labels:  graphql, apollo-client
Android Okgraphql
Reactive GraphQl client for Android
Stars: ✭ 64 (-40.74%)
Mutual labels:  graphql, graphql-client
Apollo Cache Invalidation
Experimental cache invalidation tools for Apollo.
Stars: ✭ 66 (-38.89%)
Mutual labels:  graphql, apollo-client
Graphql Apollo Next.js
A server-rendering GraphQL client with Apollo Client and Next.js
Stars: ✭ 59 (-45.37%)
Mutual labels:  graphql, apollo-client
Starter
Opinionated SaaS quick-start with pre-built user account and organization system for full-stack application development in React, Node.js, GraphQL and PostgreSQL. Powered by PostGraphile, TypeScript, Apollo Client, Graphile Worker, Graphile Migrate, GraphQL Code Generator, Ant Design and Next.js
Stars: ✭ 1,082 (+901.85%)
Mutual labels:  graphql, apollo-client
Github Graphql React
A Github client built with React / GraphQL 💻👩‍💻💽 👨‍💻
Stars: ✭ 60 (-44.44%)
Mutual labels:  graphql, apollo-client
Blaze Apollo
Blaze integration for the Apollo Client
Stars: ✭ 56 (-48.15%)
Mutual labels:  graphql, apollo-client
Cynthesize Frontend
Frontend written in Angular 7 and deployed GraphQL for Cynthesize. Development build: https://cynthesize-develop.netlify.com
Stars: ✭ 65 (-39.81%)
Mutual labels:  graphql, apollo-client
Apollo Client Devtools
Apollo Client browser developer tools.
Stars: ✭ 1,210 (+1020.37%)
Mutual labels:  graphql, apollo-client
Apollo Upload Client
A terminating Apollo Link for Apollo Client that allows FileList, File, Blob or ReactNativeFile instances within query or mutation variables and sends GraphQL multipart requests.
Stars: ✭ 1,176 (+988.89%)
Mutual labels:  graphql, apollo-client
Realm Graphql
GraphQL client for Realm Object Server
Stars: ✭ 79 (-26.85%)
Mutual labels:  graphql, apollo-client
Apollo Link Webworker
Apollo link that lets you use graphql client-side only, with a webworker as a "server" supporting normal queries and subscriptions
Stars: ✭ 88 (-18.52%)
Mutual labels:  graphql, apollo-client

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 AngularApollo from 'angular1-apollo';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';

angular.module('app', [AngularApollo]).config(apolloProvider => {
  const client = new ApolloClient({
    link: HttpLink.create(...),
    cache: new InMemoryCache(...),
  });

  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);
    });
});

Static Typing

As your application grows, you may find it helpful to include a type system to assist in development. Apollo supports type definitions for TypeScript system. Both apollo-client and angular1-apollo ship with definitions in their npm packages, so installation should be done for you after the libraries are included in your project.

Operation result

The most common need when using type systems with GraphQL is to type the results of an operation. Given that a GraphQL server's schema is strongly typed, we can even generate TypeScript definitions automatically using a tool like apollo-codegen. In these docs however, we will be writing result types manually.

Since the result of a query will be sent to the component or service, we want to be able to tell our type system the shape of it. Here is an example setting types for an operation using TypeScript:

type Hero = {
  name: string;
  power: string;
};

type Response = {
  heros: Hero[];
};

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

Without specyfing a Generic Type for Apollo.query, TypeScript would throw an error saying that hero property does not exist in result.data object (it is an Object by default).

Options

To make integration between Apollo and Angular even more statically typed you can define the shape of variables (in query, watchQuery and mutate methods). Here is an example setting the type of variables:

type Hero = {
  name: string;
  power: string;
};

type Response = {
  hero: Hero;
};

type Variables = {
  name: string;
};

angular.module('app').controller('AppCtrl', apollo => {
  apollo
    .query<Response, Variables>({
      mutation: gql`
        query getHero($name: String!) {
          hero(name: $name) {
            name
            power
          }
        }
      `,
      variables: {
        name: 'Batman',
        appearsIn: 'Star Wars', // will throw an error because `appearsIn` does not exist
      },
    })
    .then(result => {
      console.log(result.data.hero); // won't throw an issue
    });
});

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].