*what is GraphQL* 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.
*How GraphQL works* `client` -> `APISIX` -> `GraphQL server` . Proxy the user's GraphQL request and forward it to the GraphQL server according to the user's request information. When a client resource requests, GraphQL is submitted in the request body, for example: ``` curl http://***/graphql -X POST -d ' query getUser($id: ID) { person(id: $id) { firstName lastName } } ' ``` ## feature > **1th feature**: Forward to different requests upstream according to the root field. ```lua local graphql_str = [[ query getUser($id: ID) { -- root person(id: $id) { -- field 为 `person` firstName lastName } }]] local ast = parse(graphql_str) ... ``` > **2th feature**: For different GraphQL queries, different plugins are allowed to be bound. For example, querying different root fields allows completely different plug-ins to be bound. * query `person`: enable plugin prometheus. * query `bill`: enable plugin limit-count and prometheus. > **3th feature**: Later support GraphQL's `mutation`: https://graphql.org/learn/queries/#mutations *implement way* Support adding GraphQL field to route matching conditions. For example: ```shell curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -i -d ' { "uri": "/graphql", "vars": [ ["graphql_field", "==", "person"] ], "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:3000": 1 # GrapQL server } } }' ``` -- *MembPhis* My GitHub: https://github.com/membphis Apache APISIX: https://github.com/apache/apisix
