apollo-federation-ruby
apollo-federation-ruby copied to clipboard
fix: guard compatibility for GetServiceDefinition requests
Hey!
Thanks for your work around this library. We're researching GQL gateway solutions right now. And apollo gateway one of the possible solutions for us, that's why this library is really useful for us.
Before start using the gateway, we need to understand how to start using a gateway with our codebase and for this, we need to think about migration to a gateway.
For example, we have a legacy GQL endpoint with User
type like this:
# user service
# `http://user_service/graphql` endpoint
class User < BaseObject
key fields: 'id'
field :id, ID, null: false
field :reviews, [Review], null: true
def reviews
# HTTP call to another service
end
end
For start using a gateway, we want to check that everything is good and make this migration without zero downtime. For this we want to see something like this:
# user service
# `http://user_service/graphql` endpoint
class User < BaseObject
key fields: 'id'
field :id, ID, null: false
# if we call it from client we want to use this field
# if we call it from gateway we don't want to use this field
if request == CLIENT
field :reviews, [Review], null: true
elsif request == GATEWAY
# nothing
end
def reviews
# HTTP call to another service
end
end
# review service
# `http://review_service/graphql` endpoint
class User < BaseObject
key fields: 'id'
extend_type
field :id, ID, null: false, external: true
field :reviews, [Review], null: true
def reviews
# DB call
end
end
To make this happen I found that I can use https://github.com/exAspArk/graphql-guard/ library with schema masking.
class User < BaseObject
key fields: 'id'
field :id, ID, null: false
field :reviews, [Review], null: true do
mask ->(ctx) { ctx[:request_type] == 'client' }
end
end
I tried to use it with the current implementation of apollo gateway but found an issue around GetServiceDefinition
call:
I started searching where the problem and found that you change FederatedDocumentFromSchemaDefinition
but use it with an empty warden
object (link to original code).
I added hack from this PR and after that, I got the right behavior:
I'm not sure that my fix is good from a code perspective, but I'll be happy to start using the apollo federation ASAP. That's why I have a question: can we merge it soon or how I can change the code?
Hi @davydovanton. Thanks for creating this PR and sorry for the delay. If I understand the issue you're trying to fix, it looks like https://github.com/Gusto/apollo-federation-ruby/pull/45 may have already fixed it. Does that look right?
Closing this as stale. Please feel free to open a new PR/issue as needed.