Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Move 'mergeSchemas' from 'merge' to 'schema'
- Loading branch information
Showing
20 changed files
with
102 additions
and
146 deletions.
There are no files selected for viewing
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,9 @@ | ||
--- | ||
'@graphql-tools/merge': major | ||
'@graphql-tools/schema': minor | ||
--- | ||
|
||
Breaking Change; | ||
|
||
Move `mergeSchemas` from `@graphql-tools/merge` to `@graphql-tools/schema` package to prevent circular dependency between them. | ||
|
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
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
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
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
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
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,3 @@ | ||
export * from './merge-resolvers'; | ||
export * from './typedefs-mergers'; | ||
export * from './merge-schemas'; | ||
export * from './extensions'; |
This file was deleted.
Oops, something went wrong.
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
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,58 @@ | ||
import { GraphQLSchema } from 'graphql'; | ||
import { extractExtensionsFromSchema, SchemaExtensions } from '@graphql-tools/merge'; | ||
import { IResolvers, asArray, getResolversFromSchema } from '@graphql-tools/utils'; | ||
import { makeExecutableSchema } from './makeExecutableSchema'; | ||
import { IExecutableSchemaDefinition } from './types'; | ||
|
||
/** | ||
* Configuration object for schema merging | ||
*/ | ||
export type MergeSchemasConfig<T = any> = Partial<IExecutableSchemaDefinition<T>> & | ||
IExecutableSchemaDefinition<T>['parseOptions'] & { | ||
/** | ||
* The schemas to be merged | ||
*/ | ||
schemas?: GraphQLSchema[]; | ||
}; | ||
|
||
/** | ||
* Synchronously merges multiple schemas, typeDefinitions and/or resolvers into a single schema. | ||
* @param config Configuration object | ||
*/ | ||
export function mergeSchemas(config: MergeSchemasConfig) { | ||
const extractedResolvers: IResolvers<any, any>[] = []; | ||
const extractedExtensions: SchemaExtensions[] = asArray(config.extensions || []); | ||
|
||
const schemas = config.schemas || []; | ||
for (const schema of config.schemas || []) { | ||
extractedResolvers.push(getResolversFromSchema(schema)); | ||
extractedExtensions.push(extractExtensionsFromSchema(schema)); | ||
} | ||
|
||
return makeExecutableSchema({ | ||
parseOptions: config, | ||
...config, | ||
typeDefs: asArray(config.typeDefs || []).concat(schemas), | ||
resolvers: asArray(config.resolvers || []).concat(extractedResolvers), | ||
extensions: asArray(config.extensions || []).concat(extractedExtensions), | ||
}); | ||
} | ||
|
||
/** | ||
* Asynchronously merges multiple schemas, typeDefinitions and/or resolvers into a single schema. | ||
* @param config Configuration object | ||
*/ | ||
export async function mergeSchemasAsync(config: MergeSchemasConfig) { | ||
const schemas = config.schemas || []; | ||
const [extractedResolvers, extractedExtensions] = await Promise.all([ | ||
Promise.all(schemas.map(async schema => getResolversFromSchema(schema))), | ||
Promise.all(schemas.map(async schema => extractExtensionsFromSchema(schema))), | ||
]); | ||
|
||
return makeExecutableSchema({ | ||
...config, | ||
typeDefs: asArray(config.typeDefs || []).concat(config.schemas || []), | ||
resolvers: asArray(config.resolvers || []).concat(extractedResolvers), | ||
extensions: asArray(config.extensions || []).concat(extractedExtensions), | ||
}); | ||
} |
Oops, something went wrong.