Start with a schema
A GraphQL API proxy operates based on the GraphQL query language specification. GraphQL provides a flexible and efficient approach to API development by allowing clients to request exactly the data they need, nothing more and nothing less.
Unlike traditional REST APIs that require multiple endpoints for different resources, GraphQL uses a single endpoint and a type system to define the API's capabilities. This enables clients to compose complex queries that fetch related data in a single request, reducing over-fetching and under-fetching of data. GraphQL is ideal for applications that need flexible data fetching and efficient data aggregation.
This walks you through creating a GraphQL API using a sample GraphQL schema, deploying it to a gateway, testing it, and publishing it to a portal.
Prerequisites
- Go to the API Control Plane and sign in with Google or GitHub.
- Open your organization, then select the Default Project or create a new project.
Create the API
-
On the project home page, click Create API.
-
Select GraphQL API, and keep Start with a schema, which is selected by default.
-
Provide the schema in one of these ways:
-
URL: Select URL, enter the Schema URL, or click Try with Sample Schema. The sample URL is:
https://raw.githubusercontent.com/graphql/swapi-graphql/master/schema.graphqlWait until validation finishes.
-
Upload: Select Upload, then drag and drop a file or click to select one. Accepted file types are
.graphql,.gql, and.json.
-
-
Click Continue.
-
On Configure and create, review Basic information and Endpoint. For the sample schema URL, the console fills in:
Field Value Name RawIdentifier rawVersion 1.0Context /raw/v1.0/graphqlDescription Optional. The console leaves it empty. Query and Mutation URL Enter the backend URL that serves queries and mutations. -
Click Create.
Deploy the API
Deploying places a build of the API on a gateway so requests can reach the backend through that gateway.
- Choose a gateway. Your organization has a cloud gateway named Default, in the development environment. To deploy to another gateway, create it first. See Manage Gateways.
- Go to the Deploy section and deploy the API to the gateway. For more information, see Deploy an API.
Test the API
After deploying the API, test its operations to verify that requests can be sent through the gateway.
- In the left navigation menu, click Test.
- Use the GraphQL Console to execute queries against the deployed API and inspect the responses.
For more information, see the GraphQL Console guide.
Publish the API
Publishing makes the API available to developers through a portal, where they can discover the API and access its documentation.
- Create a portal first if the organization does not have one. See Manage Portals.
- Publish the API. See Publish an API.
Next Steps
- Security - Control who can invoke the API
- Attach and Manage Policies - Add capabilities such as rate limiting or header changes to the API
- Documents - Add documents that help consumers use the API
Was this page helpful?