1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <header>GQL</header>
- <body>
- <script>
- function gql(url, query, vars) {
- let fetchSettings =
- {
- method: "POST",
- headers:
- {
- "Content-Type": "application/json",
- "Accept": "application/json"
- },
- body: JSON.stringify(
- {
- query: query,
- variables: vars
- })
- };
- return fetch(url, fetchSettings).then(res => res.json());
- }
- /*
- let query =
- `
- query myGoodFind($where:String){
- GoodFind(query:$where){
- _id name
- }
- }
- `;
- let vars =
- {
- "where": '[{"name":"/alax/"}]'
- };
- gql("http://shop-roles.node.ed.asmer.org.ua/graphql", query, vars)
- .then(res => console.log(JSON.stringify(res, null, 4)));
- */
- async function test() {
- async function test1() {
- const catQuery = `query cats($q: String){
- CategoryFind(query: $q){
- _id name
- }
- }`;
- const cats = await gql("http://shop-roles.node.ed.asmer.org.ua/graphql", catQuery, { q: "[{}]" });
- console.log(cats); //список категорий с _id name и всем таким прочим
- const loginQuery = `query login($login:String, $password:String){
- login(login:$login, password:$password)
- }`;
- const token = await gql("http://shop-roles.node.ed.asmer.org.ua/graphql", loginQuery, { login: "Berg", password: "123456789" });
- console.log(token);
- }
- await test1();
- }
- test();
- </script>
- </body>
|