Skip to content

Instantly share code, notes, and snippets.

@vitorpiovezam
Created August 7, 2019 23:17
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 vitorpiovezam/ffbbf3a4960ca414c3b81367c98c0165 to your computer and use it in GitHub Desktop.
Save vitorpiovezam/ffbbf3a4960ca414c3b81367c98c0165 to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { Apollo } from 'apollo-angular'
import gql from 'graphql-tag'
/*
Apollo is needed to bring Apollo class to the constructor
gql is a lib to create larger strings - our queries - and permit
vscode syntax-highlight
*/
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent {
title = 'graphcool-chat';
constructor(private apollo: Apollo){
this.createUser('Vitor','vitorpiovezam@yandex.com','123456789');
this.allUsers();
}
allUsers(): void{
let count = 0;
}
// Get Users
allUsers() {
this.apollo.mutate({
mutation: gql`
query allUsers {
allUsers {
id
name
}
}
`
}).subscribe(res => console.log(res));
}
// Mutation Sample
async createUser(name,email,password){
this.apollo.mutate({
mutation: gql`
mutation CreateNewUser($name: String!, $email: String!, $password: String!){
createUser(name: $name, email: $email, password: $password){
id,
name,
email,
}
}
`,
variables:{
name: name,
email: email,
password: password
}
}).subscribe(res => console.log(res));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment