diff --git a/packages/graphql-tools/package.json b/packages/graphql-tools/package.json index 35c043a3298..c38cc5f464d 100644 --- a/packages/graphql-tools/package.json +++ b/packages/graphql-tools/package.json @@ -24,6 +24,13 @@ "@graphql-tools/import": "6.0.0", "@graphql-tools/links": "6.0.0", "@graphql-tools/load": "6.0.0", + "@graphql-tools/code-file-loader": "6.0.0", + "@graphql-tools/git-loader": "6.0.0", + "@graphql-tools/github-loader": "6.0.0", + "@graphql-tools/graphql-file-loader": "6.0.0", + "@graphql-tools/json-file-loader": "6.0.0", + "@graphql-tools/module-loader": "6.0.0", + "@graphql-tools/url-loader": "6.0.0", "@graphql-tools/load-files": "6.0.0", "@graphql-tools/merge": "6.0.0", "@graphql-tools/mock": "6.0.0", @@ -31,6 +38,7 @@ "@graphql-tools/resolvers-composition": "6.0.0", "@graphql-tools/schema": "6.0.0", "@graphql-tools/stitch": "6.0.0", - "@graphql-tools/utils": "6.0.0" + "@graphql-tools/utils": "6.0.0", + "@graphql-tools/wrap": "6.0.0" } -} \ No newline at end of file +} diff --git a/packages/graphql-tools/src/index.ts b/packages/graphql-tools/src/index.ts index 21cc2ff88f0..3e91ade0a88 100644 --- a/packages/graphql-tools/src/index.ts +++ b/packages/graphql-tools/src/index.ts @@ -3,6 +3,12 @@ export * from '@graphql-tools/graphql-tag-pluck'; export * from '@graphql-tools/import'; export * from '@graphql-tools/links'; export * from '@graphql-tools/load'; +export * from '@graphql-tools/code-file-loader'; +export * from '@graphql-tools/git-loader'; +export * from '@graphql-tools/github-loader'; +export * from '@graphql-tools/graphql-file-loader'; +export * from '@graphql-tools/module-loader'; +export * from '@graphql-tools/url-loader'; export * from '@graphql-tools/load-files'; export * from '@graphql-tools/merge'; export * from '@graphql-tools/mock'; diff --git a/packages/merge/package.json b/packages/merge/package.json index 26f2450b868..71ec153a75f 100644 --- a/packages/merge/package.json +++ b/packages/merge/package.json @@ -27,4 +27,4 @@ "access": "public", "directory": "dist" } -} \ No newline at end of file +} diff --git a/packages/merge/tests/merge-schemas.spec.ts b/packages/merge/tests/merge-schemas.spec.ts index 94888671c51..2415f062ad9 100644 --- a/packages/merge/tests/merge-schemas.spec.ts +++ b/packages/merge/tests/merge-schemas.spec.ts @@ -1,5 +1,5 @@ import { makeExecutableSchema } from '@graphql-tools/schema'; -import { graphql, buildSchema, GraphQLScalarType, Kind, GraphQLSchema, ListValueNode } from 'graphql'; +import { graphql, buildSchema, GraphQLScalarType, Kind, GraphQLSchema, ListValueNode, printSchema } from 'graphql'; import { mergeSchemas, mergeSchemasAsync } from '../src/merge-schemas'; describe('Merge Schemas', () => { @@ -411,7 +411,7 @@ describe('Merge Schemas', () => { expect(merged.getDirective('date')).toBeDefined(); }); - it.only('should merge a lot of directives but without high memory usage', () => { + it('should merge a lot of directives but without high memory usage', () => { let num = 100; const base = buildSchema(/* GraphQL */` directive @access(roles: [String]) on FIELD_DEFINITION @@ -429,4 +429,69 @@ describe('Merge Schemas', () => { expect((prev.getQueryType().getFields().test.astNode.directives[0].arguments[0].value as ListValueNode).values).toHaveLength(1); }); + it('should merge schemas with custom scalars', () => { + const GraphQLUUID = new GraphQLScalarType({ + name: 'UUID', + serialize: val => val, + parseValue: val => val, + parseLiteral: valueNode => { + if (valueNode.kind === 'StringValue') { + return valueNode.value; + } + return null; + } + }) + const countrySchema = makeExecutableSchema({ + typeDefs: ` + scalar UUID + type Country { + id: UUID! + name: String + } + type Query { + country: Country + } + `, + resolvers: { + UUID: GraphQLUUID, + } + }) + + + const citySchema = makeExecutableSchema({ + typeDefs: ` + scalar UUID + type City { + id: ID! + name: String + } + type Query { + city: City + } + `, + }) + + const mergedSchema = mergeSchemas({ + schemas: [ + countrySchema, + citySchema, + ] + }); + + expect(printSchema(mergedSchema)).toContain(` +type Query { + country: Country + city: City +} +scalar UUID +type Country { + id: UUID! + name: String +} +type City { + id: ID! + name: String +} + `) + }) }); diff --git a/packages/utils/src/mergeDeep.ts b/packages/utils/src/mergeDeep.ts index ae5a389ec9a..8aea0df65cb 100644 --- a/packages/utils/src/mergeDeep.ts +++ b/packages/utils/src/mergeDeep.ts @@ -1,10 +1,16 @@ -export function mergeDeep(target: any, ...sources: any): any { +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { isScalarType } from 'graphql'; + +export function mergeDeep(target: any, ...sources: any[]): any { + if (isScalarType(target)) { + return target; + } const output = { ...target, }; - sources.forEach((source: any) => { + for (const source of sources) { if (isObject(target) && isObject(source)) { - Object.keys(source).forEach(key => { + for (const key in source) { if (isObject(source[key])) { if (!(key in target)) { Object.assign(output, { [key]: source[key] }); @@ -14,9 +20,9 @@ export function mergeDeep(target: any, ...sources: any): any { } else { Object.assign(output, { [key]: source[key] }); } - }); + } } - }); + } return output; } diff --git a/yarn.lock b/yarn.lock index 70d8eae28ed..73760d69cb6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6322,6 +6322,11 @@ graphql-type-json@0.3.1: resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.3.1.tgz#47fca2b1fa7adc0758d165b33580d7be7a6cf548" integrity sha512-1lPkUXQ2L8o+ERLzVAuc3rzc/E6pGF+6HnjihCVTK0VzR0jCuUd92FqNxoHdfILXqOn2L6b4y47TBxiPyieUVA== +graphql-type-uuid@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/graphql-type-uuid/-/graphql-type-uuid-0.2.0.tgz#677a363a93d1b04c4844d20b35ffab7a1d5e6b6a" + integrity sha1-Z3o2OpPRsExIRNILNf+reh1ea2o= + graphql-upload@10.0.0: version "10.0.0" resolved "https://registry.yarnpkg.com/graphql-upload/-/graphql-upload-10.0.0.tgz#1020c8ac6208c8cdf9de1f6ad9000eab7467e00f"