-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
federation: resolveType of extended interface without knowledge of concrete type #377
Comments
I've thought a bit about this problem, too. Here's my 2 cents. Federated service should still work standalone, which your Node resolution service cannot possibly do. This is because its schema doesn't have any types for the const typeDefs = gql`
interface Node @key(fields: "id") @extends {
id: ID! @external
}
type Product @key(fields: "id") @extends {
id: ID! @external
}
extend type Query {
node(id: ID!): Node
}
`
const resolvers = {
Node: {
__resolveType(object) {
return object.__typename
},
},
Query: {
node(_, args) {
const [__typename, decodedId] = Base64.decode(args.id).split('-')
return { __typename, id: decodedId }
},
},
} However, this will mean that your Node resolution service must know of every type, and that it will resolve nodes which might not exist. The latter may be considered a feature, the former leads me to thinking that Node resolution should be part of the gateway (which anyway knows of every type). To my knowledge, there's no support for schemas which are only part of the gateway. You should be able to construct your Node resolution service as a service in the gateway, though. For example, you can extend |
Minimal working example: https://github.com/victorandree/apollo-federation-relay (see TODO) |
Thanks a lot, this example helped. @queerviolet any chance to have node query supported be moved into apollo server natively to avoid extra network hop just to resolve references? |
Our existing services and clients utilize the node interface for object resolution and I haven't been able to figure out a way to implement this with federation
Given the following services:
Product Service
Node Resolution Service
I am unable to lookup a product via the node field with its encoded id. Intuitively, this makes sense because the node resolution service is unaware of any types returned from
__resolveType
. How feasible would it be for__resolveType
to allow for arbitrary types if it's extended?Or am I thinking about this problem in the wrong way - have there been any other ideas for implementing the node interface with federation and gateway?
The text was updated successfully, but these errors were encountered: