123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- const getGQL = url =>
- (query, variables) =>
- fetch(url , {
- method: 'POST',
- headers: {
- "content-type": "application/json"
- },
- body: JSON.stringify({query, variables})
- }).then(res => res.json())
- let gql = getGQL("http://shop-roles.asmer.fs.a-level.com.ua/graphql")
- async function categoryById(id) {
- let query = `query CategoryFind($id:String) {
- CategoryFind(query:$id) {
- name goods {
- name
- price
- description
- images {url}
- }
- }
- }`
-
- let variables = {"id": JSON.stringify([{ "_id": id }])} //or {"id": "[{\"_id\":\"id\"}]"}
-
- let res = await gql(query, variables)
- console.log(res)
- return res
- }
- categoryById("5dc458985df9d670df48cc47")
- async function goodById(id) {
- let query = `query GoodFind($id:String) {
- GoodFind(query:$id) {
- categories {
- _id
- name
- }
- name
- price
- description
- createdAt
- images {url}
- }
- }`
- let variables = {"id": JSON.stringify([{ "_id": id }])} //or {"id": "[{\"_id\":\"id\"}]"}
-
- let res = await gql(query, variables)
- console.log(res)
- return res
- }
- goodById("5e203b5456d8f720513e6cba")
- async function goodFind() {
- let query = `query GoodFind($q:String) {
- GoodFind(query:$q) {
- categories {
- _id
- name
- }
- _id
- name
- price
- description
- createdAt
- images {url}
-
- }
- }`
-
- let variables = {"q": JSON.stringify([{}])} //or {"q": "[{}]"}
-
- let res = await gql(query, variables)
- console.log(res)
- return res
- }
- goodFind()
- async function categoryFind() {
- let query = `query CategoryFind($q:String) {
- CategoryFind(query:$q) {
- _id
- name
- createdAt
- goods {
- _id
- name
- price
- createdAt
- }
- }
- }`
-
- let variables = {"q": JSON.stringify([{}])} //or {"q": "[{}]"}
-
- let res = await gql(query, variables)
- console.log(res)
- return res
- }
- categoryFind()
|