1fetch('https://www.learnwithjason.dev/graphql', {
2 method: 'POST',
3 headers: {
4 'Content-Type': 'application/json',
5 },
6 body: JSON.stringify({
7 query: `
8 query GetLearnWithJasonEpisodes($now: DateTime!) {
9 allEpisode(limit: 10, sort: {date: ASC}, where: {date: {gte: $now}}) {
10 date
11 title
12 guest {
13 name
14 twitter
15 }
16 description
17 }
18 }
19 `,
20 variables: {
21 now: new Date().toISOString(),
22 },
23 }),
24})
25 .then((res) => res.json())
26 .then((result) => console.log(result));
27
1const query = `
2query {
3 questions {
4 id
5 code
6 content
7 }
8 }
9`,
10 url = "https://....com/graphql", //your url Endpoint
11 datas= [],
12 opts = {
13 method: "POST",
14 headers: {
15 'Content-Type': 'application/json',
16 'Accept': 'application/json',
17 },
18body: JSON.stringify({ query })
19};
20fetch(url, opts)
21 .then(r => r.json())
22 .then(({ data }) => (document.getElementById('id_3').innerHTML = data.questions
23 .map(r => `
24 <p>your data ${r.data}</p>
25 `)
26 .join()
27 ))