thecodingmachine / graphqlite

Use PHP Attributes/Annotations to declare your GraphQL API
https://graphqlite.thecodingmachine.io
MIT License
556 stars 97 forks source link

Federation support #351

Open alejo-lapix opened 3 years ago

alejo-lapix commented 3 years ago

Do yo have any plans to support apollo federation?

oojacoboo commented 3 years ago

I haven't used Apollo federation. Can you outline the specific requirements that'd be needed from this lib?

alejo-lapix commented 3 years ago

Apollo Federation allows you to implement a single data graph across multiple services. Libraries like pascaldevink/php-graphql-federation extends the current schema and enables federation, but it does not work well with graphqlite.

To make a GraphQL service federation capable, we need:

Hope this helps. You need help implementing any of those features? Would be great to contribute to graphlite.

oojacoboo commented 3 years ago

Thanks for the outlining that. I'm familiar with federation, just wasn't sure exactly what would be needed.

I'm not aware of any current initiatives or motivation to get federation added, at the moment. However, assuming this could be easily configured and doesn't cause performance implications, I don't see why there would be any objections to a PR raised with federation support. So yea, if you'd like to take a go at it, that'd be great.

ycfreeman commented 2 years ago

there's a new one https://github.com/Skillshare/apollo-federation-php this one is added to the official list of "Subgraph-compatible server libraries"

https://www.apollographql.com/docs/federation/other-servers/

gtavares commented 1 year ago

@oojacoboo This discussion is a bit hold but do you have any plans to support the federation? 🙂 We would like to use graphqlite in combination with apollo-federation-php but it doesn't seem a simple task.

The framework needs to be adapted to support instantiating EntityObjectType or EntityRefObjectType (for example by creating a new attribute #[ExternalType] ). However, the MutableObjectType is extending the ObjectType and we have multiple places checking if the object is instance of MutableObjectType. Maybe we could have an interface (e.g ObjectTypeInterface) where MutableObjectType would extend from? And also provide a way to add custom types?

I believe that wrapping the schema into a federated schema is already supported by doing something like this:

$config = $this->factory->createSchema()->getConfig();
$schema = new FederatedSchema(
    [
        'query' => $config->getQuery(),
        'mutation' => $config->getMutation(),
        'types' => $types,
        'assumeValid' => true,
    ]
);

But we still need to find a way to create the external types :)

Thank you!

oojacoboo commented 1 year ago

@gtavares I still haven't looked into federation too much. But, wouldn't the goal be for GraphQLite to deliver it's schema into a federation server that combines with the rest of the federated graph?

I came across this related lib and docs as well: https://github.com/pascaldevink/php-graphql-federation/blob/master/README.md.

Also, see this discussion here around SDL output and caching and https://github.com/thecodingmachine/graphqlite/issues/569. It's possible we could also make use of this output for feeding to a federation server.

As for the changes you've mentioned in GraphQLite, why are these needed? Why can't GraphQLite deliver something like an SDL to a federation server and that server proxy the requests back to GraphQLite? I don't understand why the mentioned changes are necessary.