...
/Executing a GraphQL Query Using Apollo Client
Executing a GraphQL Query Using Apollo Client
In this lesson, you will learn how to send a query to GitHub’s GraphQL API using Apollo Client.
We'll cover the following...
Now we are going to send our first query to GitHub’s GraphQL API using Apollo Client. First of all, we will import the following utility from Apollo Boost to define the query:
Press + to interact
import 'cross-fetch/polyfill';import ApolloClient, { gql } from 'apollo-boost';
Next, we will define our query with JavaScript template literals:
Press + to interact
...const GET_ORGANIZATION = gql`{organization(login: "the-road-to-learn-react") {nameurl}}`;
Now, we use the Apollo Client imperatively to send the query to GitHub’s GraphQL API. Since the Apollo Client is promise-based, the query()
method returns a promise that you can eventually resolve. It’s sufficient ...