Skip to content

Instantly share code, notes, and snippets.

View mugan86's full-sized avatar
💻
💪💪

Anartz Mugika Ledo mugan86

💻
💪💪
View GitHub Profile
@mugan86
mugan86 / gist:9fe965156b465c9c11cd77346caa3bc8
Last active November 10, 2018 06:08
Detect changes in VS Code when I work in Typescript proyects
1. Run tsc --init in your project folder to create tsconfig.json file (if you don't have one already).
2. Press Ctrl+Shift+B to open a list of tasks in VS Code and select tsc: watch - tsconfig.json.
3. Done! Your project is recompiled on every file save.
You can have several tsconfig.json files in your workspace and run multiple compilations at once if you want (e.g. frontend and backend separately).
@mugan86
mugan86 / constants.js
Created September 11, 2019 05:50
Add queries to work with queries in GraphQL from Javascript
module.exports = {
apiUrl: 'https://breaking-bad-voting.herokuapp.com/graphql',
queries: {
getCharacters: `{
characters {
id
name
actor
total_episodes
}
@mugan86
mugan86 / gist:27b5adaee2c5efe9310c7f7dd25b3c15
Created September 11, 2019 05:56
queries/axios.js para obtener info de API GraphQL
const axios_ = require('axios');
const apiUrl = require('./../constants').apiUrl;
const queries = require('./../constants').queries;
axios_.post(apiUrl, {
query: queries.getCharacters
})
.then((res) => {
console.log('--------------------- Lista de Personajes --------------------------')
console.log(res.data)
@mugan86
mugan86 / result-axios.js
Created September 11, 2019 05:58
Resultado de la ejecución desde JS a API GraphQL
iMac-de-Anartz:queries anartz$ node axios.js
--------------------- Lista de Personajes --------------------------
{ data:
{ characters:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
{
"data": {
"characters": [
{
"id": "1",
"name": "Walter White",
"total_episodes": 62
},
{
"id": "2",
@mugan86
mugan86 / request-in-terminal.txt
Created September 11, 2019 06:05
Respuesta de axios en consola
--------------------- Lista de Personajes --------------------------
[ { id: '1',
name: 'Walter White',
actor: 'Bryan Cranston',
total_episodes: 62 },
{ id: '2',
name: 'Jesse Pinkman',
actor: 'Aaron Paul',
total_episodes: 62 },
{ id: '3',
@mugan86
mugan86 / walter-white-info.js
Created September 11, 2019 07:15
Información del personaje Walter White cuyo id es "1"
axios_.post(apiUrl, {
query: queries.getCharacterWalter
})
.then((res) => {
console.log('--------------------- Información de Walter White - ID = 1 --------------------------')
console.log(res.data)
})
.catch((error) => {
console.error(error)
});
@mugan86
mugan86 / result-walter-white.txt
Created September 11, 2019 07:18
Resultado para obtener info de Walter White
--------------------- Información de Walter White - ID = 1 --------------------------
{ id: '1', name: 'Walter White', total_episodes: 62, votes: 164 }
@mugan86
mugan86 / respuesta-completa
Created September 11, 2019 07:20
Walter White todo la data
{ data:
{ character:
{ id: '1', name: 'Walter White', total_episodes: 62, votes: 164 } } }
@mugan86
mugan86 / uso-query-variables.js
Created September 11, 2019 07:23
Obtener la información pasando el ID mediante Query Variables
axios_.post(apiUrl, {
query: queries.getSelectCharacter,
variables: { id: '2'}
})
.then((res) => {
const character = res.data.data.character;
console.log(`Personaje seleccionado ID ${character.id} - ${character.name}`)
console.log(character)
})
.catch((error) => {