The de-graphql plugin maps URIs to GraphQL queries so that upstream GraphQL APIs can be accessed as standard REST services.
Running attributes
Plugin execution stage: Authorization. Plugin execution priority: 430.
Parameter configurations
|
Parameter |
Description |
Default |
|
|
The GraphQL query to execute. |
Required |
|
|
The GraphQL query endpoint. |
|
|
|
Query connection timeout, in milliseconds. |
|
|
|
Service domain name. Required when the service source is DNS. |
Use the plugin
https://github.com/alibaba/higress/issues/268
Test configurations
apiVersion: networking.higress.io/v1
kind: McpBridge
metadata:
name: default
namespace: higress-system
spec:
registries:
- domain: api.github.com
name: github
port: 443
type: dns
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
higress.io/destination: github.dns
higress.io/upstream-vhost: "api.github.com"
higress.io/backend-protocol: HTTPS
name: github-api
namespace: higress-system
spec:
ingressClassName: higress
rules:
- http:
paths:
- backend:
resource:
apiGroup: networking.higress.io
kind: McpBridge
name: default
path: /api
pathType: Prefix
---
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
name: de-graphql-github-api
namespace: higress-system
spec:
matchRules:
- ingress:
- github-api
config:
timeout: 5000
endpoint: /graphql
domain: api.github.com
gql: |
query ($owner:String! $name:String!){
repository(owner:$owner, name:$name) {
name
forkCount
description
}
}
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/de-graphql:1.0.0
Test results
curl "http://localhost/api?owner=alibaba&name=higress" -H "Authorization: Bearer some-token"
{
"data": {
"repository": {
"description": "Next-generation Cloud Native Gateway",
"forkCount": 149,
"name": "higress"
}
}
}
About GraphQL
GraphQL endpoint
Unlike REST APIs, which expose multiple endpoints, a GraphQL API has a single endpoint.
https://api.github.com/graphql
Communicate with GraphQL
GraphQL operations are expressed as JSON, so you can use cURL or any HTTP library to send requests.
In REST, the HTTP verb varies by action. In GraphQL, all queries use POST with a JSON request body. The only exception is introspection queries, which use GET.
GraphQL POST request parameters
A standard GraphQL POST request includes:
-
HTTP request header: Content-Type: application/json
-
A JSON-formatted request body
-
The JSON request body contains three fields:
-
query: the GraphQL query string. Required.
-
variables: custom variables. Optional.
-
operationName: the name of the operation. Optional, but required when the request contains multiple operations.
{ "query": "{viewer{name}}", "operationName": "", "variables": { "name": "value" } } -
Basic parameter types in GraphQL
-
Basic parameter types: String, Int, Float, and Boolean.
-
[Type] represents an array, for example, [Int] represents an array of integers.
-
Passing basic parameters in GraphQL
-
Parentheses define formal parameters. Each parameter must have a type annotation.
-
An exclamation mark (!) indicates that the parameter is required.
query ($owner : String!, $name : String!) { repository(owner: $owner, name: $name) { name forkCount description } }
-
GraphQL test on GitHub
Use cURL to run GraphQL queries. The POST request body must be valid JSON with a string field named query.
curl https://api.github.com/graphql -X POST \
-H "Authorization: bearer <PAT>" \
-d "{\"query\": \"query { viewer { login }}\"}"
{
"data": {
"viewer": {
"login": "2456868764"
}
}
}curl 'https://api.github.com/graphql' -X POST \
-H 'Authorization: bearer <PAT>' \
-d '{"query":"query ($owner: String!, $name: String!) {\n repository(owner: $owner, name: $name) {\n name\n forkCount\n description\n }\n}\n","variables":{"owner":"2456868764","name":"higress"}}'
{
"data": {
"repository": {
"name": "higress",
"forkCount": 149,
"description": "Next-generation Cloud Native Gateway"
}
}
}