fetch graphql with curl

sangwoo noh·2022년 4월 7일
0

info

목록 보기
8/14

어쩌다가?

  • api 설명서를 만들어달라고 해서...

query

curl \
  -X POST \
  -H "x-api-key: xxx-xxxx" \
  -H "Content-Type: application/json" \
  -d '{ "query": "query { listUsers { name } }" }' \
  https://localhost:5000/graphql

mutation with variables

curl \
  -X POST \
  -H "x-api-key: xxx-xxxx" \
  -H "Content-Type: application/json" \
  -d '{ "query": "mutation($user: UserInput!) { createUser(user: $user) { name location id } }" ,
        "variables": {
          "user": {
            "name": "Nader Dabit",
            "location": "United States",
            "id": "001"
          }
        }
      }' \
  https://localhost:5000/graphql

with Axios

const getLoginData = async () => {
  const query = `
    mutation loginEmail($email: String!, $passwd: String!) {
      loginEmail(email: $email, passwd: $passwd) {
        ok
        token
        error
        isConfirmed
      }
    }
  `
  const variables = { email: 'test@test.com', passwd: 'test12!!!' }
  const headers = { 'Content-Type': 'application/json' }

  const loginEmailData = await axios.post('http://localhost:8000/graphqlsandbox', {
    query,
    variables,
    headers,
  })
  console.log('get loginEmailData: ', loginEmailData)
}
profile
하기로 했으면 하자

0개의 댓글