# Can I have a graphQL API as a upstream using kong gateway?

**URL:** <https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739>\
**Category:** General\
**Tags:** kong-gateway\
**Created:** [January 14, 2021, 2:23pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739 "2021-01-14T14:23:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rviegas](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rviegas](https://discuss.konghq.com/u/rviegas)\
**Post date:** [January 14, 2021, 2:23pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/1 "2021-01-14T14:23:18Z")

</div>

What do I need to do to configure properly a simple graphQL API in the Kong gateway (open source)?  
Do I need to use a plugin?

basically, I have a graphQL API running ``[http://localhost:5005/graphql```](http://localhost:5005/graphql%60%60%60)

and here what I did in kong:  
service

```auto
{
    "host": "localhost",
    "id": "bf209028-20b8-48b4-84ed-87096114d7cf",
    "protocol": "http",
    "read_timeout": 60000,
    "tls_verify_depth": null,
    "port": 5005,
    "updated_at": 1610631073,
    "ca_certificates": null,
    "created_at": 1610630921,
    "connect_timeout": 60000,
    "write_timeout": 60000,
    "name": "hop-data-service",
    "retries": 5,
    "path": "/",
    "tls_verify": null,
    "tags": [
        "dev"
    ],
    "client_certificate": null
}

```

route

```auto
{
    "next": null,
    "data": [
        {
            "id": "4c170be9-ffb0-4d4c-b61a-79f701493da6",
            "tags": null,
            "updated_at": 1610631819,
            "destinations": null,
            "headers": null,
            "protocols": [
                "http",
                "https"
            ],
            "strip_path": false,
            "created_at": 1610630973,
            "request_buffering": true,
            "hosts": null,
            "name": "default",
            "service": {
                "id": "bf209028-20b8-48b4-84ed-87096114d7cf"
            },
            "paths": [
                "/graphql"
            ],
            "preserve_host": false,
            "regex_priority": 0,
            "response_buffering": true,
            "sources": null,
            "methods": [
                "POST"
            ],
            "https_redirect_status_code": 426,
            "path_handling": "v1",
            "snis": null
        }
    ]
}

```

when making a request to `http://{{kong-server}}/graphql` I am getting the message below:

```auto
{
  "message": "An invalid response was received from the upstream server"
}

```

---

<div class="post-metadata">

**Author:** ![rviegas](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rviegas](https://discuss.konghq.com/u/rviegas)\
**Post date:** [January 14, 2021, 2:44pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/2 "2021-01-14T14:44:34Z")

</div>

I just found the DeGraphQL plugin but it is only available in the kong enterprise subscription. Is there another way to have that using the kong API gateway (open source)?

---

<div class="post-metadata">

**Author:** ![hassanfarid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hassanfarid/32/2450_2.png) [@hassanfarid](https://discuss.konghq.com/u/hassanfarid)\
**Post date:** [January 18, 2021, 4:11am UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/3 "2021-01-18T04:11:34Z")

</div>

You don’t any plugins to move graphQL API behind Kong Community edition.

You can configure your `SERVICE` with `service.path=/graphql`. Add a `ROUTE` with `route.path=/`. (You can also set `route.path` to anything else as well.)

You are ready to hit `curl {kongIP:port}/{route.path}`

---

<div class="post-metadata">

**Author:** ![Heema\_Hinduja](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/heema_hinduja/32/2505_2.png) [@Heema\_Hinduja](https://discuss.konghq.com/u/Heema_Hinduja)\
**Post date:** [January 21, 2021, 3:27pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/4 "2021-01-21T15:27:53Z")

</div>

@hassanfarid I am facing the same issue while configuring the service for graphQL API in open source edition. I followed the same steps which you had posted above. But getting 404 Not found issue.

My backend endpoint looks like this [http://localhost:80/query](http://localhost:80/query) and using graphQL query to call my backend api.

I configured my service as below  
{  
“host”: “localhost”,  
“id”: “b3e2c794-99d5-48d8-8522-54b78a89f396”,  
“protocol”: “http”,  
“read\_timeout”: 60000,  
“tls\_verify\_depth”: null,  
“port”: 80,  
“updated\_at”: 1611241742,  
“ca\_certificates”: null,  
“created\_at”: 1611241742,  
“connect\_timeout”: 60000,  
“write\_timeout”: 60000,  
“name”: “test”,  
“retries”: 5,  
“path”: “/query”,  
“tls\_verify”: null,  
“tags”: null,  
“client\_certificate”: null  
}

I configured my route as below:

{  
“id”: “04ba3459-6eaa-491e-8af1-ae9335e813d9”,  
“tags”: null,  
“paths”: null,  
“destinations”: null,  
“headers”: null,  
“protocols”: [  
“http”,  
“https”  
],  
“strip\_path”: true,  
“created\_at”: 1611241759,  
“request\_buffering”: true,  
“hosts”: [  
“localhost”  
],  
“name”: null,  
“updated\_at”: 1611241759,  
“snis”: null,  
“preserve\_host”: false,  
“regex\_priority”: 0,  
“methods”: null,  
“sources”: null,  
“response\_buffering”: true,  
“https\_redirect\_status\_code”: 426,  
“path\_handling”: “v0”,  
“service”: {  
“id”: “b3e2c794-99d5-48d8-8522-54b78a89f396”  
}  
}

While hitting the request via postman

[http://konghost:80/query](http://konghost:80/query) + graphQL query data as a body

I am getting error as 404 method not found

@rviegas Is that working for you at open source edition?

---

<div class="post-metadata">

**Author:** ![rviegas](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rviegas](https://discuss.konghq.com/u/rviegas)\
**Post date:** [January 21, 2021, 4:16pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/5 "2021-01-21T16:16:22Z")

</div>

Actually, the issue is as you are running kong in a docker container, localhost means the kong container itself, and what you should do is run your graphql service also in a docker container within the same network as your kong and configure your service with the IP of your graphql service.

```auto
Getting your GraphQL service IP
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' your-container-name

```

---

<div class="post-metadata">

**Author:** ![Heema\_Hinduja](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/heema_hinduja/32/2505_2.png) [@Heema\_Hinduja](https://discuss.konghq.com/u/Heema_Hinduja)\
**Post date:** [January 21, 2021, 4:45pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/6 "2021-01-21T16:45:57Z")

</div>

Thanks for the reply @rviegas Let me try it

---

<div class="post-metadata">

**Author:** ![hassanfarid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hassanfarid/32/2450_2.png) [@hassanfarid](https://discuss.konghq.com/u/hassanfarid)\
**Post date:** [January 21, 2021, 5:24pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/7 "2021-01-21T17:24:05Z")

</div>

@Heema_Hinduja / @rviegas - here’s how my configurations look,

**Service** : (Most of them are defaults, only thing I have configured here are `host`, `port`, `name`, `path`)

```json
{
		"host": "10.32.9.73",
		"id": "039536b9-b451-49f2-938e-abe654b96919",
		"protocol": "http",
		"read_timeout": 60000,
		"tls_verify_depth": null,
		"port": 11020,
		"updated_at": 1606337009,
		"ca_certificates": null,
		"created_at": 1606248336,
		"connect_timeout": 60000,
		"write_timeout": 60000,
		"name": "app-gateway",
		"retries": 5,
		"path": "\/graphql",
		"tls_verify": null,
		"tags": null,
		"client_certificate": null
	}

```

**Route** : (Most of them are defaults, only thing I have configured here are (`service.id`, `path`)

```json
{
		"id": "246e468a-9fc3-4bc7-a790-84b981914234",
		"tags": null,
		"paths": ["\/app-gateway"],
		"destinations": null,
		"headers": null,
		"protocols": ["http", "https"],
		"strip_path": true,
		"created_at": 1606248364,
		"request_buffering": true,
		"hosts": null,
		"name": null,
		"updated_at": 1606248364,
		"snis": null,
		"preserve_host": false,
		"regex_priority": 0,
		"methods": null,
		"sources": null,
		"response_buffering": true,
		"https_redirect_status_code": 426,
		"path_handling": "v0",
		"service": {
			"id": "039536b9-b451-49f2-938e-abe654b96919"
		}
	}

```

Beyond this point for testing it, you can run following command.

```bash
curl http://10.32.9.73:8000/app-gateway

```

Notes:

- your backend graphQL service should be running.
- curl elimnates the cors issue, which can be resolved later on using plugin.

---

<div class="post-metadata">

**Author:** ![rviegas](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rviegas](https://discuss.konghq.com/u/rviegas)\
**Post date:** [January 21, 2021, 5:41pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/8 "2021-01-21T17:41:23Z")

</div>

Good. Let me know here if it works fine or you are facing another problem.

fingers crossed.

---

<div class="post-metadata">

**Author:** ![Heema\_Hinduja](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/heema_hinduja/32/2505_2.png) [@Heema\_Hinduja](https://discuss.konghq.com/u/Heema_Hinduja)\
**Post date:** [January 22, 2021, 10:17am UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/9 "2021-01-22T10:17:23Z")

</div>

@hassanfarid I tried the same steps you had mentioned but I getting Error: Parse Error: Expected HTTP/

---

<div class="post-metadata">

**Author:** ![rviegas](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rviegas](https://discuss.konghq.com/u/rviegas)\
**Post date:** [January 22, 2021, 11:08am UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/10 "2021-01-22T11:08:46Z")

</div>

@Heema_Hinduja Could you put here your service and route configurations?

---

<div class="post-metadata">

**Author:** ![Heema\_Hinduja](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/heema_hinduja/32/2505_2.png) [@Heema\_Hinduja](https://discuss.konghq.com/u/Heema_Hinduja)\
**Post date:** [January 22, 2021, 2:23pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/11 "2021-01-22T14:23:38Z")

</div>

@rviegas @hassanfarid

**My Service config:**

{  
“host”: “upstream\_backend\_service\_host”,  
“id”: “3071ecb6-a6e7-4b0b-a4b4-20ccb69578b5”,  
“protocol”: “http”,  
“read\_timeout”: 60000,  
“tls\_verify\_depth”: null,  
“port”: 80,  
“updated\_at”: 1611308686,  
“ca\_certificates”: null,  
“created\_at”: 1611308686,  
“connect\_timeout”: 60000,  
“write\_timeout”: 60000,  
“name”: “upstream\_backend\_host\_name”,  
“retries”: 5,  
“path”: “/query”,  
“tls\_verify”: null,  
“tags”: null,  
“client\_certificate”: null  
}

**My Route config:**

{  
“next”: null,  
“data”: [  
{  
“id”: “831e9880-a5cd-483f-b597-6d930ebe68f1”,  
“tags”: null,  
“paths”: [  
“/app-gateway”  
],  
“destinations”: null,  
“headers”: null,  
“protocols”: [  
“http”,  
“https”  
],  
“strip\_path”: true,  
“created\_at”: 1611309414,  
“request\_buffering”: true,  
“hosts”: null,  
“name”: null,  
“updated\_at”: 1611309414,  
“snis”: null,  
“preserve\_host”: false,  
“regex\_priority”: 0,  
“methods”: null,  
“sources”: null,  
“response\_buffering”: true,  
“https\_redirect\_status\_code”: 426,  
“path\_handling”: “v0”,  
“service”: {  
“id”: “3071ecb6-a6e7-4b0b-a4b4-20ccb69578b5”  
}  
}  
]  
}

Curl:

curl -X POST   
http://kong\_host\_name:9080/app-gateway   
-H ‘accept: application/json’   
-H ‘accept-encoding: gzip, deflate, br’   
-H ‘cache-control: no-cache’   
-H ‘connection: keep-alive’   
-H ‘content-type: application/json’   
-H ‘dnt: 1’   
-H ‘origin: upstream\_host’   
-H ‘postman-token: ab470068-5eae-7f70-8918-b45f93cfd46c’   
-d ‘’

Response:

POST [http://in-data-kong-1.sit.n3b.bookmyshow.org:9080/query](http://in-data-kong-1.sit.n3b.bookmyshow.org:9080/query)  
Error: Parse Error: Expected HTTP/

Note: I am facing the same issue even while sending sample HTTP request given in this kong document

> **[Open-Source API Management and Microservice Management](https://docs.konghq.com/2.2.x/getting-started/configuring-a-service/)**
>
> Secure, Manage & Extend your APIs or Microservices with plugins for authentication, logging, rate-limiting, transformations and more.

---

<div class="post-metadata">

**Author:** ![rviegas](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rviegas](https://discuss.konghq.com/u/rviegas)\
**Post date:** [January 22, 2021, 5:07pm UTC](https://discuss.konghq.com/t/can-i-have-a-graphql-api-as-a-upstream-using-kong-gateway/7739/12 "2021-01-22T17:07:07Z")

</div>

> [@Heema\_Hinduja](#):
>
> “path”: “/query”,

I think you need to make sure if your service you are trying to put behind Kong is working fine. Did you test it? If yes, how the request looks like when testing your service directly? Based on that, we can check the service/route configurations in Kong are right.
