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

Directives defined in subgraph are not added in supergraph #1892

Closed
AakashSorathiya opened this issue May 26, 2022 · 6 comments
Closed

Directives defined in subgraph are not added in supergraph #1892

AakashSorathiya opened this issue May 26, 2022 · 6 comments

Comments

@AakashSorathiya
Copy link

Directives defined in subgraph schema are not included in supergraph schema.

subgraph schema PERSON :

extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable", "@external"])

scalar link__Import

directive @link(
  url: String!,
  import: [link__Import],
) repeatable on SCHEMA

directive @relation(direction: String = "OUT", from: String = "from", name: String, to: String = "to") on OBJECT | FIELD_DEFINITION

type Person @key(fields: "mail") {
  name: String
  mail: String
  actedIn: [Movie] @relation(name: "ACTED_IN")
}

type Movie @key(fields: "title") {
  title: String
}

type Query {
  person: [Person]
}

subgraph schema MOVIE :

extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable", "@external"])

scalar link__Import

directive @link(
  url: String!,
  import: [link__Import],
) repeatable on SCHEMA

type Movie @key(fields: "title") {
  title: String
  releaseDate: String
  genre: String
}

type Query {
  movie: [Movie]
}

supergraph schema :

schema
  @link(url: "https://specs.apollo.dev/link/v1.0")
  @link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
{
  query: Query
}

directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE

directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

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

scalar join__FieldSet

enum join__Graph {
  MOVIE @join__graph(name: "movie", url: "http://localhost:8081")
  PERSON @join__graph(name: "person", url: "http://localhost:8082")
}

scalar link__Import

enum link__Purpose {
  """
  `SECURITY` features provide metadata necessary to securely resolve fields.
  """
  SECURITY

  """
  `EXECUTION` features provide metadata necessary for operation execution.
  """
  EXECUTION
}

type Movie
  @join__type(graph: MOVIE, key: "title")
  @join__type(graph: PERSON, key: "title")
{
  title: String
  releaseDate: String @join__field(graph: MOVIE)
  genre: String @join__field(graph: MOVIE)
}

type Person
  @join__type(graph: PERSON, key: "mail")
{
  name: String
  mail: String
  actedIn: [Movie]
}

type Query
  @join__type(graph: MOVIE)
  @join__type(graph: PERSON)
{
  movie: [Movie] @join__field(graph: MOVIE)
  person: [Person] @join__field(graph: PERSON)
}

Here in supergraph schema directive relation is not getting added which is defined in subgraph PERSON.
Is there any configuration by which we can enable addition of directives, defined in subgraphs, to supergraph schema?

I am using rover CLI to generate supergraph schema.

Dependencies:

"dependencies": {
    "@apollo/gateway": "^2.0.1",
    "apollo-server": "^3.6.7",
    "apollo-server-types": "^3.5.2",
    "express": "^4.17.1",
    "express-graphql": "^0.12.0",
    "graphql": "^16.0.1"
}
@cpeacock
Copy link
Contributor

Hi there! Thanks for sending in the issue. We were literally in the process of writing it up in #1893 when you sent this in, I'm going to close this in favor of that, but please take a look and add comments on it (even if it's the body of this issue). Happy federating!

@chandakakshat
Copy link

Hii, @cpeacock @clenfest This issue seems to persist in latest version as well
Is there any configuration by which we can enable addition of directives, defined in subgraphs, to supergraph schema?

I am also using rover CLI to generate supergraph schema.

  "dependencies": {
    "@apollo/gateway": "^2.2.1",
    "@apollo/rover": "^0.10.0",
    "@apollo/subgraph": "^2.2.1",
    "apollo": "^2.34.0",
    "apollo-server": "^3.6.7",
    "apollo-server-types": "^3.5.2",
    "graphql": "^16.6.0",
    "node-gyp": "^9.3.0"
  },

@clenfest
Copy link
Contributor

Hey @chandakakshat. Have you tried using the @composeDirective documentation found here? https://www.apollographql.com/docs/federation/federated-types/federated-directives/#composedirective

If not, would you mind writing up an example explaining what the issue is?
Thanks.

@chandakakshat
Copy link

chandakakshat commented Dec 1, 2022

Hii, @clenfest @cpeacock
I went through the documentation of composeDirective and tried to implement it, But found this error UNKNOWN: Directive "@relation" in subgraph "sub2" cannot be composed because it is not a member of a core feature

Tried adding the directive as core feature using @link but the documentation of URL suggests a format for specifying URL in the @link directive

Also, why do we need to provide directive specification using @link, when its already defined in the subgraph as follows

extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable", "@composeDirective"])
@composeDirective(name: "@relation")
directive @composeDirective(name: String!) repeatable on SCHEMA
directive @relation(direction: String = "OUT", from: String = "from", name: String, to: String = "to") on OBJECT | FIELD_DEFINITION

@chandakakshat
Copy link

Hii, @clenfest @cpeacock I went through the documentation of composeDirective and tried to implement it, But found this error UNKNOWN: Directive "@relation" in subgraph "sub2" cannot be composed because it is not a member of a core feature

Tried adding the directive as core feature using @link but the documentation of URL suggests a format for specifying URL in the @link directive

Also, why do we need to provide directive specification using @link, when its already defined in the subgraph as follows

extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable", "@composeDirective"])
@composeDirective(name: "@relation")
directive @composeDirective(name: String!) repeatable on SCHEMA
directive @relation(direction: String = "OUT", from: String = "from", name: String, to: String = "to") on OBJECT | FIELD_DEFINITION

Hii, @clenfest, @cpeacock any updates on this ?

@trevor-scheer
Copy link
Member

@chandakakshat it looks like you need to bump your federation version (package versions and spec versions in the SDL) to at least v2.1. Based on the snippet above, you also need to provide a @link usage for your directive and you shouldn't be providing your own definition for @composeDirective. Take a closer look at the docs that Chris linked and make sure your configuration matches the pattern correctly. If you're still having issues please paste an updated snippet or a reproduction.

Incorporating the changes I suggested should look like this:

extend schema
  @link(
    url: "https://specs.apollo.dev/federation/v2.4"
    import: ["@key", "@shareable", "@composeDirective"]
  )
  @link(
    url: "https://myRelationDirectiveSpec.dev/v1.0"
    import: ["@myDirective"]
  )
  @composeDirective(name: "@relation")

directive @relation(
  direction: String = "OUT"
  from: String = "from"
  name: String
  to: String = "to"
) on OBJECT | FIELD_DEFINITION

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

5 participants