Fetch 문법 간단 정리

created : 2020-04-07T11:22:29+00:00
modified : 2020-04-08T03:49:10+00:00

Basic Usage

const queryData = {
	query:`
query {
  hello,
  persons {
    name,
  }
}`
};
const headers = new Headers({
  "Accept" : "application/json",
  "Content-Type" : "application/json"
});

const fetchPromise = fetch('/graphql', {
    headers,
    method: "POST",
    body: JSON.stringify(queryData),
});

fetchPromise
	.then(response => response.clone().json()) // avoid reponse lock
	.then(data => console.log);