Skip to content

Commit

Permalink
initial attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Apr 28, 2020
1 parent cad8057 commit 47507fd
Show file tree
Hide file tree
Showing 91 changed files with 2,463 additions and 1,679 deletions.
2 changes: 1 addition & 1 deletion packages/loaders/url/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@graphql-tools/utils';
import { isWebUri } from 'valid-url';
import { fetch as crossFetch } from 'cross-fetch';
import { makeRemoteExecutableSchema, introspectSchema } from '@graphql-tools/schema-stitching';
import { makeRemoteExecutableSchema, introspectSchema } from '@graphql-tools/schema-wrapping';

export type FetchFn = typeof import('cross-fetch').fetch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* A very simple class for logging errors
*/

import { ILogger } from '@graphql-tools/schema-generator';
import { ILogger } from '../src/types';

export class Logger implements ILogger {
public errors: Array<Error>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse } from 'graphql';

import { extractExtensionDefinitions } from '@graphql-tools/schema-generator';
import { extractExtensionDefinitions } from '../src/extensionDefinitions';

describe('Extension extraction', () => {
test('extracts extended inputs', () => {
Expand Down
19 changes: 19 additions & 0 deletions packages/schema-generator/tests/forAwaitEach.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable callback-return */
/* eslint-disable @typescript-eslint/await-thenable */

function isAsyncIterable<T>(obj: any): obj is AsyncIterable<T> {
return Symbol.asyncIterator in obj;
}

export async function forAwaitEach<T>(
obj: AsyncIterable<T> | T,
callback: (i: T) => any | Promise<any>,
) {
if (isAsyncIterable(obj)) {
for await (const i of obj) {
await callback(i);
}
} else {
await callback(obj);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable promise/param-names */
import { graphql } from 'graphql';

import { makeExecutableSchema } from '@graphql-tools/schema-generator';
import { makeExecutableSchema } from '../src/makeExecutableSchema';

import { Logger } from './Logger';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'graphql';
import { PubSub } from 'graphql-subscriptions';

import { makeExecutableSchema, addSchemaLevelResolver } from '@graphql-tools/schema-generator';
import { makeExecutableSchema, addSchemaLevelResolver } from '../src/index';

import { forAwaitEach } from './forAwaitEach';

Expand Down
22 changes: 11 additions & 11 deletions packages/schema-generator/tests/schemaGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ import {
GraphQLSchema,
} from 'graphql';

import {
makeExecutableSchema,
addErrorLoggingToSchema,
addSchemaLevelResolver,
addResolversToSchema,
attachDirectiveResolvers,
chainResolvers,
concatenateTypeDefs,
} from '@graphql-tools/schema-generator';

import {
IResolverValidationOptions,
IResolvers,
IDirectiveResolvers,
NextResolverFn,
VisitSchemaKind,
ITypeDefinitions,
ILogger,
visitSchema
} from '@graphql-tools/utils';

import {
makeExecutableSchema,
addErrorLoggingToSchema,
addSchemaLevelResolver,
addResolversToSchema,
attachDirectiveResolvers,
chainResolvers,
concatenateTypeDefs,
ILogger,
} from '../src/index';

import TypeA from './fixtures/circularSchemaA';

interface Bird {
Expand Down
5 changes: 1 addition & 4 deletions packages/schema-stitching/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export * from './delegate';
export * from './introspect';
export * from './stitch';
export * from './wrap';
export * from './stitchSchemas';
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import {
parseSelectionSet,
forEachField,
} from '@graphql-tools/utils';
import ExpandAbstractTypes from '../delegate/transforms/ExpandAbstractTypes';
import AddReplacementFragments from '../delegate/transforms/AddReplacementFragments';

import { delegateToSchema } from '../delegate/delegateToSchema';
import { IDelegateToSchemaOptions, MergedTypeInfo } from '../delegate/types';
import { MergeTypeCandidate, MergeInfo, IResolversParameter, MergeTypeFilter } from './types';
import {
ExpandAbstractTypes,
AddReplacementFragments,
delegateToSchema,
IDelegateToSchemaOptions,
} from '@graphql-tools/schema-wrapping';
import { MergeTypeCandidate, MergedTypeInfo, MergeInfo, IResolversParameter, MergeTypeFilter } from './types';

export function createMergeInfo(
allSchemas: Array<GraphQLSchema>,
Expand Down
1 change: 0 additions & 1 deletion packages/schema-stitching/src/stitch/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from 'graphql';

import { isSubschemaConfig, SubschemaConfig } from '@graphql-tools/utils';
import { wrapSchema } from '../wrap/wrapSchema';
import { wrapSchema } from '../../schema-wrapping/src/wrap/wrapSchema';

import {
extractTypeDefinitions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQLNamedType, GraphQLSchema } from 'graphql';
import { GraphQLNamedType, GraphQLSchema, SelectionSetNode } from 'graphql';
import {
SubschemaConfig,
ReplacementSelectionSetMapping,
Expand All @@ -7,9 +7,10 @@ import {
ITypeDefinitions,
SchemaLikeObject,
Transform,
TypeMap,
} from '@graphql-tools/utils';
import { GraphQLResolveInfo } from 'graphql/type';
import { IDelegateToSchemaOptions, MergedTypeInfo } from '../delegate/types';
import { IDelegateToSchemaOptions } from '@graphql-tools/schema-wrapping';
import { IExecutableSchemaDefinition } from '@graphql-tools/schema-generator';

export type MergeTypeCandidate = {
Expand All @@ -27,6 +28,16 @@ declare module 'graphql' {
}
}

export interface MergedTypeInfo {
subschemas: Array<SubschemaConfig>;
selectionSet?: SelectionSetNode;
uniqueFields: Record<string, SubschemaConfig>;
nonUniqueFields: Record<string, Array<SubschemaConfig>>;
typeMaps: Map<SubschemaConfig, TypeMap>;
selectionSets: Map<SubschemaConfig, SelectionSetNode>;
containsSelectionSet: Map<SubschemaConfig, Map<SelectionSetNode, boolean>>;
}

export interface MergeInfo {
delegate: (
type: 'query' | 'mutation' | 'subscription',
Expand Down
19 changes: 0 additions & 19 deletions packages/schema-stitching/src/wrap/transformSchema.ts

This file was deleted.

34 changes: 17 additions & 17 deletions packages/schema-stitching/tests/alternateStitchSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from 'graphql';

import {
transformSchema,
wrapSchema,
RenameTypes,
RenameRootFields,
Expand All @@ -32,18 +31,19 @@ import {
FilterObjectFields,
RenameInterfaceFields,
TransformRootFields,
} from '../src/wrap/index';
delegateToSchema,
createMergedResolver
} from '@graphql-tools/schema-wrapping';

import { delegateToSchema } from '../src/delegate/index';
import { makeExecutableSchema } from '@graphql-tools/schema-generator';
import { stitchSchemas } from '../src/stitch/index';
import { createMergedResolver } from '../src/delegate/createMergedResolver';
import {
wrapFieldNode,
renameFieldNode,
hoistFieldNodes, filterSchema, SubschemaConfig
} from '@graphql-tools/utils';

import { stitchSchemas } from '../src/stitchSchemas';

import { forAwaitEach } from './forAwaitEach';

import {
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('merge schemas through transforms', () => {

describe('transform object fields', () => {
test('should work to add a resolver', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new TransformObjectFields(
(
typeName: string,
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('transform object fields', () => {

describe('default values', () => {
test('should work to add a default value even when renaming root fields', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new TransformRootFields(
(
typeName: string,
Expand Down Expand Up @@ -594,7 +594,7 @@ describe('transform object fields', () => {
},
});

schema = transformSchema(itemSchema, [
schema = wrapSchema(itemSchema, [
new FilterObjectFields((_typeName, fieldName) => {
if (fieldName === 'id') {
return false;
Expand Down Expand Up @@ -692,7 +692,7 @@ describe('filter and rename object fields', () => {

beforeAll(() => {
transformedPropertySchema = filterSchema({
schema: transformSchema(propertySchema, [
schema: wrapSchema(propertySchema, [
new RenameTypes((name: string) => `New_${name}`),
new RenameObjectFields((typeName: string, fieldName: string) =>
typeName === 'New_Property' ? `new_${fieldName}` : fieldName,
Expand Down Expand Up @@ -848,7 +848,7 @@ describe('rename nested object fields with interfaces', () => {
},
});

const transformedSchema = transformSchema(originalSchema, [
const transformedSchema = wrapSchema(originalSchema, [
new RenameObjectFields((typeName, fieldName) => {
if (typeName === 'Query') {
return fieldName;
Expand Down Expand Up @@ -905,7 +905,7 @@ describe('rename nested object fields with interfaces', () => {

describe('WrapType transform', () => {
test('should work', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new WrapType('Query', 'Namespace_Query', 'namespace'),
]);
const result = await graphql(
Expand Down Expand Up @@ -960,7 +960,7 @@ describe('WrapType transform', () => {

describe('schema transformation with extraction of nested fields', () => {
test('should work via ExtendSchema transform', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new ExtendSchema({
typeDefs: `
extend type Property {
Expand Down Expand Up @@ -1030,7 +1030,7 @@ describe('schema transformation with extraction of nested fields', () => {
});

test('should work via HoistField transform', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new HoistField('Property', ['location', 'name'], 'locationName'),
]);

Expand Down Expand Up @@ -1062,7 +1062,7 @@ describe('schema transformation with extraction of nested fields', () => {

describe('schema transformation with wrapping of object fields', () => {
test('should work via ExtendSchema transform', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new ExtendSchema({
typeDefs: `
extend type Property {
Expand Down Expand Up @@ -1166,7 +1166,7 @@ describe('schema transformation with wrapping of object fields', () => {

describe('WrapFields transform', () => {
test('should work', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new WrapFields(
'Property',
['outerWrap'],
Expand Down Expand Up @@ -1235,7 +1235,7 @@ describe('schema transformation with wrapping of object fields', () => {
});

test('should work, even with multiple fields', async () => {
const transformedPropertySchema = transformSchema(propertySchema, [
const transformedPropertySchema = wrapSchema(propertySchema, [
new WrapFields(
'Property',
['outerWrap', 'innerWrap'],
Expand Down Expand Up @@ -1317,7 +1317,7 @@ describe('schema transformation with renaming of object fields', () => {
let transformedPropertySchema: GraphQLSchema;

beforeAll(() => {
transformedPropertySchema = transformSchema(propertySchema, [
transformedPropertySchema = wrapSchema(propertySchema, [
new ExtendSchema({
typeDefs: `
extend type Property {
Expand Down
5 changes: 3 additions & 2 deletions packages/schema-stitching/tests/dataloader.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import DataLoader from 'dataloader';
import { graphql, GraphQLList, GraphQLResolveInfo } from 'graphql';

import { delegateToSchema } from '../src/delegate/index';
import { delegateToSchema } from '@graphql-tools/schema-wrapping';
import { makeExecutableSchema } from '@graphql-tools/schema-generator';
import { stitchSchemas } from '../src/stitch/index';

import { stitchSchemas } from '../src/stitchSchemas';

describe('dataloader', () => {
test('should work', async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/schema-stitching/tests/delegateToSchema.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GraphQLSchema, graphql } from 'graphql';

import { delegateToSchema } from '../src/delegate/delegateToSchema';
import { stitchSchemas } from '../src/stitch/stitchSchemas';
import { IResolvers } from '@graphql-tools/utils';
import { delegateToSchema, wrapSchema } from '@graphql-tools/schema-wrapping';
import { makeExecutableSchema } from '@graphql-tools/schema-generator';
import { wrapSchema } from '../src/wrap';
import { IResolvers } from '@graphql-tools/utils';

import { stitchSchemas } from '../src/stitchSchemas';

import {
propertySchema,
Expand Down
Loading

0 comments on commit 47507fd

Please sign in to comment.