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

Generate federated schema #106

Closed
AlexKlim opened this issue Oct 2, 2020 · 2 comments
Closed

Generate federated schema #106

AlexKlim opened this issue Oct 2, 2020 · 2 comments

Comments

@AlexKlim
Copy link

AlexKlim commented Oct 2, 2020

Hi all,
I want to generate a federated schema. But I get the schema without any directives/etc.

for instance, I have

class UsersSchema < GraphQL::Schema
  include ApolloFederation::Schema

  orphan_types Types::UserType
end

module Types
  class UserType < Types::BaseObject
    extend_type
    key fields: 'id'
    field :id, ID, null: false, external: true
  end
end

when I use a general way to generate schema into SDL, JSON, I get an incorrect federated schema

type User {
  id: ID!
}

type Query {
  _entities(representations: [_Any!]!): [_Entity]!
  _service: _Service!
}

scalar _Any

union _Entity = User

"""
The sdl representing the federated service capabilities. Includes federation
directives, removes federation types, and includes rest of full schema after
schema directives have been applied
"""
type _Service {
  sdl: String
}

How can I generate a federated schema?

@brettfishman
Copy link

Hello 👋

I think you're looking for something like this?

# Returns the sdl (schema definition language) representing the federated service capabilities. Includes federation
# directives, removes federation types, and includes rest of full schema after schema directives have been applied.
sdl_query = <<-GQL
    {
      _service {
        sdl
      }
    }
GQL

UsersSchema.execute(sdl_query)

I ran into this same issue myself, and someone on the Apollo team provided this solution. Let me know if that works for you.

@lennyburdette
Copy link
Contributor

puts UsersSchema.federation_sdl is even better! I just opened a PR to add this to the readme: #126

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

4 participants