Skip to content
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 directives are not showing up in SDL output #269

Open
ethomson1 opened this issue Dec 9, 2023 · 1 comment
Open

Federation directives are not showing up in SDL output #269

ethomson1 opened this issue Dec 9, 2023 · 1 comment

Comments

@ethomson1
Copy link

Hello!! I am trying to convert one of my object types to an entity, but when I pushed the subgraph to my federated graph, the type didn't show up with the @key directive, so I got a composition error when I tried to push the schema for the other subgraph where I want to reference this type.

Then, I tried outputting the schema locally with File.write("schema.graphql", Schema.federation_sdl), and the result was the same -- directive not included.

class MyObjectType < Types::BaseObject
  key fields: :id
  graphql_name 'MyObject'
  description 'Example'

  field :id, ID, null: false
  # ...other fields
end

Then, I have my BaseObject defined like so:

require 'apollo-federation'

module Types
  class BaseObject < GraphQL::Schema::Object
    include ApolloFederation::Object

    field_class BaseField
  end
end

BaseField

require 'apollo-federation'
module Types
  class BaseField < GraphQL::Schema::Field
  include ApolloFederation::Field
  end
end

Schema

require 'apollo-federation'

class Schema < GraphQL::Schema
  include ApolloFederation::Schema
  mutation Graph::MutationType
  query Graph::QueryType

  def self.resolve_type(abstract_type, object, context)
    raise "You need to define resolve_type in #{abstract_type}"
  end

  use GraphQL::Execution::Execute
  use GraphQL::Analysis
end

I tried putting a debugger in ApolloFederation::HasDirectives#add_directive, and that seems to be getting hit with the correct key that needs to be added, so I'm puzzled as to why it doesn't end up in the SDL output.

For reference, I am using apollo-federation 3.8.3 and graphql 1.12.24

@ethomson1
Copy link
Author

Update: I think I may have found the root cause. As shown above, my schema is still using the old GraphQL runtime, instead of the new

use GraphQL::Execution::Interpreter
use GraphQL::Analysis::AST

runtime that is the default as of graphql 1.12.x.

It also seems that as of apollo-federation 2.2.1, the new runtime is the only one that is supported (referencing #177). I previously tried to update my software to use the new runtime, but I got a bunch of unit test failures when I did that. It seems like something changed with the way the library interprets field names in snake_case vs camelCase, and it wasn't clear to me what changes I needed to make to migrate to the new runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant