Calling GraphQL

GraphQL operates over HTTP, you can use any language, client library, or tool to fetch GraphQL data so long as you format the HTTP request properly.

cURL

Command line tool and library for transferring data with URLs

curl -X POST -H "Content-Type: application/json" \
  --data '{ "query": "{ myProfile { id program { name }}}" }' \
  -H "Authorization: Bearer {TOKEN}" \
  https://production.suggestic.com/graphql

Fetch

Fetcharrow-up-right module will enable you to use fetch in your Node code in a cross-browser compliant fashion. The Fetch API is part of the Web platform API defined by the standards bodies WHATWG and W3C.

require("isomorphic-fetch");

fetch("https://production.suggestic.com/graphql", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer {TOKEN}",
  },
  body: JSON.stringify({
    query: `
      {
        myProfile {
          id
          program {
            name
          }
        }
      }`,
  }),
})
  .then((res) => res.json())
  .then((res) => console.log(res.data));

Apollo Client

Apollo Clientarrow-up-right is a comprehensive state management library for JavaScript that enables you to manage both local and remote data with GraphQL. Use it to fetch, cache, and modify application data, all while automatically updating your UI.

PHP curl

Last updated

Was this helpful?