
Enabling the cost endpoint for a GraphQL API
If you enable the /graphql/cost
endpoint when creating a GraphQL proxy
API, a calling application can obtain details of the cost of executing a request on the backend
GraphQL server before making the actual backend request.
The cost
does not relate purely to monetary cost but can take into account factors such as
computational time, memory consumption, and other such factors, in addition to the actual financial
costs associated with, say, using third-party systems to retrieve data.
In a production environment, in particular, you should consider carefully the resource
implications of making this path available. Note, however, that enabling the
/graphql/cost
endpoint automatically generates policy configuration in your API
assembly that would have to be created manually if you disable this option and later decide that it
is required; see the API assembly policies for the cost endpoint
section for details.
API assembly policies for the cost endpoint
This section details the API assembly policy configuration that is generated automatically if the
/graphql/cost
operation path is selected when a GraphQL proxy API is created. If
the path is not selected at creation time, and you later decide that you want to enable it, you must
add it manually to the API assembly.
case
is added to a switch
policy with the following
condition:($operationPath() = '/graphql/cost' and message.attributes.parse.GraphQLIntrospection = 'not-introspection')
- Rate limit
-
Property Value Source Plan by Name Rate Limit Name graphql-design-request Operation Consume - Validate
-
Property Value Input message Output No value, defaults to input Validate against GraphQL - Set Variable
-
Property Value Action Set Set message.body Type any Value $(message.attributes.graphql)
