Skip to content

Commit

Permalink
remove schemas property
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Sep 21, 2020
1 parent 402fc06 commit 39fd783
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 93 deletions.
2 changes: 1 addition & 1 deletion packages/links/tests/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('graphql upload', () => {
};

const gatewaySchema = stitchSchemas({
schemas: [subschema],
subschemas: [subschema],
resolvers: {
Upload: ServerGraphQLUpload,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/merge/tests/merge-typedefs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ describe('Merge TypeDefs', () => {
});
it('should handle extend types when GraphQLSchema is the source', () => {
const schema = stitchSchemas({
schemas: [
typeDefs: [
`
type Query {
foo: String
Expand Down Expand Up @@ -807,7 +807,7 @@ describe('Merge TypeDefs', () => {

it('should handle extend input types', () => {
const schema = stitchSchemas({
schemas: [
typeDefs: [
`
type Query {
foo(i: TestInput): String
Expand Down
37 changes: 0 additions & 37 deletions packages/stitch/src/stitchSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
GraphQLDirective,
specifiedDirectives,
extendSchema,
isSchema,
ASTNode,
GraphQLNamedType,
} from 'graphql';
Expand Down Expand Up @@ -34,8 +33,6 @@ export function stitchSchemas({
subschemas = [],
types = [],
typeDefs,
// `schemas` to be removed in v7, replaces by subschemas, types, typeDefs
schemas = [],
onTypeConflict,
mergeDirectives,
mergeTypes = false,
Expand Down Expand Up @@ -77,48 +74,14 @@ export function stitchSchemas({
}
});

// to be removed in v7
schemas.forEach(schemaLikeObject => {
if (
!isSchema(schemaLikeObject) &&
!isSubschemaConfig(schemaLikeObject) &&
typeof schemaLikeObject !== 'string' &&
!isDocumentNode(schemaLikeObject) &&
!Array.isArray(schemaLikeObject)
) {
throw new Error('Invalid schema passed');
}
});

// to be removed in v7
schemas.forEach(schemaLikeObject => {
if (isSchema(schemaLikeObject) || isSubschemaConfig(schemaLikeObject)) {
schemaLikeObjects.push(schemaLikeObject);
}
});

if ((typeDefs && !Array.isArray(typeDefs)) || (Array.isArray(typeDefs) && typeDefs.length)) {
schemaLikeObjects.push(buildDocumentFromTypeDefinitions(typeDefs, parseOptions));
}

// to be removed in v7
schemas.forEach(schemaLikeObject => {
if (typeof schemaLikeObject === 'string' || isDocumentNode(schemaLikeObject)) {
schemaLikeObjects.push(buildDocumentFromTypeDefinitions(schemaLikeObject, parseOptions));
}
});

if (types != null) {
schemaLikeObjects = schemaLikeObjects.concat(types);
}

// to be removed in v7
schemas.forEach(schemaLikeObject => {
if (Array.isArray(schemaLikeObject)) {
schemaLikeObjects = schemaLikeObjects.concat(schemaLikeObject);
}
});

const transformedSchemas: Map<GraphQLSchema | SubschemaConfig, GraphQLSchema> = new Map();
const extensions: Array<DocumentNode> = [];
const directives: Array<GraphQLDirective> = [];
Expand Down
1 change: 0 additions & 1 deletion packages/stitch/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export interface IStitchSchemasOptions<TContext = any> extends Omit<IExecutableS
subschemas?: Array<GraphQLSchema | SubschemaConfig | Array<SubschemaConfig>>;
typeDefs?: ITypeDefinitions;
types?: Array<GraphQLNamedType>;
schemas?: Array<SchemaLikeObject>;
onTypeConflict?: OnTypeConflict;
mergeDirectives?: boolean;
mergeTypes?: boolean | Array<string> | MergeTypeFilter;
Expand Down
48 changes: 23 additions & 25 deletions packages/stitch/tests/alternateStitchSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ describe('optional arguments', () => {
});

const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
});

it('work with schema stitching', async () => {
Expand Down Expand Up @@ -1494,12 +1494,12 @@ describe('interface resolver inheritance', () => {

test('copies resolvers from interface', async () => {
const stitchedSchema = stitchSchemas({
schemas: [
// pull in an executable schema just so mergeSchema doesn't complain
subschemas: [
// pull in an executable schema just so stitchSchemas doesn't complain
// about not finding default types (e.g. ID)
propertySchema,
testSchemaWithInterfaceResolvers,
],
typeDefs: testSchemaWithInterfaceResolvers,
resolvers,
inheritResolversFromInterfaces: true,
});
Expand All @@ -1517,12 +1517,12 @@ describe('interface resolver inheritance', () => {

test('does not copy resolvers from interface when flag is false', async () => {
const stitchedSchema = stitchSchemas({
schemas: [
subschemas: [
// pull in an executable schema just so mergeSchema doesn't complain
// about not finding default types (e.g. ID)
propertySchema,
testSchemaWithInterfaceResolvers,
],
typeDefs: testSchemaWithInterfaceResolvers,
resolvers,
inheritResolversFromInterfaces: false,
});
Expand All @@ -1537,12 +1537,12 @@ describe('interface resolver inheritance', () => {

test('does not copy resolvers from interface when flag is not provided', async () => {
const stitchedSchema = stitchSchemas({
schemas: [
// pull in an executable schema just so mergeSchema doesn't complain
subschemas: [
// pull in an executable schema just so stitchSchemas doesn't complain
// about not finding default types (e.g. ID)
propertySchema,
testSchemaWithInterfaceResolvers,
],
typeDefs: testSchemaWithInterfaceResolvers,
resolvers,
});
const query = '{ user { id name } }';
Expand Down Expand Up @@ -1573,7 +1573,7 @@ describe('stitchSchemas', () => {
},
});
const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
});

const query = '{ test { field } }';
Expand All @@ -1599,7 +1599,7 @@ describe('stitchSchemas', () => {
},
});
const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
});

const query = '{ getInput(input: {}) }';
Expand Down Expand Up @@ -1645,7 +1645,7 @@ type Query {
},
});
const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
resolvers: {
TestScalar: new GraphQLScalarType({
name: 'TestScalar',
Expand Down Expand Up @@ -1685,7 +1685,7 @@ type Query {
},
});
const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
resolvers: {
TestScalar: new GraphQLScalarType({
name: 'TestScalar',
Expand Down Expand Up @@ -1720,14 +1720,12 @@ type Query {
},
});
const stitchedSchema = stitchSchemas({
schemas: [
schema,
`
type Query {
get2: WrappingType
}
`,
],
subschemas: [schema],
typeDefs: `
type Query {
get2: WrappingType
}
`,
resolvers: {
Query: {
get2: (_root, _args, context, info) =>
Expand Down Expand Up @@ -1766,7 +1764,7 @@ type Query {
});

const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
resolvers: {
Query: {
wrappingObject: () => ({
Expand Down Expand Up @@ -1838,7 +1836,7 @@ describe('onTypeConflict', () => {

test('by default takes last type', async () => {
const stitchedSchema = stitchSchemas({
schemas: [schema1, schema2],
subschemas: [schema1, schema2],
});
const result1 = await graphql(stitchedSchema, '{ test2 { fieldC } }');
expect(result1.data?.test2.fieldC).toBe('C');
Expand All @@ -1848,7 +1846,7 @@ describe('onTypeConflict', () => {

test('can use onTypeConflict to select last type', async () => {
const stitchedSchema = stitchSchemas({
schemas: [schema1, schema2],
subschemas: [schema1, schema2],
onTypeConflict: (_left, right) => right,
});
const result1 = await graphql(stitchedSchema, '{ test2 { fieldC } }');
Expand All @@ -1859,7 +1857,7 @@ describe('onTypeConflict', () => {

test('can use onTypeConflict to select first type', async () => {
const stitchedSchema = stitchSchemas({
schemas: [schema1, schema2],
subschemas: [schema1, schema2],
onTypeConflict: (left) => left,
});
const result1 = await graphql(stitchedSchema, '{ test1 { fieldB } }');
Expand Down
2 changes: 1 addition & 1 deletion packages/stitch/tests/dataloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('dataloader', () => {
});

const schema = stitchSchemas({
schemas: [taskSchema, userSchema],
subschemas: [taskSchema, userSchema],
typeDefs: `
extend type Task {
user: User!
Expand Down
10 changes: 5 additions & 5 deletions packages/stitch/tests/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('passes along errors for missing fields on list', () => {
});

const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
});

const query = '{ getOuter { innerList { mandatoryField } } }';
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('passes along errors for missing fields on list', () => {
});

const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
});

const query = '{ getOuter { innerList { mandatoryField } } }';
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('passes along errors when list field errors', () => {
});

const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
});

const query = '{ getOuter { innerList { mandatoryField } } }';
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('passes along errors when list field errors', () => {
});

const stitchedSchema = stitchSchemas({
schemas: [schema],
subschemas: [schema],
});

const query = '{ getOuter { innerList { mandatoryField } } }';
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('passes along errors for remote schemas', () => {
}) as ExecutionResult<any>;

const stitchedSchema = stitchSchemas({
schemas: [{
subschemas: [{
schema,
executor,
}]
Expand Down
3 changes: 2 additions & 1 deletion packages/stitch/tests/fragments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ describe('stitching', () => {
let schema: GraphQLSchema;
beforeAll(() => {
schema = stitchSchemas({
schemas: [bookingSchema, propertySchema, proxyTypeDefs],
subschemas: [bookingSchema, propertySchema],
typeDefs: proxyTypeDefs,
resolvers: proxyResolvers,
});
});
Expand Down
Loading

0 comments on commit 39fd783

Please sign in to comment.