-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(): move apollo last utils to apollo pkg
- Loading branch information
1 parent
abbcac7
commit 7aa8761
Showing
11 changed files
with
132 additions
and
169 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
packages/apollo/lib/factories/graphql-federation-definitions.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { loadPackage } from '@nestjs/common/utils/load-package.util'; | ||
import { | ||
DefinitionsGeneratorOptions, | ||
GraphQLDefinitionsFactory, | ||
} from '@nestjs/graphql-experimental'; | ||
import { extend } from '@nestjs/graphql-experimental/utils'; | ||
import { gql } from 'graphql-tag'; | ||
|
||
export class GraphQLFederationDefinitionsFactory extends GraphQLDefinitionsFactory { | ||
protected async exploreAndEmit( | ||
typePaths: string[], | ||
path: string, | ||
outputAs: 'class' | 'interface', | ||
isDebugEnabled: boolean, | ||
definitionsGeneratorOptions: DefinitionsGeneratorOptions, | ||
typeDefs?: string | string[], | ||
) { | ||
const typePathDefs = await this.gqlTypesLoader.mergeTypesByPaths(typePaths); | ||
const mergedTypeDefs = extend(typePathDefs, typeDefs); | ||
|
||
const { buildSubgraphSchema }: typeof import('@apollo/subgraph') = | ||
loadPackage('@apollo/subgraph', 'ApolloFederation', () => | ||
require('@apollo/subgraph'), | ||
); | ||
|
||
const { printSubgraphSchema } = loadPackage( | ||
'@apollo/subgraph', | ||
'ApolloFederation', | ||
() => require('@apollo/subgraph'), | ||
); | ||
|
||
const schema = buildSubgraphSchema([ | ||
{ | ||
typeDefs: gql` | ||
${mergedTypeDefs} | ||
`, | ||
resolvers: {}, | ||
}, | ||
]); | ||
const tsFile = await this.gqlAstExplorer.explore( | ||
gql` | ||
${printSubgraphSchema(schema)} | ||
`, | ||
path, | ||
outputAs, | ||
definitionsGeneratorOptions, | ||
); | ||
await tsFile.save(); | ||
this.printMessage( | ||
`[${new Date().toLocaleTimeString()}] The definitions have been updated.`, | ||
isDebugEnabled, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './graphql-federation-definitions.factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './adapters'; | ||
export * from './decorators'; | ||
export * from './factories'; | ||
export * from './interfaces'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.