|
@@ -0,0 +1,62 @@
|
|
|
+const gql = function (url) {
|
|
|
+ console.log(url)
|
|
|
+return async function (query, variables = {}){
|
|
|
+ try {
|
|
|
+ fetch(url, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ },
|
|
|
+ body: JSON.stringify({query, variables}),
|
|
|
+ })
|
|
|
+ .then(response => response.json())
|
|
|
+ .then(({data}) => console.log(data[Object.keys(data)]))
|
|
|
+ return data[Object.keys(data)];
|
|
|
+ }catch (error){
|
|
|
+ console.log(`Проверься ${error}`)
|
|
|
+ }
|
|
|
+}
|
|
|
+}
|
|
|
+
|
|
|
+const url = gql(`http://shop-roles.asmer.fs.a-level.com.ua/graphql`);
|
|
|
+
|
|
|
+(async () => {
|
|
|
+ console.log(await url(`query cats{
|
|
|
+ CategoryFind(query:"[{}]"){
|
|
|
+ name goods{
|
|
|
+ name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`))
|
|
|
+})();
|
|
|
+
|
|
|
+// const getGQL = function (url) {
|
|
|
+// return async function (query, variables) {
|
|
|
+//
|
|
|
+// try {
|
|
|
+// fetch(url, {
|
|
|
+// method: 'POST',
|
|
|
+// headers: {
|
|
|
+// 'Content-Type': 'application/json'
|
|
|
+// },
|
|
|
+// body: JSON.stringify({query, variables})
|
|
|
+//
|
|
|
+// }).then((response) => response.json())
|
|
|
+// .then(({data}) => {
|
|
|
+// console.log({...data})
|
|
|
+// return {...data}
|
|
|
+// })
|
|
|
+// } catch (error) {
|
|
|
+// alert(error)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// const gql = getGQL(`http://shop-roles.asmer.fs.a-level.com.ua/graphql`);
|
|
|
+//
|
|
|
+// (async () => {
|
|
|
+// await gql(` query NameForMe1($login:String, $password:String){
|
|
|
+// login(login:$login, password:$password)
|
|
|
+// }`, {login: 'tst', password: '123'});
|
|
|
+// })();
|
|
|
+//
|