From bc596176411225765a964522ec3bcb1fd96b3ae3 Mon Sep 17 00:00:00 2001 From: yaacovCR Date: Thu, 13 Feb 2020 16:34:20 -0500 Subject: [PATCH] chore(lint): pin eslint-plugin-import to 2.22.0 To avoid windows import/order error, see: https://github.com/benmosher/eslint-plugin-import/issues/1643 --- package.json | 2 +- src/Interfaces.ts | 7 ++-- src/generate/addResolversToSchema.ts | 23 +++++------ src/generate/assertResolversPresent.ts | 10 ++--- src/generate/attachConnectorsToContext.ts | 6 +-- src/generate/attachDirectiveResolvers.ts | 4 +- .../buildSchemaFromTypeDefinitions.ts | 12 +++--- src/generate/checkForResolveTypeResolver.ts | 4 +- src/generate/concatenateTypeDefs.ts | 4 +- src/generate/decorateWithLogger.ts | 4 +- src/generate/extendResolversFromInterfaces.ts | 4 +- src/makeExecutableSchema.ts | 13 +++--- src/mock.ts | 24 +++++------ src/stitching/checkResultAndHandleErrors.ts | 35 ++++++++-------- src/stitching/createRequest.ts | 18 ++++----- src/stitching/defaultMergedResolver.ts | 4 +- src/stitching/delegateToSchema.ts | 22 +++++----- src/stitching/introspectSchema.ts | 11 +++-- src/stitching/linkToFetcher.ts | 4 +- src/stitching/makeMergedType.ts | 6 +-- src/stitching/makeRemoteExecutableSchema.ts | 22 +++++----- src/stitching/mergeFields.ts | 12 +++--- src/stitching/mergeInfo.ts | 22 +++++----- src/stitching/mergeSchemas.ts | 36 ++++++++--------- src/stitching/proxiedResult.ts | 12 +++--- src/stitching/resolvers.ts | 12 +++--- src/stitching/typeFromAST.ts | 8 ++-- src/test/testAlternateMergeSchemas.ts | 31 +++++++------- src/test/testDataloader.ts | 8 ++-- src/test/testDelegateToSchema.ts | 12 +++--- src/test/testDirectives.ts | 14 +++---- src/test/testErrors.ts | 6 +-- src/test/testExtensionExtraction.ts | 4 +- src/test/testFragmentsAreNotDuplicated.ts | 1 + src/test/testLogger.ts | 6 +-- src/test/testMakeRemoteExecutableSchema.ts | 18 ++++----- src/test/testMergeSchemas.ts | 31 +++++++------- src/test/testMocking.ts | 6 +-- src/test/testResolution.ts | 3 +- src/test/testSchemaGenerator.ts | 40 +++++++++---------- src/test/testStitchingFromSubschemas.ts | 6 +-- src/test/testTransforms.ts | 23 ++++++----- src/test/testTypeMerging.ts | 6 +-- src/test/testUpload.ts | 10 ++--- src/test/testUtils.ts | 6 +-- src/test/testingSchemas.ts | 16 ++++---- src/transforms/AddArgumentsAsVariables.ts | 10 ++--- src/transforms/AddMergedTypeSelectionSets.ts | 8 ++-- src/transforms/AddReplacementFragments.ts | 8 ++-- src/transforms/AddReplacementSelectionSets.ts | 8 ++-- src/transforms/AddTypenameToAbstract.ts | 4 +- src/transforms/CheckResultAndHandleErrors.ts | 4 +- src/transforms/ExpandAbstractTypes.ts | 6 +-- src/transforms/ExtendSchema.ts | 13 +++--- src/transforms/ExtractField.ts | 4 +- src/transforms/FilterObjectFields.ts | 4 +- src/transforms/FilterRootFields.ts | 4 +- src/transforms/FilterToSchema.ts | 10 ++--- src/transforms/FilterTypes.ts | 4 +- src/transforms/HoistField.ts | 12 +++--- src/transforms/MapFields.ts | 8 ++-- src/transforms/RenameObjectFields.ts | 4 +- src/transforms/RenameRootFields.ts | 4 +- src/transforms/RenameTypes.ts | 10 ++--- src/transforms/ReplaceFieldWithFragment.ts | 10 ++--- src/transforms/TransformObjectFields.ts | 12 +++--- src/transforms/TransformQuery.ts | 8 ++-- src/transforms/TransformRootFields.ts | 10 ++--- src/transforms/WrapFields.ts | 10 ++--- src/transforms/WrapQuery.ts | 4 +- src/transforms/WrapType.ts | 4 +- src/transforms/filterSchema.ts | 8 ++-- src/transforms/transformSchema.ts | 5 +-- src/transforms/transforms.ts | 4 +- src/utils/SchemaDirectiveVisitor.ts | 16 ++++---- src/utils/clone.ts | 6 +-- src/utils/forEachDefaultValue.ts | 4 +- src/utils/forEachField.ts | 4 +- src/utils/getResolversFromSchema.ts | 10 ++--- src/utils/heal.ts | 10 ++--- src/utils/visitSchema.ts | 26 ++++++------ 81 files changed, 430 insertions(+), 434 deletions(-) diff --git a/package.json b/package.json index 27383aa74d0..e70e59ea61e 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "dataloader": "^2.0.0", "dateformat": "^3.0.3", "eslint": "^6.8.0", - "eslint-plugin-import": "^2.20.1", + "eslint-plugin-import": "2.20.0", "eslint-watch": "^6.0.1", "express": "^4.17.1", "express-graphql": "^0.9.0", diff --git a/src/Interfaces.ts b/src/Interfaces.ts index 5c2416b52d9..c049d65e057 100644 --- a/src/Interfaces.ts +++ b/src/Interfaces.ts @@ -1,6 +1,3 @@ -import { SchemaDirectiveVisitor } from './utils/SchemaDirectiveVisitor'; -import { SchemaVisitor } from './utils/SchemaVisitor'; - import { GraphQLSchema, GraphQLField, @@ -29,9 +26,11 @@ import { } from 'graphql'; import { TypeMap } from 'graphql/type/schema'; - import { ApolloLink } from 'apollo-link'; +import { SchemaVisitor } from './utils/SchemaVisitor'; +import { SchemaDirectiveVisitor } from './utils/SchemaDirectiveVisitor'; + /* TODO: Add documentation */ export type UnitOrList = Type | Array; diff --git a/src/generate/addResolversToSchema.ts b/src/generate/addResolversToSchema.ts index 1dc4edbd2b6..2292dc6be50 100644 --- a/src/generate/addResolversToSchema.ts +++ b/src/generate/addResolversToSchema.ts @@ -1,9 +1,19 @@ +import { + GraphQLField, + GraphQLEnumType, + GraphQLScalarType, + GraphQLSchema, + GraphQLObjectType, + GraphQLInterfaceType, + isSpecifiedScalarType, + GraphQLUnionType, +} from 'graphql'; + import { IResolvers, IResolverValidationOptions, IAddResolversToSchemaOptions, } from '../Interfaces'; - import { parseInputValue, serializeInputValue, @@ -16,17 +26,6 @@ import SchemaError from './SchemaError'; import checkForResolveTypeResolver from './checkForResolveTypeResolver'; import extendResolversFromInterfaces from './extendResolversFromInterfaces'; -import { - GraphQLField, - GraphQLEnumType, - GraphQLScalarType, - GraphQLSchema, - GraphQLObjectType, - GraphQLInterfaceType, - isSpecifiedScalarType, - GraphQLUnionType, -} from 'graphql'; - function addResolversToSchema( schemaOrOptions: GraphQLSchema | IAddResolversToSchemaOptions, legacyInputResolvers?: IResolvers, diff --git a/src/generate/assertResolversPresent.ts b/src/generate/assertResolversPresent.ts index 4dc860225be..06173157188 100644 --- a/src/generate/assertResolversPresent.ts +++ b/src/generate/assertResolversPresent.ts @@ -1,8 +1,3 @@ -import { IResolverValidationOptions } from '../Interfaces'; -import { forEachField } from '../utils'; - -import SchemaError from './SchemaError'; - import { GraphQLSchema, GraphQLField, @@ -10,6 +5,11 @@ import { GraphQLScalarType, } from 'graphql'; +import { IResolverValidationOptions } from '../Interfaces'; +import { forEachField } from '../utils'; + +import SchemaError from './SchemaError'; + function assertResolversPresent( schema: GraphQLSchema, resolverValidationOptions: IResolverValidationOptions = {}, diff --git a/src/generate/attachConnectorsToContext.ts b/src/generate/attachConnectorsToContext.ts index 589b06d92d8..dd0cb6c21fd 100644 --- a/src/generate/attachConnectorsToContext.ts +++ b/src/generate/attachConnectorsToContext.ts @@ -1,10 +1,10 @@ +import { deprecated } from 'deprecated-decorator'; +import { GraphQLSchema, GraphQLFieldResolver } from 'graphql'; + import { IConnectors, IConnector, IConnectorCls } from '../Interfaces'; import addSchemaLevelResolver from './addSchemaLevelResolver'; -import { deprecated } from 'deprecated-decorator'; -import { GraphQLSchema, GraphQLFieldResolver } from 'graphql'; - // takes a GraphQL-JS schema and an object of connectors, then attaches // the connectors to the context by wrapping each query or mutation resolve // function with a function that attaches connectors if they don't exist. diff --git a/src/generate/attachDirectiveResolvers.ts b/src/generate/attachDirectiveResolvers.ts index ef2e7236ff6..a6d01cb39e4 100644 --- a/src/generate/attachDirectiveResolvers.ts +++ b/src/generate/attachDirectiveResolvers.ts @@ -1,8 +1,8 @@ +import { GraphQLSchema, GraphQLField, defaultFieldResolver } from 'graphql'; + import { IDirectiveResolvers } from '../Interfaces'; import { SchemaDirectiveVisitor } from '../utils/SchemaDirectiveVisitor'; -import { GraphQLSchema, GraphQLField, defaultFieldResolver } from 'graphql'; - function attachDirectiveResolvers( schema: GraphQLSchema, directiveResolvers: IDirectiveResolvers, diff --git a/src/generate/buildSchemaFromTypeDefinitions.ts b/src/generate/buildSchemaFromTypeDefinitions.ts index c9fafe1fe50..10deb9ea45a 100644 --- a/src/generate/buildSchemaFromTypeDefinitions.ts +++ b/src/generate/buildSchemaFromTypeDefinitions.ts @@ -1,9 +1,3 @@ -import { ITypeDefinitions, GraphQLParseOptions } from '../Interfaces'; - -import extractExtensionDefinitions from './extractExtensionDefinitions'; -import concatenateTypeDefs from './concatenateTypeDefs'; -import SchemaError from './SchemaError'; - import { parse, extendSchema, @@ -13,6 +7,12 @@ import { ASTNode, } from 'graphql'; +import { ITypeDefinitions, GraphQLParseOptions } from '../Interfaces'; + +import extractExtensionDefinitions from './extractExtensionDefinitions'; +import concatenateTypeDefs from './concatenateTypeDefs'; +import SchemaError from './SchemaError'; + function buildSchemaFromTypeDefinitions( typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions, diff --git a/src/generate/checkForResolveTypeResolver.ts b/src/generate/checkForResolveTypeResolver.ts index 9e85b86cd67..75bf947291e 100644 --- a/src/generate/checkForResolveTypeResolver.ts +++ b/src/generate/checkForResolveTypeResolver.ts @@ -1,7 +1,7 @@ -import SchemaError from './SchemaError'; - import { GraphQLInterfaceType, GraphQLUnionType, GraphQLSchema } from 'graphql'; +import SchemaError from './SchemaError'; + // If we have any union or interface types throw if no there is no resolveType or isTypeOf resolvers function checkForResolveTypeResolver( schema: GraphQLSchema, diff --git a/src/generate/concatenateTypeDefs.ts b/src/generate/concatenateTypeDefs.ts index 91abe980fd1..61face52f7a 100644 --- a/src/generate/concatenateTypeDefs.ts +++ b/src/generate/concatenateTypeDefs.ts @@ -1,9 +1,9 @@ +import { print, ASTNode } from 'graphql'; + import { ITypedef } from '../Interfaces'; import SchemaError from './SchemaError'; -import { print, ASTNode } from 'graphql'; - function concatenateTypeDefs( typeDefinitionsAry: Array, calledFunctionRefs = [] as any, diff --git a/src/generate/decorateWithLogger.ts b/src/generate/decorateWithLogger.ts index 6809333c456..9e08aeaa291 100644 --- a/src/generate/decorateWithLogger.ts +++ b/src/generate/decorateWithLogger.ts @@ -1,7 +1,7 @@ -import { ILogger } from '../Interfaces'; - import { defaultFieldResolver, GraphQLFieldResolver } from 'graphql'; +import { ILogger } from '../Interfaces'; + /* * fn: The function to decorate with the logger * logger: an object instance of type Logger diff --git a/src/generate/extendResolversFromInterfaces.ts b/src/generate/extendResolversFromInterfaces.ts index c6947d38968..5783c7b72e4 100644 --- a/src/generate/extendResolversFromInterfaces.ts +++ b/src/generate/extendResolversFromInterfaces.ts @@ -1,7 +1,7 @@ -import { IResolvers } from '../Interfaces'; - import { GraphQLObjectType, GraphQLSchema } from 'graphql'; +import { IResolvers } from '../Interfaces'; + function extendResolversFromInterfaces( schema: GraphQLSchema, resolvers: IResolvers, diff --git a/src/makeExecutableSchema.ts b/src/makeExecutableSchema.ts index 6c23352d4f9..f73d6d0419c 100644 --- a/src/makeExecutableSchema.ts +++ b/src/makeExecutableSchema.ts @@ -1,11 +1,15 @@ -import { IExecutableSchemaDefinition, ILogger } from './Interfaces'; +import { + defaultFieldResolver, + GraphQLSchema, + GraphQLFieldResolver, +} from 'graphql'; +import { IExecutableSchemaDefinition, ILogger } from './Interfaces'; import { SchemaDirectiveVisitor, forEachField, mergeDeep } from './utils'; - import { attachDirectiveResolvers, assertResolversPresent, @@ -17,11 +21,6 @@ import { SchemaError } from './generate'; -import { - defaultFieldResolver, - GraphQLSchema, - GraphQLFieldResolver, -} from 'graphql'; export function makeExecutableSchema({ typeDefs, diff --git a/src/mock.ts b/src/mock.ts index e7b524ddb2c..432f0b797f5 100644 --- a/src/mock.ts +++ b/src/mock.ts @@ -1,15 +1,3 @@ -import { buildSchemaFromTypeDefinitions } from './makeExecutableSchema'; -import { forEachField } from './utils'; - -import { - IMocks, - IMockServer, - IMockOptions, - IMockFn, - IMockTypeFn, - ITypeDefinitions, -} from './Interfaces'; - import { graphql, GraphQLSchema, @@ -29,6 +17,18 @@ import { } from 'graphql'; import { v4 as uuid } from 'uuid'; +import { buildSchemaFromTypeDefinitions } from './makeExecutableSchema'; +import { forEachField } from './utils'; + +import { + IMocks, + IMockServer, + IMockOptions, + IMockFn, + IMockTypeFn, + ITypeDefinitions, +} from './Interfaces'; + // This function wraps addMocksToSchema for more convenience function mockServer( schema: GraphQLSchema | ITypeDefinitions, diff --git a/src/stitching/checkResultAndHandleErrors.ts b/src/stitching/checkResultAndHandleErrors.ts index 3458821f73d..3100851e7ae 100644 --- a/src/stitching/checkResultAndHandleErrors.ts +++ b/src/stitching/checkResultAndHandleErrors.ts @@ -1,20 +1,3 @@ -import { - SubschemaConfig, - IGraphQLToolsResolveInfo, - isSubschemaConfig, - MergedTypeInfo, -} from '../Interfaces'; - -import { - relocatedError, - combineErrors, - getErrorsByPathSegment, -} from './errors'; -import { getResponseKeyFromInfo } from './getResponseKeyFromInfo'; -import resolveFromParentTypename from './resolveFromParentTypename'; -import { setErrors, setObjectSubschema } from './proxiedResult'; -import { mergeFields } from './mergeFields'; - import { GraphQLResolveInfo, responsePathAsArray, @@ -35,6 +18,24 @@ import { } from 'graphql'; import { collectFields, ExecutionContext } from 'graphql/execution/execute'; +import { + SubschemaConfig, + IGraphQLToolsResolveInfo, + isSubschemaConfig, + MergedTypeInfo, +} from '../Interfaces'; + +import { + relocatedError, + combineErrors, + getErrorsByPathSegment, +} from './errors'; +import { getResponseKeyFromInfo } from './getResponseKeyFromInfo'; +import resolveFromParentTypename from './resolveFromParentTypename'; +import { setErrors, setObjectSubschema } from './proxiedResult'; +import { mergeFields } from './mergeFields'; + + export function checkResultAndHandleErrors( result: ExecutionResult, context: Record, diff --git a/src/stitching/createRequest.ts b/src/stitching/createRequest.ts index 27aa1ae55db..22178b97f38 100644 --- a/src/stitching/createRequest.ts +++ b/src/stitching/createRequest.ts @@ -1,12 +1,3 @@ -import { - ICreateRequestFromInfo, - Operation, - Request, - SubschemaConfig, - isSubschemaConfig, -} from '../Interfaces'; -import { serializeInputValue } from '../utils'; - import { ArgumentNode, FieldNode, @@ -30,6 +21,15 @@ import { SelectionSetNode, } from 'graphql'; +import { + ICreateRequestFromInfo, + Operation, + Request, + SubschemaConfig, + isSubschemaConfig, +} from '../Interfaces'; +import { serializeInputValue } from '../utils'; + export function getDelegatingOperation( parentType: GraphQLObjectType, schema: GraphQLSchema diff --git a/src/stitching/defaultMergedResolver.ts b/src/stitching/defaultMergedResolver.ts index b58bd6e3829..3c45099be3c 100644 --- a/src/stitching/defaultMergedResolver.ts +++ b/src/stitching/defaultMergedResolver.ts @@ -1,11 +1,11 @@ +import { defaultFieldResolver } from 'graphql'; + import { IGraphQLToolsResolveInfo } from '../Interfaces'; import { getErrors, getSubschema } from './proxiedResult'; import { handleResult } from './checkResultAndHandleErrors'; import { getResponseKeyFromInfo } from './getResponseKeyFromInfo'; -import { defaultFieldResolver } from 'graphql'; - // Resolver that knows how to: // a) handle aliases for proxied schemas // b) handle errors from proxied schemas diff --git a/src/stitching/delegateToSchema.ts b/src/stitching/delegateToSchema.ts index d32a2a44158..b86128e5526 100644 --- a/src/stitching/delegateToSchema.ts +++ b/src/stitching/delegateToSchema.ts @@ -1,3 +1,14 @@ +import { isAsyncIterable } from 'iterall'; +import { ApolloLink, execute as executeLink } from 'apollo-link'; +import { + subscribe, + execute, + validate, + GraphQLSchema, + ExecutionResult, + GraphQLOutputType, +} from 'graphql'; + import { IDelegateToSchemaOptions, IDelegateRequestOptions, @@ -29,17 +40,6 @@ import { observableToAsyncIterable } from './observableToAsyncIterable'; import mapAsyncIterator from './mapAsyncIterator'; import { combineErrors } from './errors'; -import { isAsyncIterable } from 'iterall'; -import { ApolloLink, execute as executeLink } from 'apollo-link'; -import { - subscribe, - execute, - validate, - GraphQLSchema, - ExecutionResult, - GraphQLOutputType, -} from 'graphql'; - export default function delegateToSchema( options: IDelegateToSchemaOptions | GraphQLSchema, ): any { diff --git a/src/stitching/introspectSchema.ts b/src/stitching/introspectSchema.ts index cb0f50155f7..bc2f43a9cbc 100644 --- a/src/stitching/introspectSchema.ts +++ b/src/stitching/introspectSchema.ts @@ -1,10 +1,4 @@ -import { Fetcher } from '../Interfaces'; - -import { combineErrors } from './errors'; -import linkToFetcher from './linkToFetcher'; - import { ApolloLink } from 'apollo-link'; - import { GraphQLSchema, DocumentNode, @@ -13,6 +7,11 @@ import { parse, } from 'graphql'; +import { Fetcher } from '../Interfaces'; + +import { combineErrors } from './errors'; +import linkToFetcher from './linkToFetcher'; + const parsedIntrospectionQuery: DocumentNode = parse(introspectionQuery); export default function introspectSchema( diff --git a/src/stitching/linkToFetcher.ts b/src/stitching/linkToFetcher.ts index 4d253f9fc8c..9c4082dac42 100644 --- a/src/stitching/linkToFetcher.ts +++ b/src/stitching/linkToFetcher.ts @@ -1,5 +1,3 @@ -import { Fetcher, IFetcherOperation } from '../Interfaces'; - import { ApolloLink, toPromise, @@ -7,6 +5,8 @@ import { ExecutionResult, } from 'apollo-link'; +import { Fetcher, IFetcherOperation } from '../Interfaces'; + export { execute } from 'apollo-link'; export default function linkToFetcher(link: ApolloLink): Fetcher { diff --git a/src/stitching/makeMergedType.ts b/src/stitching/makeMergedType.ts index 769fefc10c8..003a9c14c58 100644 --- a/src/stitching/makeMergedType.ts +++ b/src/stitching/makeMergedType.ts @@ -1,6 +1,3 @@ -import defaultMergedResolver from './defaultMergedResolver'; -import resolveFromParentTypename from './resolveFromParentTypename'; - import { GraphQLType, GraphQLObjectType, @@ -8,6 +5,9 @@ import { GraphQLUnionType, } from 'graphql'; +import defaultMergedResolver from './defaultMergedResolver'; +import resolveFromParentTypename from './resolveFromParentTypename'; + export function makeMergedType(type: GraphQLType): void { if (type instanceof GraphQLObjectType) { type.isTypeOf = undefined; diff --git a/src/stitching/makeRemoteExecutableSchema.ts b/src/stitching/makeRemoteExecutableSchema.ts index 9c3edbc5f0f..10ecbe7ad20 100644 --- a/src/stitching/makeRemoteExecutableSchema.ts +++ b/src/stitching/makeRemoteExecutableSchema.ts @@ -1,14 +1,3 @@ -import { addResolversToSchema } from '../generate'; -import { Fetcher, Operation } from '../Interfaces'; -import { cloneSchema } from '../utils'; - -import linkToFetcher, { execute } from './linkToFetcher'; -import { addTypenameToAbstract } from './addTypenameToAbstract'; -import { checkResultAndHandleErrors } from './checkResultAndHandleErrors'; -import { observableToAsyncIterable } from './observableToAsyncIterable'; -import mapAsyncIterator from './mapAsyncIterator'; -import { stripResolvers, generateProxyingResolvers } from './resolvers'; - import { ApolloLink } from 'apollo-link'; import { GraphQLFieldResolver, @@ -21,6 +10,17 @@ import { } from 'graphql'; import { Options as PrintSchemaOptions } from 'graphql/utilities/schemaPrinter'; +import { addResolversToSchema } from '../generate'; +import { Fetcher, Operation } from '../Interfaces'; +import { cloneSchema } from '../utils'; + +import linkToFetcher, { execute } from './linkToFetcher'; +import { addTypenameToAbstract } from './addTypenameToAbstract'; +import { checkResultAndHandleErrors } from './checkResultAndHandleErrors'; +import { observableToAsyncIterable } from './observableToAsyncIterable'; +import mapAsyncIterator from './mapAsyncIterator'; +import { stripResolvers, generateProxyingResolvers } from './resolvers'; + export type ResolverFn = ( rootValue?: any, args?: any, diff --git a/src/stitching/mergeFields.ts b/src/stitching/mergeFields.ts index 08f09039faa..374f23e6251 100644 --- a/src/stitching/mergeFields.ts +++ b/src/stitching/mergeFields.ts @@ -1,3 +1,9 @@ +import { + FieldNode, + SelectionNode, + Kind, +} from 'graphql'; + import { SubschemaConfig, IGraphQLToolsResolveInfo, @@ -6,12 +12,6 @@ import { import { mergeProxiedResults } from './proxiedResult'; -import { - FieldNode, - SelectionNode, - Kind, -} from 'graphql'; - function buildDelegationPlan( mergedTypeInfo: MergedTypeInfo, originalSelections: Array, diff --git a/src/stitching/mergeInfo.ts b/src/stitching/mergeInfo.ts index 215d6551eae..e071b3add86 100644 --- a/src/stitching/mergeInfo.ts +++ b/src/stitching/mergeInfo.ts @@ -1,3 +1,14 @@ +import { + GraphQLNamedType, + GraphQLObjectType, + GraphQLScalarType, + GraphQLSchema, + Kind, + SelectionNode, + SelectionSetNode, +} from 'graphql'; +import { TypeMap } from 'graphql/type/schema'; + import { IDelegateToSchemaOptions, MergeInfo, @@ -21,17 +32,6 @@ import { import delegateToSchema from './delegateToSchema'; -import { - GraphQLNamedType, - GraphQLObjectType, - GraphQLScalarType, - GraphQLSchema, - Kind, - SelectionNode, - SelectionSetNode, -} from 'graphql'; -import { TypeMap } from 'graphql/type/schema'; - type MergeTypeCandidate = { type: GraphQLNamedType; schema?: GraphQLSchema; diff --git a/src/stitching/mergeSchemas.ts b/src/stitching/mergeSchemas.ts index f2b004c4b75..830d846c6e5 100644 --- a/src/stitching/mergeSchemas.ts +++ b/src/stitching/mergeSchemas.ts @@ -1,3 +1,21 @@ +import { + DocumentNode, + GraphQLNamedType, + GraphQLObjectType, + GraphQLScalarType, + GraphQLSchema, + extendSchema, + getNamedType, + isNamedType, + parse, + Kind, + GraphQLDirective, + GraphQLInterfaceType, + GraphQLUnionType, + GraphQLEnumType, + ASTNode, +} from 'graphql'; + import { OnTypeConflict, IResolversParameter, @@ -23,24 +41,6 @@ import { import typeFromAST from './typeFromAST'; import { createMergeInfo, completeMergeInfo } from './mergeInfo'; -import { - DocumentNode, - GraphQLNamedType, - GraphQLObjectType, - GraphQLScalarType, - GraphQLSchema, - extendSchema, - getNamedType, - isNamedType, - parse, - Kind, - GraphQLDirective, - GraphQLInterfaceType, - GraphQLUnionType, - GraphQLEnumType, - ASTNode, -} from 'graphql'; - type MergeTypeCandidate = { type: GraphQLNamedType; schema?: GraphQLSchema; diff --git a/src/stitching/proxiedResult.ts b/src/stitching/proxiedResult.ts index b8267984dc5..5bdf82bb8e4 100644 --- a/src/stitching/proxiedResult.ts +++ b/src/stitching/proxiedResult.ts @@ -1,15 +1,15 @@ -import { SubschemaConfig, IGraphQLToolsResolveInfo } from '../Interfaces'; -import { mergeDeep } from '../utils'; - -import { handleNull } from './checkResultAndHandleErrors'; -import { relocatedError } from './errors'; - import { GraphQLError, GraphQLSchema, responsePathAsArray, } from 'graphql'; +import { SubschemaConfig, IGraphQLToolsResolveInfo } from '../Interfaces'; +import { mergeDeep } from '../utils'; + +import { handleNull } from './checkResultAndHandleErrors'; +import { relocatedError } from './errors'; + const hasSymbol = (typeof global !== 'undefined' && 'Symbol' in global) || // eslint-disable-next-line no-undef diff --git a/src/stitching/resolvers.ts b/src/stitching/resolvers.ts index 828ade698e5..511ad3f3541 100644 --- a/src/stitching/resolvers.ts +++ b/src/stitching/resolvers.ts @@ -1,3 +1,9 @@ +import { + GraphQLSchema, + GraphQLFieldResolver, + GraphQLObjectType, +} from 'graphql'; + import { IResolvers, Operation, @@ -8,12 +14,6 @@ import { Transform } from '../transforms'; import delegateToSchema from './delegateToSchema'; import { makeMergedType } from './makeMergedType'; -import { - GraphQLSchema, - GraphQLFieldResolver, - GraphQLObjectType, -} from 'graphql'; - export type Mapping = { [typeName: string]: { [fieldName: string]: { diff --git a/src/stitching/typeFromAST.ts b/src/stitching/typeFromAST.ts index 0c2314e53cb..d73ef220055 100644 --- a/src/stitching/typeFromAST.ts +++ b/src/stitching/typeFromAST.ts @@ -1,7 +1,3 @@ -import { createNamedStub } from '../utils/stub'; - -import resolveFromParentTypename from './resolveFromParentTypename'; - import { DefinitionNode, EnumTypeDefinitionNode, @@ -34,6 +30,10 @@ import { StringValueNode, } from 'graphql'; +import { createNamedStub } from '../utils/stub'; + +import resolveFromParentTypename from './resolveFromParentTypename'; + const backcompatOptions = { commentDescriptions: true }; export type GetType = ( diff --git a/src/test/testAlternateMergeSchemas.ts b/src/test/testAlternateMergeSchemas.ts index 04c41438ced..83171e4fd22 100644 --- a/src/test/testAlternateMergeSchemas.ts +++ b/src/test/testAlternateMergeSchemas.ts @@ -1,3 +1,19 @@ +import { + graphql, + GraphQLSchema, + ExecutionResult, + subscribe, + parse, + GraphQLScalarType, + FieldNode, + printSchema, + GraphQLObjectTypeConfig, + GraphQLFieldConfig, + GraphQLObjectType, +} from 'graphql'; +import { forAwaitEach } from 'iterall'; +import { expect } from 'chai'; + import { transformSchema, filterSchema, @@ -31,21 +47,6 @@ import { subscriptionPubSubTrigger, } from './testingSchemas'; -import { - graphql, - GraphQLSchema, - ExecutionResult, - subscribe, - parse, - GraphQLScalarType, - FieldNode, - printSchema, - GraphQLObjectTypeConfig, - GraphQLFieldConfig, - GraphQLObjectType, -} from 'graphql'; -import { forAwaitEach } from 'iterall'; -import { expect } from 'chai'; const linkSchema = ` """ diff --git a/src/test/testDataloader.ts b/src/test/testDataloader.ts index dcb8bc58a36..89bde4208bc 100644 --- a/src/test/testDataloader.ts +++ b/src/test/testDataloader.ts @@ -1,3 +1,7 @@ +import DataLoader from 'dataloader'; +import { graphql, GraphQLList } from 'graphql'; +import { expect } from 'chai'; + import { makeExecutableSchema } from '../makeExecutableSchema'; import { mergeSchemas, @@ -5,10 +9,6 @@ import { } from '../stitching'; import { IGraphQLToolsResolveInfo } from '../Interfaces'; -import DataLoader from 'dataloader'; -import { graphql, GraphQLList } from 'graphql'; -import { expect } from 'chai'; - describe('dataloader', () => { it('should work', async () => { const taskSchema = makeExecutableSchema({ diff --git a/src/test/testDelegateToSchema.ts b/src/test/testDelegateToSchema.ts index d3a0e0d6229..9114c8560be 100644 --- a/src/test/testDelegateToSchema.ts +++ b/src/test/testDelegateToSchema.ts @@ -1,15 +1,15 @@ -import delegateToSchema from '../stitching/delegateToSchema'; -import mergeSchemas from '../stitching/mergeSchemas'; -import { IResolvers } from '../Interfaces'; - -import { propertySchema, bookingSchema, sampleData, Property } from './testingSchemas'; - import { GraphQLSchema, graphql } from 'graphql'; import { expect } from 'chai'; +import delegateToSchema from '../stitching/delegateToSchema'; +import mergeSchemas from '../stitching/mergeSchemas'; +import { IResolvers } from '../Interfaces'; + +import { propertySchema, bookingSchema, sampleData, Property } from './testingSchemas'; + function findPropertyByLocationName ( properties: { [key: string]: Property }, name: string diff --git a/src/test/testDirectives.ts b/src/test/testDirectives.ts index 4009eda0b44..1127a547099 100644 --- a/src/test/testDirectives.ts +++ b/src/test/testDirectives.ts @@ -1,11 +1,5 @@ import crypto from 'crypto'; -import { makeExecutableSchema } from '../makeExecutableSchema'; -import { VisitableSchemaType } from '../Interfaces'; -import { SchemaDirectiveVisitor } from '../utils/SchemaDirectiveVisitor'; -import { SchemaVisitor } from '../utils/SchemaVisitor'; -import { visitSchema } from '../utils/visitSchema'; - import { ExecutionResult, GraphQLArgument, @@ -28,11 +22,15 @@ import { GraphQLInt, GraphQLOutputType, } from 'graphql'; - import { assert } from 'chai'; - import formatDate from 'dateformat'; +import { makeExecutableSchema } from '../makeExecutableSchema'; +import { VisitableSchemaType } from '../Interfaces'; +import { SchemaDirectiveVisitor } from '../utils/SchemaDirectiveVisitor'; +import { SchemaVisitor } from '../utils/SchemaVisitor'; +import { visitSchema } from '../utils/visitSchema'; + const typeDefs = ` directive @schemaDirective(role: String) on SCHEMA directive @queryTypeDirective on OBJECT diff --git a/src/test/testErrors.ts b/src/test/testErrors.ts index 8c95eb25c5e..367ff8037ed 100644 --- a/src/test/testErrors.ts +++ b/src/test/testErrors.ts @@ -1,3 +1,6 @@ +import { expect, assert } from 'chai'; +import { GraphQLError, graphql } from 'graphql'; + import { relocatedError } from '../stitching/errors'; import { getErrors, ERROR_SYMBOL } from '../stitching/proxiedResult'; import { checkResultAndHandleErrors } from '../stitching/checkResultAndHandleErrors'; @@ -5,9 +8,6 @@ import { makeExecutableSchema } from '../makeExecutableSchema'; import { mergeSchemas } from '../stitching'; import { IGraphQLToolsResolveInfo } from '../Interfaces'; -import { expect, assert } from 'chai'; -import { GraphQLError, graphql } from 'graphql'; - class ErrorWithExtensions extends GraphQLError { constructor(message: string, code: string) { super(message, null, null, null, null, null, { code }); diff --git a/src/test/testExtensionExtraction.ts b/src/test/testExtensionExtraction.ts index a7621874604..234205a5774 100644 --- a/src/test/testExtensionExtraction.ts +++ b/src/test/testExtensionExtraction.ts @@ -1,8 +1,8 @@ -import extractExtensionDefinitons from '../generate/extractExtensionDefinitions'; - import { expect } from 'chai'; import { parse } from 'graphql'; +import extractExtensionDefinitons from '../generate/extractExtensionDefinitions'; + describe('Extension extraction', () => { it('extracts extended inputs', () => { const typeDefs = ` diff --git a/src/test/testFragmentsAreNotDuplicated.ts b/src/test/testFragmentsAreNotDuplicated.ts index 409faccdd29..ab7d70c9ec0 100644 --- a/src/test/testFragmentsAreNotDuplicated.ts +++ b/src/test/testFragmentsAreNotDuplicated.ts @@ -1,5 +1,6 @@ import {expect} from 'chai'; import {ExecutionResult, graphql} from 'graphql'; + import { addMocksToSchema, makeExecutableSchema, diff --git a/src/test/testLogger.ts b/src/test/testLogger.ts index 5668b10136e..b6176fb4299 100644 --- a/src/test/testLogger.ts +++ b/src/test/testLogger.ts @@ -1,9 +1,9 @@ -import { Logger } from '../Logger'; -import { makeExecutableSchema } from '../makeExecutableSchema'; - import { assert } from 'chai'; import { graphql } from 'graphql'; +import { Logger } from '../Logger'; +import { makeExecutableSchema } from '../makeExecutableSchema'; + describe('Logger', () => { it('logs the errors', () => { const shorthand = ` diff --git a/src/test/testMakeRemoteExecutableSchema.ts b/src/test/testMakeRemoteExecutableSchema.ts index 8a63e866162..b47f742a92b 100644 --- a/src/test/testMakeRemoteExecutableSchema.ts +++ b/src/test/testMakeRemoteExecutableSchema.ts @@ -1,12 +1,3 @@ -import { - propertySchema, - subscriptionSchema, - subscriptionPubSubTrigger, - subscriptionPubSub, - makeSchemaRemoteFromLink -} from '../test/testingSchemas'; -import { makeRemoteExecutableSchema } from '../stitching'; - import { expect } from 'chai'; import { forAwaitEach } from 'iterall'; import { @@ -17,6 +8,15 @@ import { graphql, } from 'graphql'; +import { makeRemoteExecutableSchema } from '../stitching'; +import { + propertySchema, + subscriptionSchema, + subscriptionPubSubTrigger, + subscriptionPubSub, + makeSchemaRemoteFromLink +} from '../test/testingSchemas'; + describe('remote queries', () => { let schema: GraphQLSchema; before(async () => { diff --git a/src/test/testMergeSchemas.ts b/src/test/testMergeSchemas.ts index 39863e45440..dad277839bc 100644 --- a/src/test/testMergeSchemas.ts +++ b/src/test/testMergeSchemas.ts @@ -1,3 +1,19 @@ +import { forAwaitEach } from 'iterall'; +import { expect } from 'chai'; +import { + graphql, + GraphQLSchema, + GraphQLField, + GraphQLObjectType, + GraphQLScalarType, + subscribe, + parse, + ExecutionResult, + defaultFieldResolver, + findDeprecatedUsages, + printSchema, +} from 'graphql'; + import mergeSchemas from '../stitching/mergeSchemas'; import { SchemaDirectiveVisitor } from '../utils/SchemaDirectiveVisitor'; import { makeExecutableSchema } from '../makeExecutableSchema'; @@ -21,21 +37,6 @@ import { subscriptionPubSubTrigger, } from './testingSchemas'; -import { forAwaitEach } from 'iterall'; -import { expect } from 'chai'; -import { - graphql, - GraphQLSchema, - GraphQLField, - GraphQLObjectType, - GraphQLScalarType, - subscribe, - parse, - ExecutionResult, - defaultFieldResolver, - findDeprecatedUsages, - printSchema, -} from 'graphql'; // eslint-disable-next-line @typescript-eslint/no-unused-vars const removeLocations = ({ locations, ...rest }: any): any => ({ ...rest }); diff --git a/src/test/testMocking.ts b/src/test/testMocking.ts index 0d8afcd010b..4d25f611f36 100644 --- a/src/test/testMocking.ts +++ b/src/test/testMocking.ts @@ -1,3 +1,6 @@ +import { expect } from 'chai'; +import { graphql, GraphQLResolveInfo, GraphQLSchema, GraphQLFieldResolver } from 'graphql'; + import { addMocksToSchema, MockList, mockServer } from '../mock'; import { buildSchemaFromTypeDefinitions, @@ -6,9 +9,6 @@ import { } from '../makeExecutableSchema'; import { IMocks } from '../Interfaces'; -import { expect } from 'chai'; -import { graphql, GraphQLResolveInfo, GraphQLSchema, GraphQLFieldResolver } from 'graphql'; - describe('Mock', () => { const shorthand = ` scalar MissingMockType diff --git a/src/test/testResolution.ts b/src/test/testResolution.ts index 94ef49378e8..9ed712896e8 100644 --- a/src/test/testResolution.ts +++ b/src/test/testResolution.ts @@ -1,9 +1,10 @@ import { assert } from 'chai'; -import { makeExecutableSchema, addSchemaLevelResolver } from '..'; import { parse, graphql, subscribe, ExecutionResult } from 'graphql'; import { PubSub } from 'graphql-subscriptions'; import { forAwaitEach } from 'iterall'; +import { makeExecutableSchema, addSchemaLevelResolver } from '..'; + describe('Resolve', () => { describe('addSchemaLevelResolver', () => { const pubsub = new PubSub(); diff --git a/src/test/testSchemaGenerator.ts b/src/test/testSchemaGenerator.ts index 78ed7cef031..3ea69ec74c9 100644 --- a/src/test/testSchemaGenerator.ts +++ b/src/test/testSchemaGenerator.ts @@ -1,6 +1,26 @@ // TODO: reduce code repetition in this file. // see https://github.com/apollostack/graphql-tools/issues/26 +import { GraphQLJSON } from 'graphql-type-json'; +import { assert, expect } from 'chai'; +import { + graphql, + GraphQLResolveInfo, + GraphQLScalarType, + Kind, + IntValueNode, + parse, + ExecutionResult, + GraphQLError, + GraphQLEnumType, + execute, + VariableDefinitionNode, + DocumentNode, + GraphQLBoolean, + graphqlSync, + GraphQLSchema, +} from 'graphql'; + import { Logger } from '../Logger'; import { makeExecutableSchema, @@ -26,26 +46,6 @@ import { addResolversToSchema } from '../generate'; import TypeA from './circularSchemaA'; -import { GraphQLJSON } from 'graphql-type-json'; -import { assert, expect } from 'chai'; -import { - graphql, - GraphQLResolveInfo, - GraphQLScalarType, - Kind, - IntValueNode, - parse, - ExecutionResult, - GraphQLError, - GraphQLEnumType, - execute, - VariableDefinitionNode, - DocumentNode, - GraphQLBoolean, - graphqlSync, - GraphQLSchema, -} from 'graphql'; - interface Bird { name: string; wingspan?: number; diff --git a/src/test/testStitchingFromSubschemas.ts b/src/test/testStitchingFromSubschemas.ts index dba307cb9b6..7f49a29e208 100644 --- a/src/test/testStitchingFromSubschemas.ts +++ b/src/test/testStitchingFromSubschemas.ts @@ -11,15 +11,15 @@ // The fragment field is still necessary when working with a remote schema // where this is not possible. +import { expect } from 'chai'; +import { graphql } from 'graphql'; + import { delegateToSchema, mergeSchemas, addMocksToSchema, } from '../index'; -import { expect } from 'chai'; -import { graphql } from 'graphql'; - const chirpTypeDefs = ` type Chirp { id: ID! diff --git a/src/test/testTransforms.ts b/src/test/testTransforms.ts index 34f6501f4e2..6e38bdaa9b1 100644 --- a/src/test/testTransforms.ts +++ b/src/test/testTransforms.ts @@ -1,3 +1,15 @@ +import { expect } from 'chai'; +import { + GraphQLSchema, + GraphQLNamedType, + GraphQLScalarType, + graphql, + Kind, + SelectionSetNode, + print, + parse, +} from 'graphql'; + import { makeExecutableSchema } from '../makeExecutableSchema'; import { delegateToSchema, @@ -21,17 +33,6 @@ import { import { propertySchema, bookingSchema } from './testingSchemas'; -import { expect } from 'chai'; -import { - GraphQLSchema, - GraphQLNamedType, - GraphQLScalarType, - graphql, - Kind, - SelectionSetNode, - print, - parse, -} from 'graphql'; describe('transforms', () => { describe('base transform function', () => { diff --git a/src/test/testTypeMerging.ts b/src/test/testTypeMerging.ts index 39024b8feca..156eb6ec238 100644 --- a/src/test/testTypeMerging.ts +++ b/src/test/testTypeMerging.ts @@ -1,15 +1,15 @@ // The below is meant to be an alternative canonical schema stitching example // which relies on type merging. +import { expect } from 'chai'; +import { graphql } from 'graphql'; + import { mergeSchemas, addMocksToSchema, makeExecutableSchema, } from '../index'; -import { expect } from 'chai'; -import { graphql } from 'graphql'; - const chirpSchema = makeExecutableSchema({ typeDefs: ` type Chirp { diff --git a/src/test/testUpload.ts b/src/test/testUpload.ts index 8c5a38b5a51..e3046c801db 100644 --- a/src/test/testUpload.ts +++ b/src/test/testUpload.ts @@ -2,11 +2,6 @@ import { Server } from 'http'; import { AddressInfo } from 'net'; import { Readable } from 'stream'; -import { SubschemaConfig } from '../Interfaces'; -import { createServerHttpLink } from '../links'; -import { makeExecutableSchema } from '../makeExecutableSchema'; -import { mergeSchemas} from '../stitching'; - import { expect } from 'chai'; import express, { Express } from 'express'; import graphqlHTTP from 'express-graphql'; @@ -15,6 +10,11 @@ import FormData from 'form-data'; import fetch from 'node-fetch'; import { buildSchema } from 'graphql'; +import { mergeSchemas} from '../stitching'; +import { makeExecutableSchema } from '../makeExecutableSchema'; +import { createServerHttpLink } from '../links'; +import { SubschemaConfig } from '../Interfaces'; + function streamToString(stream: Readable) { const chunks: Array = []; return new Promise((resolve, reject) => { diff --git a/src/test/testUtils.ts b/src/test/testUtils.ts index 9f6dfc2165a..12107a6bede 100644 --- a/src/test/testUtils.ts +++ b/src/test/testUtils.ts @@ -1,9 +1,9 @@ -import { healSchema } from '../utils'; -import { makeExecutableSchema } from '../makeExecutableSchema'; - import { expect } from 'chai'; import { GraphQLObjectType, GraphQLObjectTypeConfig } from 'graphql'; +import { healSchema } from '../utils'; +import { makeExecutableSchema } from '../makeExecutableSchema'; + describe('heal', () => { it('should prune empty types', () => { const schema = makeExecutableSchema({ diff --git a/src/test/testingSchemas.ts b/src/test/testingSchemas.ts index 1d0f9ad9133..aee75b331ea 100644 --- a/src/test/testingSchemas.ts +++ b/src/test/testingSchemas.ts @@ -1,11 +1,3 @@ -import { makeExecutableSchema } from '../makeExecutableSchema'; -import { - IResolvers, - Fetcher, - SubschemaConfig, -} from '../Interfaces'; -import introspectSchema from '../stitching/introspectSchema'; - import { PubSub } from 'graphql-subscriptions'; import { ApolloLink, @@ -26,6 +18,14 @@ import { } from 'graphql'; import { forAwaitEach } from 'iterall'; +import introspectSchema from '../stitching/introspectSchema'; +import { + IResolvers, + Fetcher, + SubschemaConfig, +} from '../Interfaces'; +import { makeExecutableSchema } from '../makeExecutableSchema'; + export type Location = { name: string; coordinates: string; diff --git a/src/transforms/AddArgumentsAsVariables.ts b/src/transforms/AddArgumentsAsVariables.ts index a0d761fe0bd..6f7986075c3 100644 --- a/src/transforms/AddArgumentsAsVariables.ts +++ b/src/transforms/AddArgumentsAsVariables.ts @@ -1,8 +1,3 @@ -import { Request } from '../Interfaces'; -import { serializeInputValue } from '../utils'; - -import { Transform } from './transforms'; - import { ArgumentNode, DocumentNode, @@ -21,6 +16,11 @@ import { VariableDefinitionNode, } from 'graphql'; +import { Request } from '../Interfaces'; +import { serializeInputValue } from '../utils'; + +import { Transform } from './transforms'; + export default class AddArgumentsAsVariablesTransform implements Transform { private readonly targetSchema: GraphQLSchema; private readonly args: { [key: string]: any }; diff --git a/src/transforms/AddMergedTypeSelectionSets.ts b/src/transforms/AddMergedTypeSelectionSets.ts index 3ea058965d2..45b7c3f39e0 100644 --- a/src/transforms/AddMergedTypeSelectionSets.ts +++ b/src/transforms/AddMergedTypeSelectionSets.ts @@ -1,7 +1,3 @@ -import { Request, MergedTypeInfo } from '../Interfaces'; - -import { Transform } from './transforms'; - import { DocumentNode, GraphQLSchema, @@ -13,6 +9,10 @@ import { visitWithTypeInfo, } from 'graphql'; +import { Request, MergedTypeInfo } from '../Interfaces'; + +import { Transform } from './transforms'; + export default class AddMergedTypeFragments implements Transform { private readonly targetSchema: GraphQLSchema; private readonly mapping: Record; diff --git a/src/transforms/AddReplacementFragments.ts b/src/transforms/AddReplacementFragments.ts index 9b31ac0b9d3..251d3962943 100644 --- a/src/transforms/AddReplacementFragments.ts +++ b/src/transforms/AddReplacementFragments.ts @@ -1,7 +1,3 @@ -import { Request, ReplacementFragmentMapping } from '../Interfaces'; - -import { Transform } from './transforms'; - import { DocumentNode, GraphQLSchema, @@ -13,6 +9,10 @@ import { visitWithTypeInfo, } from 'graphql'; +import { Request, ReplacementFragmentMapping } from '../Interfaces'; + +import { Transform } from './transforms'; + export default class AddReplacementFragments implements Transform { private readonly targetSchema: GraphQLSchema; private readonly mapping: ReplacementFragmentMapping; diff --git a/src/transforms/AddReplacementSelectionSets.ts b/src/transforms/AddReplacementSelectionSets.ts index 5e8d25b6a0a..1b09837f8e5 100644 --- a/src/transforms/AddReplacementSelectionSets.ts +++ b/src/transforms/AddReplacementSelectionSets.ts @@ -1,7 +1,3 @@ -import { Request, ReplacementSelectionSetMapping } from '../Interfaces'; - -import { Transform } from './transforms'; - import { DocumentNode, GraphQLSchema, @@ -13,6 +9,10 @@ import { visitWithTypeInfo, } from 'graphql'; +import { Request, ReplacementSelectionSetMapping } from '../Interfaces'; + +import { Transform } from './transforms'; + export default class AddReplacementSelectionSets implements Transform { private readonly schema: GraphQLSchema; private readonly mapping: ReplacementSelectionSetMapping; diff --git a/src/transforms/AddTypenameToAbstract.ts b/src/transforms/AddTypenameToAbstract.ts index f700bdde441..d7f3c4a7f7d 100644 --- a/src/transforms/AddTypenameToAbstract.ts +++ b/src/transforms/AddTypenameToAbstract.ts @@ -1,10 +1,10 @@ +import { GraphQLSchema } from 'graphql'; + import { Request } from '../Interfaces'; import { addTypenameToAbstract } from '../stitching/addTypenameToAbstract'; import { Transform } from './transforms'; -import { GraphQLSchema } from 'graphql'; - export default class AddTypenameToAbstract implements Transform { private readonly targetSchema: GraphQLSchema; diff --git a/src/transforms/CheckResultAndHandleErrors.ts b/src/transforms/CheckResultAndHandleErrors.ts index a49c8325fa6..ab8aa0e34a9 100644 --- a/src/transforms/CheckResultAndHandleErrors.ts +++ b/src/transforms/CheckResultAndHandleErrors.ts @@ -1,10 +1,10 @@ +import { GraphQLSchema, GraphQLOutputType } from 'graphql'; + import { checkResultAndHandleErrors } from '../stitching/checkResultAndHandleErrors'; import { SubschemaConfig, IGraphQLToolsResolveInfo } from '../Interfaces'; import { Transform } from './transforms'; -import { GraphQLSchema, GraphQLOutputType } from 'graphql'; - export default class CheckResultAndHandleErrors implements Transform { private readonly context?: Record; private readonly info: IGraphQLToolsResolveInfo; diff --git a/src/transforms/ExpandAbstractTypes.ts b/src/transforms/ExpandAbstractTypes.ts index 37e2fd0645a..7761d51494f 100644 --- a/src/transforms/ExpandAbstractTypes.ts +++ b/src/transforms/ExpandAbstractTypes.ts @@ -1,6 +1,3 @@ -import implementsAbstractType from '../utils/implementsAbstractType'; -import { Transform, Request } from '../Interfaces'; - import { DocumentNode, FragmentDefinitionNode, @@ -17,6 +14,9 @@ import { visitWithTypeInfo, } from 'graphql'; +import implementsAbstractType from '../utils/implementsAbstractType'; +import { Transform, Request } from '../Interfaces'; + type TypeMapping = { [key: string]: Array }; export default class ExpandAbstractTypes implements Transform { diff --git a/src/transforms/ExtendSchema.ts b/src/transforms/ExtendSchema.ts index 623df9a0671..a6661c346f0 100644 --- a/src/transforms/ExtendSchema.ts +++ b/src/transforms/ExtendSchema.ts @@ -1,17 +1,16 @@ -import { IFieldResolver, IResolvers, Request } from '../Interfaces'; +import { + GraphQLSchema, + extendSchema, + parse, +} from 'graphql'; +import { IFieldResolver, IResolvers, Request } from '../Interfaces'; import { addResolversToSchema } from '../generate'; import { defaultMergedResolver } from '../stitching'; import { Transform } from './transforms'; import MapFields, { FieldNodeTransformerMap } from './MapFields'; -import { - GraphQLSchema, - extendSchema, - parse, -} from 'graphql'; - export default class ExtendSchema implements Transform { private readonly typeDefs: string | undefined; private readonly resolvers: IResolvers | undefined; diff --git a/src/transforms/ExtractField.ts b/src/transforms/ExtractField.ts index 15d13f817c6..7d8003f408f 100644 --- a/src/transforms/ExtractField.ts +++ b/src/transforms/ExtractField.ts @@ -1,5 +1,3 @@ -import { Transform, Request } from '../Interfaces'; - import { visit, Kind, @@ -8,6 +6,8 @@ import { FieldNode, } from 'graphql'; +import { Transform, Request } from '../Interfaces'; + export default class ExtractField implements Transform { private readonly from: Array; private readonly to: Array; diff --git a/src/transforms/FilterObjectFields.ts b/src/transforms/FilterObjectFields.ts index f47b66fcf8f..4577c01ac66 100644 --- a/src/transforms/FilterObjectFields.ts +++ b/src/transforms/FilterObjectFields.ts @@ -1,8 +1,8 @@ +import { GraphQLField, GraphQLSchema } from 'graphql'; + import { Transform } from './transforms'; import TransformObjectFields from './TransformObjectFields'; -import { GraphQLField, GraphQLSchema } from 'graphql'; - export type ObjectFilter = (typeName: string, fieldName: string, field: GraphQLField) => boolean; export default class FilterObjectFields implements Transform { diff --git a/src/transforms/FilterRootFields.ts b/src/transforms/FilterRootFields.ts index 4e316912ce5..196a6cbf68c 100644 --- a/src/transforms/FilterRootFields.ts +++ b/src/transforms/FilterRootFields.ts @@ -1,8 +1,8 @@ +import { GraphQLField, GraphQLSchema } from 'graphql'; + import { Transform } from './transforms'; import TransformRootFields from './TransformRootFields'; -import { GraphQLField, GraphQLSchema } from 'graphql'; - export type RootFilter = ( operation: 'Query' | 'Mutation' | 'Subscription', fieldName: string, diff --git a/src/transforms/FilterToSchema.ts b/src/transforms/FilterToSchema.ts index 2ae2ee615bf..b60f9d8982f 100644 --- a/src/transforms/FilterToSchema.ts +++ b/src/transforms/FilterToSchema.ts @@ -1,8 +1,3 @@ -import { Request } from '../Interfaces'; -import implementsAbstractType from '../utils/implementsAbstractType'; - -import { Transform } from './transforms'; - import { ArgumentNode, DocumentNode, @@ -26,6 +21,11 @@ import { getNamedType, } from 'graphql'; +import { Request } from '../Interfaces'; +import implementsAbstractType from '../utils/implementsAbstractType'; + +import { Transform } from './transforms'; + export default class FilterToSchema implements Transform { private readonly targetSchema: GraphQLSchema; diff --git a/src/transforms/FilterTypes.ts b/src/transforms/FilterTypes.ts index 6500f5d4bb4..3584c1fba63 100644 --- a/src/transforms/FilterTypes.ts +++ b/src/transforms/FilterTypes.ts @@ -1,9 +1,9 @@ +import { GraphQLSchema, GraphQLNamedType } from 'graphql'; + import { Transform } from '../transforms/transforms'; import { visitSchema } from '../utils/visitSchema'; import { VisitSchemaKind } from '../Interfaces'; -import { GraphQLSchema, GraphQLNamedType } from 'graphql'; - export default class FilterTypes implements Transform { private readonly filter: (type: GraphQLNamedType) => boolean; diff --git a/src/transforms/HoistField.ts b/src/transforms/HoistField.ts index 2f4ed8f4ba0..3c9dd77eae9 100644 --- a/src/transforms/HoistField.ts +++ b/src/transforms/HoistField.ts @@ -1,3 +1,9 @@ +import { + GraphQLSchema, + GraphQLObjectType, + getNullableType, +} from 'graphql'; + import { healSchema, wrapFieldNode, renameFieldNode } from '../utils'; import { createMergedResolver } from '../stitching'; import { appendFields, removeFields } from '../utils/fields'; @@ -6,12 +12,6 @@ import { Request } from '../Interfaces'; import { Transform } from './transforms'; import MapFields from './MapFields'; -import { - GraphQLSchema, - GraphQLObjectType, - getNullableType, -} from 'graphql'; - export default class HoistField implements Transform { private readonly typeName: string; private readonly path: Array; diff --git a/src/transforms/MapFields.ts b/src/transforms/MapFields.ts index 86be806cb0c..bee993374e2 100644 --- a/src/transforms/MapFields.ts +++ b/src/transforms/MapFields.ts @@ -1,7 +1,3 @@ -import { Request } from '../Interfaces'; - -import { Transform } from './transforms'; - import { GraphQLSchema, GraphQLType, @@ -15,6 +11,10 @@ import { FragmentDefinitionNode } from 'graphql'; +import { Request } from '../Interfaces'; + +import { Transform } from './transforms'; + export type FieldNodeTransformer = ( fieldNode: FieldNode, fragments: Record diff --git a/src/transforms/RenameObjectFields.ts b/src/transforms/RenameObjectFields.ts index 4e56b37a02a..e14b0769105 100644 --- a/src/transforms/RenameObjectFields.ts +++ b/src/transforms/RenameObjectFields.ts @@ -1,10 +1,10 @@ +import { GraphQLField, GraphQLSchema } from 'graphql'; + import { Request } from '../Interfaces'; import TransformObjectFields from './TransformObjectFields'; import { Transform } from './transforms'; -import { GraphQLField, GraphQLSchema } from 'graphql'; - export default class RenameObjectFields implements Transform { private readonly transformer: TransformObjectFields; diff --git a/src/transforms/RenameRootFields.ts b/src/transforms/RenameRootFields.ts index e8f934fc32a..8b993b78db8 100644 --- a/src/transforms/RenameRootFields.ts +++ b/src/transforms/RenameRootFields.ts @@ -1,10 +1,10 @@ +import { GraphQLField, GraphQLSchema } from 'graphql'; + import { Request } from '../Interfaces'; import { Transform } from './transforms'; import TransformRootFields from './TransformRootFields'; -import { GraphQLField, GraphQLSchema } from 'graphql'; - export default class RenameRootFields implements Transform { private readonly transformer: TransformRootFields; diff --git a/src/transforms/RenameTypes.ts b/src/transforms/RenameTypes.ts index 3dd542003b6..4caf9088935 100644 --- a/src/transforms/RenameTypes.ts +++ b/src/transforms/RenameTypes.ts @@ -1,8 +1,3 @@ -import isSpecifiedScalarType from '../utils/isSpecifiedScalarType'; -import { Request, Result, VisitSchemaKind } from '../Interfaces'; -import { Transform } from '../transforms/transforms'; -import { visitSchema, cloneType } from '../utils'; - import { visit, GraphQLSchema, @@ -12,6 +7,11 @@ import { GraphQLScalarType, } from 'graphql'; +import isSpecifiedScalarType from '../utils/isSpecifiedScalarType'; +import { Request, Result, VisitSchemaKind } from '../Interfaces'; +import { Transform } from '../transforms/transforms'; +import { visitSchema, cloneType } from '../utils'; + export type RenameOptions = { renameBuiltins: boolean; renameScalars: boolean; diff --git a/src/transforms/ReplaceFieldWithFragment.ts b/src/transforms/ReplaceFieldWithFragment.ts index c91f4ce05f7..7fbce45ddda 100644 --- a/src/transforms/ReplaceFieldWithFragment.ts +++ b/src/transforms/ReplaceFieldWithFragment.ts @@ -1,8 +1,3 @@ -import { concatInlineFragments } from '../utils'; -import { Request } from '../Interfaces'; - -import { Transform } from './transforms'; - import { DocumentNode, GraphQLSchema, @@ -17,6 +12,11 @@ import { visitWithTypeInfo, } from 'graphql'; +import { concatInlineFragments } from '../utils'; +import { Request } from '../Interfaces'; + +import { Transform } from './transforms'; + export default class ReplaceFieldWithFragment implements Transform { private readonly targetSchema: GraphQLSchema; private readonly mapping: FieldToFragmentMapping; diff --git a/src/transforms/TransformObjectFields.ts b/src/transforms/TransformObjectFields.ts index bbf98f55a38..aaab2f0368e 100644 --- a/src/transforms/TransformObjectFields.ts +++ b/src/transforms/TransformObjectFields.ts @@ -1,9 +1,3 @@ -import isEmptyObject from '../utils/isEmptyObject'; -import { Request, VisitSchemaKind } from '../Interfaces'; -import { visitSchema } from '../utils/visitSchema'; - -import { Transform } from './transforms'; - import { GraphQLObjectType, GraphQLSchema, @@ -21,6 +15,12 @@ import { FragmentDefinitionNode } from 'graphql'; +import isEmptyObject from '../utils/isEmptyObject'; +import { Request, VisitSchemaKind } from '../Interfaces'; +import { visitSchema } from '../utils/visitSchema'; + +import { Transform } from './transforms'; + export type ObjectFieldTransformer = ( typeName: string, fieldName: string, diff --git a/src/transforms/TransformQuery.ts b/src/transforms/TransformQuery.ts index 63e6161265b..f0c967a4a65 100644 --- a/src/transforms/TransformQuery.ts +++ b/src/transforms/TransformQuery.ts @@ -1,7 +1,3 @@ -import { Request, Result } from '../Interfaces'; - -import { Transform } from './transforms'; - import { visit, Kind, @@ -10,6 +6,10 @@ import { GraphQLError, } from 'graphql'; +import { Request, Result } from '../Interfaces'; + +import { Transform } from './transforms'; + export type QueryTransformer = ( selectionSet: SelectionSetNode, fragments: Record diff --git a/src/transforms/TransformRootFields.ts b/src/transforms/TransformRootFields.ts index a123c539407..94c3e2acac1 100644 --- a/src/transforms/TransformRootFields.ts +++ b/src/transforms/TransformRootFields.ts @@ -1,14 +1,14 @@ -import { Request } from '../Interfaces'; - -import { Transform } from './transforms'; -import TransformObjectFields, { FieldNodeTransformer } from './TransformObjectFields'; - import { GraphQLSchema, GraphQLField, GraphQLFieldConfig, } from 'graphql'; +import { Request } from '../Interfaces'; + +import { Transform } from './transforms'; +import TransformObjectFields, { FieldNodeTransformer } from './TransformObjectFields'; + export type RootTransformer = ( operation: 'Query' | 'Mutation' | 'Subscription', fieldName: string, diff --git a/src/transforms/WrapFields.ts b/src/transforms/WrapFields.ts index d6d26064279..d597795390b 100644 --- a/src/transforms/WrapFields.ts +++ b/src/transforms/WrapFields.ts @@ -1,3 +1,8 @@ +import { + GraphQLSchema, + GraphQLObjectType, +} from 'graphql'; + import { Request } from '../Interfaces'; import { appendFields, removeFields } from '../utils/fields'; import { hoistFieldNodes, healSchema } from '../utils'; @@ -6,11 +11,6 @@ import { defaultMergedResolver, createMergedResolver } from '../stitching'; import { Transform } from './transforms'; import MapFields from './MapFields'; -import { - GraphQLSchema, - GraphQLObjectType, -} from 'graphql'; - export default class WrapFields implements Transform { private readonly outerTypeName: string; private readonly wrappingFieldNames: Array; diff --git a/src/transforms/WrapQuery.ts b/src/transforms/WrapQuery.ts index bf78bcd6da6..b3dc3aa8abe 100644 --- a/src/transforms/WrapQuery.ts +++ b/src/transforms/WrapQuery.ts @@ -1,7 +1,7 @@ -import { Transform, Request, Result } from '../Interfaces'; - import { FieldNode, visit, Kind, SelectionNode, SelectionSetNode } from 'graphql'; +import { Transform, Request, Result } from '../Interfaces'; + export type QueryWrapper = (subtree: SelectionSetNode) => SelectionNode | SelectionSetNode; export default class WrapQuery implements Transform { diff --git a/src/transforms/WrapType.ts b/src/transforms/WrapType.ts index bb8e2e05266..ddff33b58a5 100644 --- a/src/transforms/WrapType.ts +++ b/src/transforms/WrapType.ts @@ -1,10 +1,10 @@ +import { GraphQLSchema } from 'graphql'; + import { Request } from '../Interfaces'; import { Transform } from './transforms'; import WrapFields from './WrapFields'; -import { GraphQLSchema } from 'graphql'; - export default class WrapType implements Transform { private readonly transformer: Transform; diff --git a/src/transforms/filterSchema.ts b/src/transforms/filterSchema.ts index eaa3950de46..37684ee4a02 100644 --- a/src/transforms/filterSchema.ts +++ b/src/transforms/filterSchema.ts @@ -1,7 +1,3 @@ -import { GraphQLSchemaWithTransforms, VisitSchemaKind } from '../Interfaces'; -import { visitSchema } from '../utils/visitSchema'; -import { cloneSchema } from '../utils/clone'; - import { GraphQLEnumType, GraphQLInputObjectType, @@ -12,6 +8,10 @@ import { GraphQLType, } from 'graphql'; +import { GraphQLSchemaWithTransforms, VisitSchemaKind } from '../Interfaces'; +import { visitSchema } from '../utils/visitSchema'; +import { cloneSchema } from '../utils/clone'; + export type RootFieldFilter = ( operation: 'Query' | 'Mutation' | 'Subscription', rootFieldName: string diff --git a/src/transforms/transformSchema.ts b/src/transforms/transformSchema.ts index c5c6b3263e3..ff9bd34e671 100644 --- a/src/transforms/transformSchema.ts +++ b/src/transforms/transformSchema.ts @@ -1,3 +1,5 @@ +import { GraphQLSchema } from 'graphql'; + import { addResolversToSchema } from '../makeExecutableSchema'; import { Transform, applySchemaTransforms } from '../transforms/transforms'; import { @@ -9,11 +11,8 @@ import { isSubschemaConfig, GraphQLSchemaWithTransforms, } from '../Interfaces'; - import { cloneSchema } from '../utils/clone'; -import { GraphQLSchema } from 'graphql'; - export function wrapSchema( subschemaOrSubschemaConfig: GraphQLSchema | SubschemaConfig, transforms?: Array, diff --git a/src/transforms/transforms.ts b/src/transforms/transforms.ts index 72e9930d478..44fc62b4c33 100644 --- a/src/transforms/transforms.ts +++ b/src/transforms/transforms.ts @@ -1,8 +1,8 @@ +import { GraphQLSchema } from 'graphql'; + import { Request, Transform } from '../Interfaces'; import { cloneSchema } from '../utils'; -import { GraphQLSchema } from 'graphql'; - export { Transform }; export function applySchemaTransforms( diff --git a/src/utils/SchemaDirectiveVisitor.ts b/src/utils/SchemaDirectiveVisitor.ts index c00de99b8a6..dcf3bf594f3 100644 --- a/src/utils/SchemaDirectiveVisitor.ts +++ b/src/utils/SchemaDirectiveVisitor.ts @@ -1,19 +1,17 @@ +import { + GraphQLDirective, + GraphQLSchema, + DirectiveLocationEnum, +} from 'graphql'; +import { getArgumentValues } from 'graphql/execution/values'; + import { VisitableSchemaType } from '../Interfaces'; import each from './each'; import valueFromASTUntyped from './valueFromASTUntyped'; - import { SchemaVisitor } from './SchemaVisitor'; import { visitSchema } from './visitSchema'; -import { getArgumentValues } from 'graphql/execution/values'; - -import { - GraphQLDirective, - GraphQLSchema, - DirectiveLocationEnum, -} from 'graphql'; - const hasOwn = Object.prototype.hasOwnProperty; // This class represents a reusable implementation of a @directive that may diff --git a/src/utils/clone.ts b/src/utils/clone.ts index a2520948bd0..662d27b3f3d 100644 --- a/src/utils/clone.ts +++ b/src/utils/clone.ts @@ -1,6 +1,3 @@ -import { healTypes } from './heal'; -import isSpecifiedScalarType from './isSpecifiedScalarType'; - import { GraphQLDirective, GraphQLEnumType, @@ -13,6 +10,9 @@ import { GraphQLUnionType, } from 'graphql'; +import { healTypes } from './heal'; +import isSpecifiedScalarType from './isSpecifiedScalarType'; + export function cloneDirective(directive: GraphQLDirective): GraphQLDirective { return new GraphQLDirective(directive.toConfig()); } diff --git a/src/utils/forEachDefaultValue.ts b/src/utils/forEachDefaultValue.ts index b54e452124a..8bda359a78d 100644 --- a/src/utils/forEachDefaultValue.ts +++ b/src/utils/forEachDefaultValue.ts @@ -1,5 +1,3 @@ -import { IDefaultValueIteratorFn } from '../Interfaces'; - import { getNamedType, GraphQLInputObjectType, @@ -7,6 +5,8 @@ import { GraphQLObjectType, } from 'graphql'; +import { IDefaultValueIteratorFn } from '../Interfaces'; + export function forEachDefaultValue(schema: GraphQLSchema, fn: IDefaultValueIteratorFn): void { const typeMap = schema.getTypeMap(); diff --git a/src/utils/forEachField.ts b/src/utils/forEachField.ts index 12f7f565d47..09a94f29ab5 100644 --- a/src/utils/forEachField.ts +++ b/src/utils/forEachField.ts @@ -1,11 +1,11 @@ -import { IFieldIteratorFn } from '../Interfaces'; - import { getNamedType, GraphQLObjectType, GraphQLSchema, } from 'graphql'; +import { IFieldIteratorFn } from '../Interfaces'; + export function forEachField(schema: GraphQLSchema, fn: IFieldIteratorFn): void { const typeMap = schema.getTypeMap(); Object.keys(typeMap).forEach(typeName => { diff --git a/src/utils/getResolversFromSchema.ts b/src/utils/getResolversFromSchema.ts index 7d505b62036..00ef7ed457c 100644 --- a/src/utils/getResolversFromSchema.ts +++ b/src/utils/getResolversFromSchema.ts @@ -1,8 +1,3 @@ -import { IResolvers } from '../Interfaces'; - -import isSpecifiedScalarType from './isSpecifiedScalarType'; -import { cloneType } from './clone'; - import { GraphQLSchema, GraphQLScalarType, @@ -12,6 +7,11 @@ import { GraphQLUnionType, } from 'graphql'; +import { IResolvers } from '../Interfaces'; + +import isSpecifiedScalarType from './isSpecifiedScalarType'; +import { cloneType } from './clone'; + export function getResolversFromSchema(schema: GraphQLSchema): IResolvers { const resolvers = Object.create({}); diff --git a/src/utils/heal.ts b/src/utils/heal.ts index 1090bb27bde..7ce80dc74ad 100644 --- a/src/utils/heal.ts +++ b/src/utils/heal.ts @@ -1,8 +1,3 @@ -import each from './each'; -import updateEachKey from './updateEachKey'; -import { isStub, getBuiltInForStub } from './stub'; -import { cloneSchema } from './clone'; - import { GraphQLDirective, GraphQLEnumType, @@ -21,6 +16,11 @@ import { GraphQLOutputType, } from 'graphql'; +import each from './each'; +import updateEachKey from './updateEachKey'; +import { isStub, getBuiltInForStub } from './stub'; +import { cloneSchema } from './clone'; + type NamedTypeMap = { [key: string]: GraphQLNamedType; }; diff --git a/src/utils/visitSchema.ts b/src/utils/visitSchema.ts index a569b011a10..b59fe6a4708 100644 --- a/src/utils/visitSchema.ts +++ b/src/utils/visitSchema.ts @@ -1,16 +1,3 @@ -import { - VisitableSchemaType, - VisitorSelector, - VisitSchemaKind, - NamedTypeVisitor, - SchemaVisitorMap, -} from '../Interfaces'; - -import updateEachKey from './updateEachKey'; -import { healSchema } from './heal'; -import { SchemaVisitor } from './SchemaVisitor'; -import each from './each'; - import { GraphQLEnumType, GraphQLInputObjectType, @@ -25,6 +12,19 @@ import { GraphQLInputField, } from 'graphql'; +import { + VisitableSchemaType, + VisitorSelector, + VisitSchemaKind, + NamedTypeVisitor, + SchemaVisitorMap, +} from '../Interfaces'; + +import updateEachKey from './updateEachKey'; +import { healSchema } from './heal'; +import { SchemaVisitor } from './SchemaVisitor'; +import each from './each'; + // Generic function for visiting GraphQLSchema objects. export function visitSchema( schema: GraphQLSchema,