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
Support Apollo Federation 2 #2251
Support Apollo Federation 2 #2251
Conversation
As a suggestion, get rid of Then Handle a |
Thanks for your contribution @greguintow. I think @ChrisBates suggestion about using the |
Thanks @kamilmysliwiec and @ChrisBates , I'll make the changes shortly |
@kamilmysliwiec @ChrisBates I've finished the changes, please review it! |
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable", "@external", "@override", "@requires"]) | ||
* ``` | ||
*/ | ||
useFed2?: UseFed2Value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to be pedantic- but wouldn't federationVersion?: FederationVersion
(an enum or similar) be more flexible to future changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Teagan42 I think that we wouldn't have such a big change as we had with apollo federation 2 vs 1 in any near future. Due to to how is setup, I think would be best to just be like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @Teagan42 - we don't know what the future brings, but we know for certain that Fed V2 won't be the latest version forever and we'll eventually need to deprecate a useFed2
property. At least federationVersion
can have the default updated to adopt the current version, and overwritten for backward compatibility (where people need it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to accommodate future changes, using a scalable/flexible pattern will shield the project from having to do deep refactoring. I added comments to your PR with some suggestions, future contributors will be thankful if you use a factory or provider pattern instead of rigid checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greguintow Let me know if you're interested in making these changes, otherwise, I'll take over! 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kamilmysliwiec I'd have time for it this weekend, if that's okay
GraphQLModule.forRoot<ApolloDriverConfig>({ | ||
driver: ApolloFederationDriver, | ||
autoSchemaFile: { | ||
useFed2: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request] federationVersion: 2
@@ -10,6 +10,7 @@ const config: Config.InitialOptions = { | |||
moduleFileExtensions: ['js', 'json', 'ts'], | |||
rootDir: '../.', | |||
testRegex: '.spec.ts$', | |||
testPathIgnorePatterns: ['.fed2-spec.ts$'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request] .fed.$versions-spec.ts
|
||
const isApolloSubgraph2 = Number(apolloSubgraphVersion.split('.')[0]) >= 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request]
const apolloSubgraphVersion = Number(...)
[Suggestion]
const apolloSubgraphVersion = Number(/^(\d+)\..*/)
@@ -105,9 +114,49 @@ export class GraphQLFederationFactory { | |||
options, | |||
this.resolversExplorerService.getAllCtors(), | |||
); | |||
let typeDefs = isApolloSubgraph2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] SchemaPrinterFactory(version: number)
|
||
const useFed2 = getFederation2Info(options.autoSchemaFile); | ||
|
||
if (useFed2 && isApolloSubgraph2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request] Pattern does not scale, implement a factory or mapping
options: T, | ||
resolvers: Function[], | ||
) { | ||
const scalarsMap = this.scalarsExplorerService.getScalarsMap(); | ||
try { | ||
const buildSchemaOptions = options.buildSchemaOptions || {}; | ||
const useFed2 = getFederation2Info(options.autoSchemaFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request] FederatedDirectivesProvider(version: number)
as: string; | ||
} | ||
|
||
export interface Federation2Config { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request] Utilize type composition
type FederationConfig1 = boolean
type FederationConfig2 = { ... }
type FederationConfig = FederationConfig1 | FederationConfig2
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable", "@external", "@override", "@requires"]) | ||
* ``` | ||
*/ | ||
useFed2?: UseFed2Value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request] federationConfig: FederationConfig
import { isString, isObject } from '@nestjs/common/utils/shared.utils'; | ||
import { AutoSchemaFileValue, UseFed2Value } from '../interfaces'; | ||
|
||
export function getPathForAutoSchemaFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Change Request] Factory or Provider pattern
Can't get a federation working currently, are there any news on this PR? Which are the latest versions I can use to make a federated graph work with nestjs otherwise? |
I use "@apollo/federation": "^0.36.1", "@nestjs/graphql": "^10.0.18", "graphql": "^15.7.2", you have to avoid apollo federation 2 packages and not go above 15.7 in graphql. |
Turns out I was using |
@NeutronScott12 @cristian-moreno-ruiz just to note, |
@greguintow Let me know if you're busy and if so, I'll take over & address the proposed changes! 🙌 |
@kamilmysliwiec Yeah, I'm busy at the moment, please take over |
I'm so confused... is this working or not? Documentation says it should "just work" by using Edit: Fixed by adding the |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #2141
This also fixes:
What is the new behavior?
Allows to add a property called
useFed2
insideautoSchemaFile
that will make the necessary schema changes to be considered a federation 2 schema:https://github.com/greguintow/nestjs-graphql/blob/cb6090d766c78af96a628358c10d7efaca61ba9e/packages/apollo/tests/code-first-graphql-federation2/users-service/federation-users.module.ts#L12-L14
By default will add:
But that can be customized as
useFed2
type isboolean | Federation2Config
Does this PR introduce a breaking change?
cc @trevor-scheer @hwillson