2

Hello I'm trying to federate two example APIs (built using latest Apollo server) but when I try to run rover supergraph compose --config ./supergraph.yaml I get this error:

rover supergraph compose --config ./supergraph.yaml
Composing supergraph with Federation v2.0.5.
error[E029]: Encountered 1 build error while trying to build a supergraph.

Caused by:
    UNKNOWN: Error: Cannot find type __Schema in destination schema (with types: link__Purpose, link__Import, join__Graph, join__FieldSet, CreateUserInput, DateTime, DeleteUserInput, EmailAddress, JWT, Mutation, PhoneNumber, Query, RegisterError, RegisterResponse, RegisterSuccess, Token, UpdateUserInput, User, _FieldSet)
    
        The subgraph schemas you provided are incompatible with each other. See https://www.apollographql.com/docs/federation/errors/ for more information on resolving build errors.

This is my supergraph.yaml file:

federation_version: 2
subgraphs:
  auth:
    routing_url: http://localhost:1313/
    schema:
      file: auth-api/generated/service.graphql
  orders:
    routing_url: http://localhost:1312/
    schema:
      file: order-api/generated/service.graphql

I generate individual service schemas using graphql-codegen-schema-ast package with these settings in codegen.yaml:

schema:
  - "entities/**/*.graphql"
  - "extensions/**/*.graphql"
generates:
  ./generated/service.graphql:
    plugins:
      - schema-ast
    config:
      commentDescriptions: true
      includeDirectives: true
      includeIntrospectionTypes: true
      federation: true
  ./generated/types.ts:
    plugins:
      - typescript
      - typescript-resolvers
    config:
      federation: true
      useIndexSignature: true
      useTypeImports: true
      skipTypename: true
      optionalInfoArgument: true
      contextType: ../index#Context
      allowParentTypeOverride: true
      makeResolverTypeCallable: true
      mapperTypeSuffix: Model

      # mappers:
      #   _FieldSet: "federated__FieldSet"

      # Custom scalars package
      scalars:
        AccountNumber: string
       # ...otherCustomScalars

So both services are able to run, I see all needed directives in Apollo Studio as well as "subgraph" badge but rover can't compose a supergraph. Also tried with graphql-codegen but apparently that does not generate compatible supergraph (does not put core directives and graph connections, just mashes the thing together).

And finally these are schemas that I want to federate (I will post just one service schema, since I'm using only that one to just get the federation going, the other service is very similar in terms of federation directives etc.):

Thanks!

"""
Marks an element of a GraphQL schema as no longer supported.
"""
directive @deprecated(
  """
  Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).
  """
  reason: String = "No longer supported"
) on ARGUMENT_DEFINITION | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION

"""
Directs the executor to include this field or fragment only when the `if` argument is true.
"""
directive @include(
  """
  Included when true.
  """
  if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"""
Directs the executor to skip this field or fragment when the `if` argument is true.
"""
directive @skip(
  """
  Skipped when true.
  """
  if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"""
Exposes a URL that specifies the behavior of this scalar.
"""
directive @specifiedBy(
  """
  The URL that specifies the behavior of this scalar.
  """
  url: String!
) on SCALAR

"""
A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.
"""
type __Schema {
  description: String

  """
  A list of all types supported by this server.
  """
  types: [__Type!]!

  """
  The type that query operations will be rooted at.
  """
  queryType: __Type!

  """
  If this server supports mutation, the type that mutation operations will be rooted at.
  """
  mutationType: __Type

  """
  If this server support subscription, the type that subscription operations will be rooted at.
  """
  subscriptionType: __Type

  """
  A list of all directives supported by this server.
  """
  directives: [__Directive!]!
}

"""
The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.

Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByURL`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
"""
type __Type {
  kind: __TypeKind!
  name: String
  description: String
  specifiedByURL: String
  fields(includeDeprecated: Boolean = false): [__Field!]
  interfaces: [__Type!]
  possibleTypes: [__Type!]
  enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
  inputFields(includeDeprecated: Boolean = false): [__InputValue!]
  ofType: __Type
}

"""
An enum describing what kind of type a given `__Type` is.
"""
enum __TypeKind {
  """
  Indicates this type is a scalar.
  """
  SCALAR

  """
  Indicates this type is an object. `fields` and `interfaces` are valid fields.
  """
  OBJECT

  """
  Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields.
  """
  INTERFACE

  """
  Indicates this type is a union. `possibleTypes` is a valid field.
  """
  UNION

  """
  Indicates this type is an enum. `enumValues` is a valid field.
  """
  ENUM

  """
  Indicates this type is an input object. `inputFields` is a valid field.
  """
  INPUT_OBJECT

  """
  Indicates this type is a list. `ofType` is a valid field.
  """
  LIST

  """
  Indicates this type is a non-null. `ofType` is a valid field.
  """
  NON_NULL
}

"""
Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.
"""
type __Field {
  name: String!
  description: String
  args(includeDeprecated: Boolean = false): [__InputValue!]!
  type: __Type!
  isDeprecated: Boolean!
  deprecationReason: String
}

"""
Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.
"""
type __InputValue {
  name: String!
  description: String
  type: __Type!

  """
  A GraphQL-formatted string representing the default value for this input value.
  """
  defaultValue: String
  isDeprecated: Boolean!
  deprecationReason: String
}

"""
One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.
"""
type __EnumValue {
  name: String!
  description: String
  isDeprecated: Boolean!
  deprecationReason: String
}

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.

In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
"""
type __Directive {
  name: String!
  description: String
  isRepeatable: Boolean!
  locations: [__DirectiveLocation!]!
  args(includeDeprecated: Boolean = false): [__InputValue!]!
}

"""
A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.
"""
enum __DirectiveLocation {
  """
  Location adjacent to a query operation.
  """
  QUERY

  """
  Location adjacent to a mutation operation.
  """
  MUTATION

  """
  Location adjacent to a subscription operation.
  """
  SUBSCRIPTION

  """
  Location adjacent to a field.
  """
  FIELD

  """
  Location adjacent to a fragment definition.
  """
  FRAGMENT_DEFINITION

  """
  Location adjacent to a fragment spread.
  """
  FRAGMENT_SPREAD

  """
  Location adjacent to an inline fragment.
  """
  INLINE_FRAGMENT

  """
  Location adjacent to a variable definition.
  """
  VARIABLE_DEFINITION

  """
  Location adjacent to a schema definition.
  """
  SCHEMA

  """
  Location adjacent to a scalar definition.
  """
  SCALAR

  """
  Location adjacent to an object type definition.
  """
  OBJECT

  """
  Location adjacent to a field definition.
  """
  FIELD_DEFINITION

  """
  Location adjacent to an argument definition.
  """
  ARGUMENT_DEFINITION

  """
  Location adjacent to an interface definition.
  """
  INTERFACE

  """
  Location adjacent to a union definition.
  """
  UNION

  """
  Location adjacent to an enum definition.
  """
  ENUM

  """
  Location adjacent to an enum value definition.
  """
  ENUM_VALUE

  """
  Location adjacent to an input object type definition.
  """
  INPUT_OBJECT

  """
  Location adjacent to an input object field definition.
  """
  INPUT_FIELD_DEFINITION
}
schema
  @link(url: "https://specs.apollo.dev/link/v1.0")
  @link(
    url: "https://specs.apollo.dev/federation/v2.0"
    import: [
      "@key"
      "@requires"
      "@provides"
      "@external"
      "@extends"
      "@shareable"
      "@inaccessible"
      "@override"
    ]
  ) {
  query: Query
  mutation: Mutation
}

directive @extends on INTERFACE | OBJECT

directive @external on FIELD_DEFINITION

directive @inaccessible on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION

directive @key(
  fields: federation__FieldSet!
  resolvable: Boolean = true
) repeatable on INTERFACE | OBJECT

directive @link(
  as: String
  for: link__Purpose
  import: [link__Import]
  url: String
) repeatable on SCHEMA

directive @override(from: String!) on FIELD_DEFINITION

directive @provides(fields: federation__FieldSet!) on FIELD_DEFINITION

directive @requires(fields: federation__FieldSet!) on FIELD_DEFINITION

directive @shareable on FIELD_DEFINITION | OBJECT

input CreateUserInput {
  email: EmailAddress!
  name: String!
  phoneNumber: PhoneNumber!
}

scalar DateTime

input DeleteUserInput {
  userIDs: [ID!]!
}

scalar EmailAddress

scalar JWT

type Mutation {
  register(input: CreateUserInput): RegisterResponse
  updateUser(input: UpdateUserInput!): User
}

scalar PhoneNumber

type Query {
  allUsers: [User!]!
  user(id: ID!): User
  __schema: __Schema!
  __type(name: String!): __Type
}

type RegisterError {
  error: String!
  success: Boolean!
}

union RegisterResponse = RegisterError | RegisterSuccess

type RegisterSuccess {
  profile: User!
  success: Boolean!
  token: Token!
}

type Token {
  authorization: JWT!
  refresh: JWT!
}

input UpdateUserInput {
  email: EmailAddress!
  name: String
  phoneNumber: PhoneNumber!
}

type User @key(fields: "id") {
  active: Boolean!
  createdAt: DateTime!
  email: EmailAddress!
  id: ID!
  name: String!
  phoneNumber: PhoneNumber!
  updatedAt: DateTime!
}

scalar _Any

scalar _FieldSet

scalar federation__FieldSet

scalar link__Import

enum link__Purpose {
  """
  `EXECUTION` features provide metadata necessary for operation execution.
  """
  EXECUTION
  """
  `SECURITY` features provide metadata necessary to securely resolve fields.
  """
  SECURITY
}

```

"""
Marks an element of a GraphQL schema as no longer supported.
"""
directive @deprecated(
  """
  Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).
  """
  reason: String = "No longer supported"
) on ARGUMENT_DEFINITION | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION

"""
Directs the executor to include this field or fragment only when the `if` argument is true.
"""
directive @include(
  """
  Included when true.
  """
  if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"""
Directs the executor to skip this field or fragment when the `if` argument is true.
"""
directive @skip(
  """
  Skipped when true.
  """
  if: Boolean!
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

"""
Exposes a URL that specifies the behavior of this scalar.
"""
directive @specifiedBy(
  """
  The URL that specifies the behavior of this scalar.
  """
  url: String!
) on SCALAR

"""
A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.
"""
type __Schema {
  description: String

  """
  A list of all types supported by this server.
  """
  types: [__Type!]!

  """
  The type that query operations will be rooted at.
  """
  queryType: __Type!

  """
  If this server supports mutation, the type that mutation operations will be rooted at.
  """
  mutationType: __Type

  """
  If this server support subscription, the type that subscription operations will be rooted at.
  """
  subscriptionType: __Type

  """
  A list of all directives supported by this server.
  """
  directives: [__Directive!]!
}

"""
The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.

Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByURL`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
"""
type __Type {
  kind: __TypeKind!
  name: String
  description: String
  specifiedByURL: String
  fields(includeDeprecated: Boolean = false): [__Field!]
  interfaces: [__Type!]
  possibleTypes: [__Type!]
  enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
  inputFields(includeDeprecated: Boolean = false): [__InputValue!]
  ofType: __Type
}

"""
An enum describing what kind of type a given `__Type` is.
"""
enum __TypeKind {
  """
  Indicates this type is a scalar.
  """
  SCALAR

  """
  Indicates this type is an object. `fields` and `interfaces` are valid fields.
  """
  OBJECT

  """
  Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields.
  """
  INTERFACE

  """
  Indicates this type is a union. `possibleTypes` is a valid field.
  """
  UNION

  """
  Indicates this type is an enum. `enumValues` is a valid field.
  """
  ENUM

  """
  Indicates this type is an input object. `inputFields` is a valid field.
  """
  INPUT_OBJECT

  """
  Indicates this type is a list. `ofType` is a valid field.
  """
  LIST

  """
  Indicates this type is a non-null. `ofType` is a valid field.
  """
  NON_NULL
}

"""
Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.
"""
type __Field {
  name: String!
  description: String
  args(includeDeprecated: Boolean = false): [__InputValue!]!
  type: __Type!
  isDeprecated: Boolean!
  deprecationReason: String
}

"""
Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.
"""
type __InputValue {
  name: String!
  description: String
  type: __Type!

  """
  A GraphQL-formatted string representing the default value for this input value.
  """
  defaultValue: String
  isDeprecated: Boolean!
  deprecationReason: String
}

"""
One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.
"""
type __EnumValue {
  name: String!
  description: String
  isDeprecated: Boolean!
  deprecationReason: String
}

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.

In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
"""
type __Directive {
  name: String!
  description: String
  isRepeatable: Boolean!
  locations: [__DirectiveLocation!]!
  args(includeDeprecated: Boolean = false): [__InputValue!]!
}

"""
A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.
"""
enum __DirectiveLocation {
  """
  Location adjacent to a query operation.
  """
  QUERY

  """
  Location adjacent to a mutation operation.
  """
  MUTATION

  """
  Location adjacent to a subscription operation.
  """
  SUBSCRIPTION

  """
  Location adjacent to a field.
  """
  FIELD

  """
  Location adjacent to a fragment definition.
  """
  FRAGMENT_DEFINITION

  """
  Location adjacent to a fragment spread.
  """
  FRAGMENT_SPREAD

  """
  Location adjacent to an inline fragment.
  """
  INLINE_FRAGMENT

  """
  Location adjacent to a variable definition.
  """
  VARIABLE_DEFINITION

  """
  Location adjacent to a schema definition.
  """
  SCHEMA

  """
  Location adjacent to a scalar definition.
  """
  SCALAR

  """
  Location adjacent to an object type definition.
  """
  OBJECT

  """
  Location adjacent to a field definition.
  """
  FIELD_DEFINITION

  """
  Location adjacent to an argument definition.
  """
  ARGUMENT_DEFINITION

  """
  Location adjacent to an interface definition.
  """
  INTERFACE

  """
  Location adjacent to a union definition.
  """
  UNION

  """
  Location adjacent to an enum definition.
  """
  ENUM

  """
  Location adjacent to an enum value definition.
  """
  ENUM_VALUE

  """
  Location adjacent to an input object type definition.
  """
  INPUT_OBJECT

  """
  Location adjacent to an input object field definition.
  """
  INPUT_FIELD_DEFINITION
}
schema
  @link(url: "https://specs.apollo.dev/link/v1.0")
  @link(
    url: "https://specs.apollo.dev/federation/v2.0"
    import: [
      "@key"
      "@requires"
      "@provides"
      "@external"
      "@extends"
      "@shareable"
      "@inaccessible"
      "@override"
    ]
  ) {
  query: Query
  mutation: Mutation
}

directive @extends on INTERFACE | OBJECT

directive @external on FIELD_DEFINITION

directive @inaccessible on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION

directive @key(
  fields: federation__FieldSet!
  resolvable: Boolean = true
) repeatable on INTERFACE | OBJECT

directive @link(
  as: String
  for: link__Purpose
  import: [link__Import]
  url: String
) repeatable on SCHEMA

directive @override(from: String!) on FIELD_DEFINITION

directive @provides(fields: federation__FieldSet!) on FIELD_DEFINITION

directive @requires(fields: federation__FieldSet!) on FIELD_DEFINITION

directive @shareable on FIELD_DEFINITION | OBJECT

input CreateUserInput {
  email: EmailAddress!
  name: String!
  phoneNumber: PhoneNumber!
}

scalar DateTime

input DeleteUserInput {
  userIDs: [ID!]!
}

scalar EmailAddress

scalar JWT

type Mutation {
  register(input: CreateUserInput): RegisterResponse
  updateUser(input: UpdateUserInput!): User
}

scalar PhoneNumber

type Query {
  allUsers: [User!]!
  user(id: ID!): User
  __schema: __Schema!
  __type(name: String!): __Type
}

type RegisterError {
  error: String!
  success: Boolean!
}

union RegisterResponse = RegisterError | RegisterSuccess

type RegisterSuccess {
  profile: User!
  success: Boolean!
  token: Token!
}

type Token {
  authorization: JWT!
  refresh: JWT!
}

input UpdateUserInput {
  email: EmailAddress!
  name: String
  phoneNumber: PhoneNumber!
}

type User @key(fields: "id") {
  active: Boolean!
  createdAt: DateTime!
  email: EmailAddress!
  id: ID!
  name: String!
  phoneNumber: PhoneNumber!
  updatedAt: DateTime!
}

scalar _Any

scalar _FieldSet

scalar federation__FieldSet

scalar link__Import

enum link__Purpose {
  """
  EXECUTION features provide metadata necessary for operation execution.
  """
  EXECUTION
  """
  SECURITY features provide metadata necessary to securely resolve fields.
  """
  SECURITY
}
Jakša Mališić
  • 345
  • 7
  • 13

0 Answers0