GraphQL API is a tool that allows you to retrieve exactly the data you need using more specific and flexible queries. One of the main benefits of GraphQL API is that you can get many different resources using a single request.
For cases when you want to run queries against the Crowdin GraphQL API, we recommend using the GraphQL Playground app, with the help of which you can build, test and debug queries from Crowdin Enterprise web UI even before writing any code in your application.
To work with GraphQL API in Crowdin Enterprise, use one of the following access tokens:
Ensure to use the following header in your requests:
Authorization: Bearer <ACCESS_TOKEN>
The response in case authorization fails:
401 Unauthorized
{
"error": {
"message": "Unauthorized",
"code": 401
}
}
In contrast to the REST API, GraphQL API has only one endpoint that remains constant, not depending on the performed operations.
GraphQL endpoint:
https://{domain}.api.crowdin.com/api/graphql
The Crowdin GraphQL API has limitations to prevent excessive or abusive calls to Crowdin servers.
All GraphQL API calls must comply with the following requirements to pass schema validation:
first
or last
argument on any connection.first
and last
must be within 1-10,000.In the following examples, you can check out how the nodes in a call are calculated.
Simple query:
query {
viewer {
projects(first: 50) {
edges {
node {
name
files(first: 10) {
totalCount
edges {
node {
name
type
}
}
}
}
}
}
}
}
Calculation:
50 = 50 projects
+
50 x 10 = 500 files
= 550 total nodes
Complex query:
query {
viewer {
projects(first: 50) {
edges {
node {
files(first: 20) {
edges {
node {
strings(first: 10) {
edges {
node {
... on PlainSourceString {
text
}
... on ICUSourceString {
text
}
... on PluralSourceString {
plurals {
one
other
}
}
... on AssetSourceString {
text
}
}
}
}
}
}
}
translations(first: 20, languageId: "uk") {
edges {
node {
... on PlainStringTranslation {
text
}
... on ICUStringTranslation {
text
}
... on PluralStringTranslation {
pluralForm
text
}
... on AssetStringTranslation {
text
}
}
}
}
}
}
}
}
}
Calculation:
50 = 50 projects
+
50 x 20 = 1,000 files
+
50 x 20 x 10 = 10,000 strings
+
50 x 20 = 1,000 translations
= 12,050 total nodes
The GraphQL API limit is quite different compared to the rate limits set for REST API.
As mentioned above, you can get the same amount of data using only one GraphQL call and replacing the need to execute multiple REST calls. While a single complex GraphQL call could be equivalent to thousands of REST requests and wouldn’t exceed the REST API rate limit, its computation might be just as expensive for Crowdin servers.
The GraphQL API uses a normalized point scale to precisely depict the server cost of a query by calculating a call’s rate limit score. This score includes the first and last arguments on a parent connection and its children.
first
and last
arguments on a parent connection and its children to pre-determine the possible load on Crowdin systems, such as MySQL and ElasticSearch.The GraphQL API rate limit is set to 5,000 points per hour. Since the GraphQL API and REST API use different rate limits, 5,000 points per hour aren’t the same as 5,000 calls per hour.
To check the rate limit status when using GraphQL API, query the fields on the rateLimit
object:
query {
viewer {
username
}
rateLimit {
limit
cost
remaining
resetAt
}
}
limit
– returns the maximum number of points the user is allowed to consume in a 60-minute window.cost
– returns the point cost for the current call that counts against the rate limit.remaining
– returns the number of points remaining in the current rate limit window.resetAt
– returns the time at which the current rate limit window resets in UTC epoch seconds.While querying the rateLimit
object can give you a call’s score, it counts against the limit. To work around this situation, you can estimate the score of a call in advance. Using the following calculation, you can get approximately the same cost as returned by rateLimit { cost }
.
first
or last
argument limits.Here’s an example query and score calculation:
query {
viewer {
username
projects(first: 100) {
edges {
node {
id
files(first: 50) {
edges {
node {
id
strings(first: 60) {
edges {
node {
... on PlainSourceString {
id
text
}
... on ICUSourceString {
id
text
}
... on PluralSourceString {
id
plurals {
one
other
}
}
... on AssetSourceString {
id
text
}
}
}
}
}
}
}
}
}
}
}
}
Now, divide the total of 5,101 by 100 and round it. As a result, you get the final score of the query, which is 51.