About this task
Let’s look at a sample scenario, where you are creating a GraphQL API, Star
Wars API, by importing an API from URL.
Before you begin
Ensure that you have:
- Manage APIs or Activate/Deactivate APIs functional privilege. If
you are an Administrator, you would have this privilege by default.
- A GraphQL API base URL to create an API using the importer. For example, you can use the
base URL
https://raw.githubusercontent.com/graphql/swapi-graphql/master/schema.graphql.
To create a GraphQL API by importing an API from URL
Procedure
-
Click APIs in the title navigation bar.
-
Click Create API.
-
Select Import API from URL.
-
Provide the URL as
https://raw.githubusercontent.com/graphql/swapi-graphql/master/schema.graphql.
-
Select Protected to make the API a protected API and provide the
Username and Password.
-
Provide a description for the API in the Description
field.
-
Type a name for the API name in the Name field. For
example, Starwars_GraphQL_URL.
-
Select GraphQL SDL from the Type dropdown
menu
-
Provide the version number as 1.0 in the Version field.
-
Select the team as Administrator for which you want to assign
the API in the Team field
This field appears only when the Team feature is enabled. It displays only the teams
that you are a part of.
-
Click Create.
A GraphQL API is created with the default Straight Through Routing policy.
-
Click Edit to replace the Endpoint URI of the Straight Through
Routing policy.
For the API to work, you must replace the Endpoint URI of the default Straight Through
Routing policy with the query string of the native API.
-
Navigate to Policies > Routing >
Straight Through Routing and replace the
${sys:query_string} alias in the Endpoint URI with the query string of the
native API.
Here, use the native API endpoint of the Star Wars API, that is,
https://swapi-graphql.netlify.app/.netlify/functions/index.
-
Click Activate.
-
Click Yes in the confirmation dialog box.
The API is now activated. The API Gateway endpoint is now available, and consumers can
use this endpoint to invoke the API.
What to do next
Next Steps
Now that you have created the REST API, you must