graphql-request is a simple & lightweight GraphQL client.
superplate comes with optional graphql-request feature plugin. We'll show basic usage of graphql-request with SpaceX-API.
We'll define the shape of the query we'll use to fetch
launchesPast from SpaceX-API.
Since we are using TypeScript in the project, also import the necessary types that are generated from SpaceX-API schema definitions:
To generate the types automatically we use graphql-code-generator and need to set configs in
Then run the following command which is defined in package.json.
Running this command will generate types into
__generated__ folder in project root directory automatically.
All this work will be handled automatically by CLI, so you don’t need to do anything extra as long as you choose graphql-request feature plugin during the project creation phase.
If you want to add graphql-request to your existing project first install the dependencies