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

Gradle Plugin Doesn't Generate Federation Directives #2242

Open
kartomic8 opened this issue Dec 16, 2024 · 2 comments
Open

Gradle Plugin Doesn't Generate Federation Directives #2242

kartomic8 opened this issue Dec 16, 2024 · 2 comments

Comments

@kartomic8
Copy link

kartomic8 commented Dec 16, 2024

When using the Gradle Plugin (v2.6.2), the output of the generateSchema gradle task does not appear to generate federation-compatible directives.

Sample code:

generateSchema {
    destination = "build/generated/schema.graphql"
    includeTransitiveDependencies = true
    includeDirectives = true
    includeScalars = true
}
// Example of annotated class
@Data
@AllArgsConstructor
@Shareable
public class Menu {
  @NonNull List<MenuItem> menuItems;
}
# generated graphql
# expected @shareable directive in the line below, but it is not there:

type Menu {
  menuItems: [MenuItem]!
}


# In addition, the federation directives aren't imported, nor are they defined in the output.

I took a look at the maven plugin, which does appear to implement federation, and I can't find similar code in the gradle plugin, so I believe its just not implemented. Can the team confirm, and if it isn't implemented advise on a timeframe for doing so?

@jmartisk
Copy link
Member

Hi, currently the plugin assumes that it should enable Federation if at least one of these conditions is true:

If this is not good enough, we welcome suggestions on how to improve it

@kartomic8
Copy link
Author

Thanks for responding. @jmartisk, looks like most of it was user error, enabling the appopriate settings resulted in those directives being added to the schema. However, there's one thing I wanted to inquire about that we weren't able to figure out. We're using the Apollo Federated Router in our environment, and from playing around with it it seems to want us to import directives rather than redefine them.

E.g. This works with apollo router:

extend schema
  @link(url: "https://specs.apollo.dev/federation/v2.7",
        import: ["@key"]) {
  query: Query
  mutation: Mutation
}

But this generated output from the smallrye doesn't

"Designates an object type as an entity and specifies its key fields (a set of fields that the subgraph can use to uniquely identify any instance of the entity). You can apply multiple @key directives to a single entity (to specify multiple valid sets of key fields)."
directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE

Is there a way we can get the smallrye-graphql library to emit the extend schema style of importing directions from the federation spec?

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

2 participants