Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jun 2, 2022
1 parent 15c2c80 commit 4b8bbf2
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions packages/load/src/schema.ts
@@ -1,7 +1,7 @@
import { loadTypedefs, LoadTypedefsOptions, UnnormalizedTypeDefPointer, loadTypedefsSync } from './load-typedefs';
import { GraphQLSchema, BuildSchemaOptions, Source as GraphQLSource, print, lexicographicSortSchema } from 'graphql';
import { OPERATION_KINDS } from './documents';
import { makeExecutableSchema, IExecutableSchemaDefinition } from '@graphql-tools/schema';
import { IExecutableSchemaDefinition, mergeSchemas } from '@graphql-tools/schema';
import { getResolversFromSchema, IResolvers, Source, TypeSource } from '@graphql-tools/utils';
import { extractExtensionsFromSchema, SchemaExtensions } from '@graphql-tools/merge';

Expand Down Expand Up @@ -29,21 +29,7 @@ export async function loadSchema(
...options,
filterKinds: OPERATION_KINDS,
});

const { typeDefs, resolvers, schemaExtensions } = collectSchemaParts(sources);

const schema = makeExecutableSchema({
...options,
typeDefs,
resolvers,
schemaExtensions,
});

if (options?.includeSources) {
includeSources(schema, sources);
}

return options.sort ? lexicographicSortSchema(schema) : schema;
return getSchemaFromSources(sources, options);
}

/**
Expand All @@ -59,21 +45,7 @@ export function loadSchemaSync(
filterKinds: OPERATION_KINDS,
...options,
});

const { typeDefs, resolvers, schemaExtensions } = collectSchemaParts(sources);

const schema = makeExecutableSchema({
...options,
typeDefs,
resolvers,
schemaExtensions,
});

if (options?.includeSources) {
includeSources(schema, sources);
}

return options.sort ? lexicographicSortSchema(schema) : schema;
return getSchemaFromSources(sources, options);
}

function includeSources(schema: GraphQLSchema, sources: Source[]) {
Expand All @@ -92,6 +64,23 @@ function includeSources(schema: GraphQLSchema, sources: Source[]) {
};
}

function getSchemaFromSources(sources: Source[], options: LoadSchemaOptions) {
const { typeDefs, resolvers, schemaExtensions } = collectSchemaParts(sources);

const schema = mergeSchemas({
...options,
typeDefs,
resolvers,
schemaExtensions,
});

if (options?.includeSources) {
includeSources(schema, sources);
}

return options.sort ? lexicographicSortSchema(schema) : schema;
}

function collectSchemaParts(sources: Source[]) {
const typeDefs: TypeSource[] = [];
const resolvers: IResolvers[] = [];
Expand Down

0 comments on commit 4b8bbf2

Please sign in to comment.