Graphql fragment dont work as expected

Hey, i tried to do a basic query to my graphql endpoint using fragments
When i do it directly to my graphql endpoint it works perfectly but when it goes through tyk it doesn’t
Normal query works using tyk so the problem is specifically with fragments i guess.
This is the example when i only get typename(doesnt belong to the fragment fields)

The other is a working example of what the response should look like (directly to the endpoint)

Thanks in advance !

Hey @itzhakyos

could you let me know which Tyk version you’re on? I just tried replicating this problem on v5.2 and was not able to, fragments worked just fine. I checked our Dashboard Playground, the public Playground (which I think you were using to do your screenshots) and via Postman as well.
Would be great to get a bit more detail: Tyk version - as mentioned already, logs if you’ve got anything available.

Also attaching the screenshot from my test in public Playground.

Hey,
I am using version 5.0.1
Thank you in advance !

any updates ? @agata-wit

I tried to replicate your problem on a few different versions, including 5.0.1, and I am still getting fragments to work as they should. No issues whatsoever.

Is there anything “special” about your upstream? From the looks of it, it seems like a pretty standard GQL API, but obviously I just see the Playground screenshots, not the service itself.
Also - what are you getting the the gateway logs? Something similar to the below or something else?

time="Nov 13 14:22:38" level=debug msg=Started api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=VersionCheck org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/ ts=1699881758606370000
time="Nov 13 14:22:38" level=debug msg=Finished api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades code=200 mw=VersionCheck ns=39169 org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/
time="Nov 13 14:22:38" level=debug msg=Started api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=RateCheckMW org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/ ts=1699881758606429000
time="Nov 13 14:22:38" level=debug msg=Finished api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades code=200 mw=RateCheckMW ns=17912 org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/
time="Nov 13 14:22:38" level=debug msg=Started api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=OrganizationMonitor org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/ ts=1699881758606480000
time="Nov 13 14:22:38" level=debug msg=Finished api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades code=200 mw=OrganizationMonitor ns=13993 org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/
time="Nov 13 14:22:38" level=debug msg=Started api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=GraphQLMiddleware org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/ ts=1699881758606510000
time="Nov 13 14:22:38" level=debug msg=Finished api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades code=200 mw=GraphQLMiddleware ns=387240 org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/
time="Nov 13 14:22:38" level=debug msg=Started api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=RedisCacheMiddleware org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/ ts=1699881758606925000
time="Nov 13 14:22:38" level=debug msg="Not a cached path" api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=RedisCacheMiddleware org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/
time="Nov 13 14:22:38" level=debug msg=Finished api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades code=200 mw=RedisCacheMiddleware ns=24916 org_id=60dc2ae33ff411a0ddd459d9 origin="::1" path=/trevorblades/
time="Nov 13 14:22:38" level=debug msg="Started proxy"
time="Nov 13 14:22:38" level=debug msg="Stripping proxy listen path: /trevorblades/"
time="Nov 13 14:22:38" level=debug msg="Upstream path is: /"
time="Nov 13 14:22:38" level=debug msg=Started api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=ReverseProxy org_id=60dc2ae33ff411a0ddd459d9 ts=1699881758606987000
time="Nov 13 14:22:38" level=debug msg="Upstream request URL: /" api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=ReverseProxy org_id=60dc2ae33ff411a0ddd459d9
time="Nov 13 14:22:38" level=debug msg="Outbound request URL: https://countries.trevorblades.com/" api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=ReverseProxy org_id=60dc2ae33ff411a0ddd459d9
time="Nov 13 14:22:38" level=debug msg="Request is not cacheable" mw=ResponseCacheMiddleware
time="Nov 13 14:22:38" level=debug msg=Finished api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades mw=ReverseProxy ns=232948830 org_id=60dc2ae33ff411a0ddd459d9
time="Nov 13 14:22:38" level=debug msg="Upstream request took (ms): 232.966685"
time="Nov 13 14:22:38" level=debug msg="Checking: 60dc2ae33ff411a0ddd459d9" api_id=150ad0d4f8764dbb74ff61ee2e1f27a8 api_name=trevorblades org_id=60dc2ae33ff411a0ddd459d9
time="Nov 13 14:22:38" level=debug msg="Done proxy"

when i try using this query with fragment in the playground outside of the gateway dashboard what i shoed above were the results.
But i notice that when i use the internal playground with the exact query using fragment there is a response:
{
“message”: “fragment spread: my-fragment-name forms fragment cycle”,
“path”:[
“query”,
" my-fragment-name "
]
}

any lead ? @agata-wit

Hello @itzhakyos,

I’m currently looking into your issue but unfortunately, your provided information is not enough to reproduce the issue.

Can you please provide a (minimal) schema and the operation (if possible as copyable text)?

Thank you!

yes
i have a type:
gql interface StaticEntity { id: String kind: String }

some other types:
gql union StaticEntityTypes = Circle | Corridor

gql type Circle implements StaticEntity { id: String kind: String }

gql type Corridor implements StaticEntity { id: String kind: String }

gql type Query { myArea(ts: String): [StaticEntityTypes] }

and then i do a query from the client:

fragment GenericStaticEntity on StaticEntity{
id
kind
}

query MyArea($ts: String){
MyArea(ts: $ts) {
…GenericStaticEntity
_typename
}
}

everything works perfectly when i go directly to my graphql endpoint
but when i go through tyk the results are as i showed above

i added all the minimal schema @patric @agata-wit
thank you guys !

Hello @itzhakyos,

I’ve tried following setup now:

Schema

union StaticEntityTypes = Circle | Corridor

interface StaticEntity { 
	id: String 
	kind: String
}

type Query {
	myArea(ts: String): [StaticEntityTypes]
}

type Circle implements StaticEntity { 
	id: String 
	kind: String
}

type Corridor implements StaticEntity { 
	id: String 
	kind: String
}

Operation

fragment GenericStaticEntity on StaticEntity{
	id
	kind
}

query MyArea($area: String) {
	myArea(ts: $area) {
    ...GenericStaticEntity
    __typename
  }
}

Variables

{"area": "HE"}

Can you check if my setup resembles yours? Currently, I’m not experiencing the error you are, so I want to make sure, that everything is the same.

If this issue is blocking you, try to avoid fragments for this use case for now (as Tyk will remove the fragment internally anyway)

Thank you!

I tried your setup and it does not work…
Unfortunately changing our project to work without fragments is not realistic at the moment,
because there we use it a lot inside a big project.