Use your GraphQL server data in your Angular 1.0 app, with the Apollo Client.
npm install angular1-apollo apollo-client --save
angular.module('app', [
'angular-apollo'
])
import AngularApollo from 'angular1-apollo'
import ApolloClient from 'apollo-client';
angular.module('app', [
AngularApollo
]).config((apolloProvider) => {
const client = new ApolloClient();
apolloProvider.defaultClient(client);
});
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);
});
});
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);
});
});
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.