Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: degraphql plugin proposal and simple implement #8787

Closed
Sn0rt opened this issue Feb 3, 2023 · 5 comments · Fixed by #8959
Closed

feat: degraphql plugin proposal and simple implement #8787

Sn0rt opened this issue Feb 3, 2023 · 5 comments · Fixed by #8959

Comments

@Sn0rt
Copy link
Contributor

Sn0rt commented Feb 3, 2023

Description

DeGraphQL allows users to map URIs to fixed GraphQL queries through configuration, thereby converting GraphQL endpoints into ordinary endpoints.

parameter

name type requried default value format describe
endpoint string yes /    
query string yes “” graphql string The body of graphql that actually needs to be executed

enable plugin

You can enable the plugin in a specific route with the following command:

curl "http://127.0.0.1:9180/apisix/admin/routes/1"  \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
  "uri": "/me",
  "plugins": {
    "degraphql": {
      "endpoint": "/graphql",
      "query": "{\"query\":\"query{viewer{login}}\"}"
    }
  },
  "upstream": {
    "scheme":"https",
    "nodes": {
      "api.github.com:443": 1
    },
    "type": "roundrobin"
  }
}'

user case 1

the user want map a resetful api /me to [github.com/login](http://github.com/login) info

  1. enable plugin
curl "http://127.0.0.1:9180/apisix/admin/routes/1"  \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
  "uri": "/me",
  "plugins": {
    "degraphql": {
      "endpoint": "/graphql",
      "query": "{\"query\":\"query{viewer{login}}\"}"
    }
  },
  "upstream": {
    "scheme":"https",
    "nodes": {
      "api.github.com:443": 1
    },
    "type": "roundrobin"
  }
}'
  1. query route

to query the route info for double check

$ curl -s -X GET -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' "http://127.0.0.1:9180/apisix/admin/routes/1"  | jq

{
  "value": {
    "status": 1,
    "plugins": {
      "degraphql": {
        "query": "{\"query\":\"query{viewer{login}}\"}",
        "endpoint": "/graphql"
      }
    },
    "update_time": 1675435553,
    "uri": "/me",
    "priority": 0,
    "create_time": 1675396064,
    "upstream": {
      "pass_host": "pass",
      "type": "roundrobin",
      "hash_on": "vars",
      "nodes": {
        "api.github.com:443": 1
      },
      "scheme": "https"
    },
    "id": "1"
  },
  "createdIndex": 31,
  "modifiedIndex": 735,
  "key": "/apisix/routes/1"
}
  1. test

to send a request to /me path

curl -i -X GET "http://127.0.0.1:9080/me" -H "Host: api.github.com" -H "Authorization: bearer xxx"

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 38
Connection: keep-alive
Date: Thu, 02 Feb 2023 10:39:37 GMT
X-OAuth-Scopes: audit_log, gist, notifications, project, user
X-Accepted-OAuth-Scopes: repo
github-authentication-token-expiration: 2023-05-03 07:06:06 UTC
X-GitHub-Media-Type: github.v4; format=json
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4992
X-RateLimit-Reset: 1675335703
X-RateLimit-Used: 8
X-RateLimit-Resource: graphql
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Vary: Accept-Encoding, Accept, X-Requested-With
X-GitHub-Request-Id: D111:7589:2F097:32432:63DB92E8
Server: APISIX/3.1.0

{"data":{"viewer":{"login":"Sn0rt"}}}

user case 2

a new RESTful API /describe?owner=apache&name=apisix to query the repo description

  1. create a route
curl "http://127.0.0.1:9180/apisix/admin/routes/2" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
  "uri": "/describe",
  "plugins": {
    "degraphql": {
      "endpoint": "/graphql",
      "query": "{\"query\":\"query{repository(owner:\\\"$owner\\\",name:\\\"$name\\\"){description}}\"}"
    }
  },
  "upstream": {
    "scheme":"https",
    "nodes": {
      "api.github.com:443": 1
    },
    "type": "roundrobin"
  }
}'
  1. test

send a request to the /describe

curl -i -X GET "http://127.0.0.1:9080/describe?owner=apache&name=apisix" -H "Host: api.github.com" -H "Authorization: bearer xx"

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 71
Connection: keep-alive
Date: Sat, 04 Feb 2023 05:59:00 GMT
X-OAuth-Scopes: audit_log, gist, notifications, project, user
X-Accepted-OAuth-Scopes: repo
github-authentication-token-expiration: 2023-05-03 07:06:06 UTC
X-GitHub-Media-Type: github.v4; format=json
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4989
X-RateLimit-Reset: 1675492836
X-RateLimit-Used: 11
X-RateLimit-Resource: graphql
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Vary: Accept-Encoding, Accept, X-Requested-With
X-GitHub-Request-Id: D196:25BA:5B0836:628EB6:63DDF423
Server: APISIX/3.1.0
Apisix-Plugins: degraphql

{"data":{"repository":{"description":"The Cloud-Native API Gateway"}}}

reference

https://docs.konghq.com/hub/kong-inc/degraphql/

@Sn0rt Sn0rt changed the title feat: degraphql plugin proposal feat: degraphql plugin proposal and simple implement Feb 4, 2023
@spacewander
Copy link
Member

spacewander commented Feb 5, 2023

We have developed a degraphql plugin last year for customers which has more features.
There is a plan to open source it soon.

@Sn0rt
Copy link
Contributor Author

Sn0rt commented Feb 6, 2023

We have developed a degraphql plugin last year for customers which has more features. There is a plan to open source it soon.

copy that.
I want keep this issues status is open for track the feature until your implementation has been shared.
What do you think @spacewander ?

@spacewander
Copy link
Member

Yes, we can keep it open.

@Sn0rt
Copy link
Contributor Author

Sn0rt commented Feb 7, 2023

Yes, we can keep it open.

aha, I have another idea. can you create a branch for this feature . I can help you to impove your implementation of DeGraphQL.

I want to lean how to contribute for this project. what do you think ?

@spacewander
Copy link
Member

I am afraid I don't have the privilege to open-source the code at any time I want.
Maybe you can take a look at other good first issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants