Hello,
So as I’m looking to integrate FQLv10 with a GraphQL gateway, one thing I’m noticing is that in order for the gateway to properly resolve union types it requires a __typename
attribute to be available on the result that indicates which subtype it is. In the query, I am adding this manually on the resulting page object, but it’s a bit clunky. Is there a better way than creating a temporary struct and using Object.assign
? As far as I can tell, a projection won’t work as that would add the __typename
field to each resulting struct in data
An example for illustration:
Example GQL Schema
type Charge {
id: ID
chargeType: String
chargeDate: Date
"""
This amount is represented in the smallest currency unit,
which for USD is cents.
"""
chargeAmount: Int
}
"""
A paginated representation of a list of Charges.
"""
type ChargePage {
data: [Charge]
"""
The after cursor will be populated if there is more data after this page.
"""
after: ID
}
"""
This indicates the error messages for a specific input field.
"""
type FieldError{
field: String
errors: [String]
}
"""
This indicates there was an error in the input provided to the mutation. The attributes
provide further information on the errors that were encountered.
"""
type InputError {
fieldErrors: [FieldError]
nonFieldErrors: [String]
}
"""
The possible results from a paginated Charge query. If the cursor provided is invalid,
then an InputError will be returned instead of the ChargePage.
"""
union ChargePageResult = ChargePage | InputError
type Account {
id: ID
charges(cursor: ID): ChargePageResult
}
Example FSL defining collections
collection Charge {
index byAccount {
terms [.account]
}
}
collection Account {
}
Example FQLv10 Query
let account = Account.byId(${accountID})
let charges = Charge.byAccount(account) {
id,
chargeAmount
}
let chargeResult = {__typename: "ChargePage"}
account {
id,
charges: Object.assign(chargeResult, charges.paginate())
}