Created
February 12, 2020 14:57
-
-
Save lindenmelvin/6f201b569d17859b0e37b40e3c7cc5c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
axios.defaults.baseURL = "http://localhost:4000/"; | |
const login = async (email, password) => { | |
const axiosResponse = await axios.post('/', { | |
query: `mutation Login { | |
login(email: "${email}", password: "${password}") { | |
token | |
} | |
}` | |
}); | |
const graphqlQueryData = axiosResponse.data; | |
const authenticationToken = graphqlQueryData.data.login.token; | |
axios.defaults.headers.common['Authorization'] = `Bearer ${authenticationToken}`; | |
} | |
const posts = async () => { | |
const axiosResponse = await axios.post('/', { | |
query: `query FetchPosts { | |
posts { | |
title | |
} | |
}` | |
}); | |
const graphqlQueryData = axiosResponse.data; | |
const posts = graphqlQueryData.data.posts; | |
return posts; | |
} | |
const main = async () => { | |
await login("foo@example.com", "bar"); | |
await posts(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment