movio / bramble

A federated GraphQL API gateway
https://movio.github.io/bramble/
MIT License
497 stars 53 forks source link

nested abstract fragment error if returned type not queried #191

Closed benzolium closed 3 months ago

benzolium commented 1 year ago

I have some types, e.g.:

type Foo @boundary {
    id: ID!
}
type Bar @boundary {
    id: ID!
}
union FooOrBar = Foo | Bar
type Baz @boundary {
    id: ID!
    value: FooOrBar
}

I'm trying to query:

query Foo {
    baz(id: "BAZ1") {
        id
        value {
            ...BazValueFragment
        }
    }
}
fragment FooFragment on Foo {
    id
}
fragment BazValueFragment on FooOrBar {
    ...FooFragment
}

As you can see, I forgot to query BarFragment on Bar.

Expected:

Actual:

I've also reproduced it with a test: https://github.com/benzolium/bramble/blob/f3ddc95ce4450327509ea8b258d4bc7889431935/execution_test.go#L696

I could probably fix that, but I don't know where to start.

nmaquet commented 1 year ago

@benzolium Thanks for the report. I've tried to reproduce it using your test but it seems there is a JSON syntax error in the handler response of serviceC (notice the spurious comma after "id": "1". This is the cause of the invalid character '}' error message.

"value": {
    "_bramble_id": "BAR1",
    "_bramble__typename": "BAR",
    "id": "1",
}
benzolium commented 1 year ago

Oh, my bad. Good catch, @nmaquet. I'll try to reproduce the issue properly cause I'm still getting this error in actual gateway.

Maybe I should catch the issue somewhere else. 🤔

nmaquet commented 1 year ago

No worries. Can you double check that your downstream service returns syntactically correct JSON? If you're templating your JSON or using string builders it's easy to make a make a mistake and have that extra comma.

nmaquet commented 1 year ago

@benzolium Any update on this issue? We'd be happy to help if you have some steps to reproduce the problem.

benzolium commented 1 year ago

@nmaquet sorry, got lost in work.

I've just tried to test query on downstream service only.

In my case downstream service returns this for value:

"value": {}

So it is syntactically correct JSON.