Skillshare / apollo-federation-php

🌍 A PHP implementation of the Apollo Federation specification
MIT License
35 stars 9 forks source link

Entities subscription #25

Open DiegoAlar opened 2 years ago

DiegoAlar commented 2 years ago

Hi,

I'm having the following issue with the library in this part of the code: https://github.com/Skillshare/apollo-federation-php/blob/4f958ddb683c1fceb1d162f58a5dc2957e26fe5d/src/FederatedSchema.php?rgh-link-date=2022-06-23T15%3A36%3A45Z#L215-L227

The issue is that the library is unable to subscribe entities that aren't returned by a query.

Thank you!

Aeliot-Tm commented 2 years ago

@DiegoAlar Could you describe your problem more verbose?

P.s. Provide link to exact version instead of main branch, please. Otherwise, it might be broken after the merging of any changes.

magnusnordlander commented 1 year ago

@Aeliot-Tm I think we're experiencing the same issue, in which case the issue is that if a type is not directly or indirectly referenced by the Query type, the type is not discovered as an entity.

Consider the following sub-graph schemas:

# Subgraph A

extend type Query {
    restaurants: [Restaurant!]!
}

type Restaurant {
    id: ID! @key
    name: String!
}

# Subgraph B

extend type Query {
    locations: [Location!]!
}

type Location {
    lat: Float!
    long: Float!
}

extend type Restaurant {
    id: ID! @key
    location: Location!
}

Note that in Subgraph B, the Query type does not reference the Restaurant Type. If this schema is implemented using this library, it is unable to discover that the Restaurant type is an Entity, because Apollo\Federation\FederatedSchema::extractEntityTypes gets its list of candidate types from $config['query'] (cf. https://github.com/Skillshare/apollo-federation-php/blob/4f958dd/src/FederatedSchema.php#L218 ).