Skip to content

Federation directives are not showing up in SDL output #269

@ethomson1

Description

@ethomson1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions