You can make requests to the TakeShape GraphQL API from your project endpoint:
You can find your project's ID in its URL. When inside your project, the ID follows after
You can find and copy your project's API endpoint from the left sidebar within the API section.
Your request should include the API key you created as a Bearer Token.
For a simple request using
fetch set the body of the request as a stringified object with the
query key containing
the GraphQL query.
The response will look like this:
When you're making GraphQL requests from client-side code, you're exposing your API key to the world. Make sure you only use read-only permissions on keys you intend to use in queries from the browser.
When you create a shape with built-in data storage, TakeShape automatically creates queries for getting results.
Here's an example of a query for books and for authors, from a project using our Shape Books pattern:
As you can see, with GraphQL we're able to get data about books and authors at the same time. Additionally, for each book we get a little information about its author, and for each author we get a little information about the books they've written.
TakeShape's automatically-generated queries support pagination with the
size arguments and
from- The offset to start from.
size- The maximum number of items to return.
sizeis limited to 100.
total- The total number of items matching your search criteria.
With these three values, you can generate and navigate pages of your responses.
Automatically-generated queries also support two approaches to filtering using the
terms argument will filter results that match the provided string in any of their text fields.
where argument allows for more complex filters that can also be combined using the boolean
sort argument to order the results of TakeShape's automatically generated queries. It takes the name of a
field to sort by and an
asc for ascending ordering or
desc for descending ordering.
TakeShape also automatically creates mutations for creating, duplicating, updating, and deleting records for shapes that use built-in data storage.
Mutations must use the
mutation keyword at the beginning of their query and data as an
input argument. When
duplicating, updating or deleting a record, the input should contain the
_id for the record you'd like to operate on.
When creating a new record, you don't need to provide a unique id—one will be generated for you.
These built-in mutations will resolve with the created, duplicated, or updated record, allowing you to query their data as result of a successful mutation. When deleting records, the result will be a boolean indicating success.
If you receive a 429 error you are bumping into a rate limit. 429 means "Too Many Requests". You can use the following HTTP response headers to tune requests to the API.
X-RateLimit-Limit - How many API requests you can make per second. Your limit is measured over a 60 second window.
X-RateLimit-Remaining - How many API requests are remaining in the window.
X-RateLimit-Reset - When the rate limit window resets.