Short version: Can I use Apollo Federation to replace the functionality of delegateToSchema
, and if so, how? The idea is to reuse resolver logic from another service that is a black-box.
Long version:
I've been scouring the internet for hours trying to figure out how to merge two services without explicitly writing a new resolver. Apollo vaguely says that you can migrate from schema-stitching to federation, but consider this example:
type User @key(fields: "username"){
username: ID!
photos: [Photo] @provides(fields: "created_by")
}
extend type Photo @key(fields: "id") {
id: ID! @external
created_by: ID! @external # I want to match this with username
}
I'm using PostGraphile to convert my database into a GraphQL schema with all the necessary resolvers for CRUD. There is already a query with which I could fetch the photos for a specific user:
allPhotos(condition: {created_by: $username}) { ... }
This exists in another service which I'm treating as a black-box. It's not ideal (or easy) to manually write a new resolver, especially since the data is there, I just need to tell Apollo how to get it. I thought maybe I could use delegateToSchema
:
delegateToSchema({
schema: pgSchema,
operation: 'query',
fieldName: 'allPhotos(condition: {created_by: $username})',
args: { username: args.username },
context: context,
info: info
})
But from what I see in the docs and in articles, this is schema-stitching, which is supposed to be replaced by federation. Ideally I'd like to use only federation to achieve this if it's possible. Is it possible? The docs don't make it clear, and every example I've seen with federation still requires you to write a custom resolver. It's almost as if the directives just gives hints to ensure you have the correct fields in your resolvers, instead of actually doing any logic.
Any help is appreciated!