You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are working on building a federated graph and this gem is helping us getting closer to a production release. 😄 I've been tasked to control the visibility of the schema so the external Federated schema does not expose every single field from internal schemas.
classBaseField < GraphQL::Schema::FieldincludeApolloFederation::Fieldargument_classBaseArgumentdefinitialize(*_args,expose: false, **_kwargs)@exposed=exposedsuper(*args, **kwargs, &block)enddefto_graphqlfield_definition=superfield_definition.metadata[:expose]=@exposefield_definitionendend# ---classQuery < BaseObjectfield:foobar,Foobar,null: true,expose: trueend# ---# controllerresult=GraphSchema.execute(query,variables: variables,operation_name: operation_name,context: context,only: ExposeWhitelist.new)# ---# Work in progressclassExposeWhitelistdefcall(schema_member,_context)ifschema_member.is_a?(GraphQL::Field)# TODO: better detection of Federated fields.schema_member.name == "_entities" ||
schema_member.name == "_service" ||
schema_member.name == "sdl" ||
schema_member.introspection? ||
schema_member.metadata[:exposed]elsifschema_member.is_a?(GraphQL::Argument)# TODO: implement logic here to decide either or not Argument should be exposed.trueelse# TODO: implement logic here to decide either or not Type, Enum should be exposed.trueendendend
This causes the following error:
{
"errors": [
{
"message": "A copy of Types has been removed from the module tree but is still active!",
"extensions": {
"type": "ArgumentError",
It seems that the challenge lies around the fact that the module ApolloFederation::Field also defines an initialize method and the super calls gets confused 🤔 and crashes in unexpected ways, the bare minimum example I tried just overwrote initialize while including the Federation module and that was enough to cause issues.
Hi 👋
We are working on building a federated graph and this gem is helping us getting closer to a production release. 😄 I've been tasked to control the visibility of the schema so the external Federated schema does not expose every single field from internal schemas.
So far my proposed solution is simple, users opt-in to have their fields/objects exposed, I am following the documentation on Limiting Visibility and Extending the GraphQL-Ruby Type Definition System and this is what I come up with:
This causes the following error:
It seems that the challenge lies around the fact that the module
ApolloFederation::Field
also defines aninitialize
method and thesuper
calls gets confused 🤔 and crashes in unexpected ways, the bare minimum example I tried just overwroteinitialize
while including the Federation module and that was enough to cause issues.Based of the following technique for extending a method from a module, I came up with the following solution:
Thoughts on this approach, would you consider a Pull Request with similar change?
Thanks for open sourcing this Apollo Federation solution, I appreciate it 💜
The text was updated successfully, but these errors were encountered: