GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.source: GraphQL Foundation website
Open(Keyless)
, but that option is not advised for production APIs. See Client Authentication for more details on securing your API.Authorization
./api/apis
endpoint to see what APIs are loaded
/trevorblades
. Using this path-based-routing, the gateway was able to identify the API the client intended to target.
The gateway stripped the listen path and reverse-proxied the request to https://countries.trevorblades.com/
api.trevorblades.json
file we just created, and modify a couple of fields to enable authentication.
Change use_keyless
from true
to false
.
Change auth_configs.authToken.auth_header_name
to apikey
.
Then send a PUT
request back to Tyk Dashboard to update its configurations.
/apps
folder of the Tyk Gateway installation folder. This is demonstrated in the file-based configuration section.
tyk.conf
file, the property is called secret
, you will need to use this as a header called x-tyk-authorization
to make calls to the Gateway API.
apis
endpoint, which will return the status and version of your Gateway. Change the x-tyk-authorization
value and curl
domain name and port to be the correct values for your environment.
This example API definition configures the Tyk Gateway to reverse proxy to the https://countries.trevorblades.com/ public GraphQL service.
To view the raw API definition object, you may visit: https://bit.ly/3nt8KDa
/apis
endpoint. API definitions are discussed in detail in the API section of this documentation. These objects encapsulate all of the settings for an API within Tyk Gateway.
/trevorblades/
.
Your GraphQL API is now ready to use. We recommend securing any GraphQL API before publishing it.
Check the following docs for more on GraphQL-specific security options:
balance
field on type Account
, the gateway will respond with:
interface
. With this query you can get a list of objects that implements a specific interface
.
enum
type defines a set of discrete values. With this query you can get a complete list of those values for a chosen enum
.
Query
in the schema. You can use the below introspection query to find out more about a query operations of the graph.
Query
type is called QueryRoot
. In those cases the above introspection query needs to be modified in line 2 to: __type(name: "QueryRoot")
Query
type, just change the name argument to Mutation
or Subscription
.
4.3.0
release includes a way to expose GraphQL queries as REST endpoints. For now, this can only be configured via the raw API definition, Tyk Dashboard support is coming soon.
persist_graphql
section of the extended_paths
on an HTTP type in any API version you intend to use to serve as the GraphQL query to REST endpoint proxy.
Here is a sample REST API proxy for the HTTP type API:
extended_paths.persist_graphql
field. The persist_graphql
object consists of three fields:
method
: The HTTP method used to access that endpoint, in this example, any GET requests to <PROXY ENDPOINT>/getContinentByCode
will be handled by the persist graphql middleware
path
: The path the middleware listens to
operation
: This is the GraphQL operation (query
in this case) that is sent to the upstream.
variables
: A list of variables that should be included in the upstream request.
If you run a request to your proxy, you should get a response similar to this:
code
header value as a variable in persist_graphql
middleware configuration:
"code": "UK"
, should result in a response similar to this:
persist_graphql
block to this:
/getCountryByCode/NG
you should get a result similar to this:
2
:
3
:
Global Limits and Quota
) The query depth value will be applied on all APIs attached on a Key/Policy.
Global Limits and Quota
by unchecking the Unlimited query depth checkmark and insert the maximum allowed query depth.Set per API Limits and Quota
) This value will overwrite any value registered for query depth limitation on global Key/Policy level, and will be applied on all fields for Query and Mutation types defined within the API schema.
Set per API Limits and Quota
section.Set per query depth limits
) By setting a query depth limit value on a specific Query/Mutation type field, will take highest priority and all values set on first 2 steps will be overwritten.
Set per query depth limits
section.max_query_depth
set:
field_access_rights
per API are set correctly:
-1
in any of the above examples will allow Unlimited query depth for your consumers.balance
for example.
Field access can be restricted by setting up field based permissions in a policy or directly on a key.
When a field is restricted and used in a GraphQL operation, the consumer will receive an error response (400 Bad Request):
owner
. When any other fields are used in a GraphQL operation, the consumer will receive an error response (400 Bad Request):
Query
and Account
types. Please note that the asterisk operator does not work recursively. For example, in the example below, the asterisk operator only allows access to fields of the Query
type. Fields of the Account
type remain restricted.
Account
type.
Please note that the list of allowed types overrides the list of restricted types.
code
and countries
fields in Continent
type.latt
and longt
fields in Coordinates
type.code
field in Continent
type.code
and name
fields in Language
type.Query
type is unchecked, which indicates that all fields in Query
type are unchecked. Subsequently, you will not be able to run any query.
author
field with type User
, which is defined in a different subgraph.
reviews
field to it.
@key
directive to an object’s type definition so that other subgraphs can reference or extend that type. The @key
directive makes an object type an entity.
true
in your tyk.conf
file.
complete
message, including the GraphQL response inside the payload.next
messages containing the GraphQL response inside the payload until the data stream ends with a complete
message. It can happen infinitely if desired.connection_init
message is sent after 15 seconds after opening, then the connection will be closed.v4.0.0
in which graphql-ws protocol support was introduced.
With the release of Tyk v4.3.0
the number of supported subscription protocols has been extended.
In Tyk subscriptions are using the WebSocket transport for connections between the client and Gateway. For connections between Gateway and upstream WebSockets or SSE can be used.
Transport | Protocol |
---|---|
WebSockets | graphql-ws (default, no longer maintained) |
WebSockets | graphql-transport-ws |
HTTP | Server-Sent Events (SSE) |
graphql-ws
graphql-transport-ws
sse
(Server-Sent Events)Set theme
dropdown.
There’s also a built in Explorer
to help with query building and a Prettify
button that helps to make the typed out operation easier to read.
The GraphiQL try-out playground comes with a series of features by default, which can be very useful while configuring the API:
API Designer
, that’s only accessible via Tyk Dashboard and is always enabled. You need to log into the Tyk Dashboard to be able to use it.
playground
folder under template_path (default: /opt/tyk-gateway/templates
).
If you change this path, be sure to copy the playground
folder to the new location to preserve functionality.Core Settings
tab in API designer
Enable API Playground
section.Playground path
. By default, this path is set to /playground
but you can change it.Public Playground
will be available at http://{API-URL}/playground
.Query variables
section of the Playground like this:
Authorization
header in case of Authentication Token protection over the API). This can be done using the dedicated headers tab in the Graphiql IDE.
Info
, Debug
, Warning
, and Error
, and each log belongs to one of these levels.
The first column of the table displays the color-coded “level”
property of the log. A log should never be absent of a level. The second column displays the log “msg”
(message) property, if any. The third column displays the “mw”
(middleware) property, if any.
info
and error
filters buttons are both active. If there are no logs for a particular level of log, the button will appear as a gray and disabled, as shown by the Warning
filter button.
“Show”
.
If all filter buttons are inactive, a message asking whether the user would like to reset all filters will display. Clicking this text will activate all available filters.
api_definition.graphql
) changed significantly, hence GraphQL API definitions created in previous beta versions are not supported via the UI and need to go through a manual migration.
graphql.type_field_configurations
is now obsolete and new data sources can be defined under graphql.engine.data_sources
(see example below).
REST
or GraphQL
regardless of your API being internal or not.
tyk://
scheme, the graphql.engine.data_sources[n].internal
property is set to true.
graphql.engine.data_sources[n].name
.
graphql.engine.field_configs
regardless of it requiring mapping or not.
graphql.version
property set to 2
.