Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stitchSchemas): subschemas with object inputs and mergeTypes as true causes crash #1631

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/stitch/src/typeCandidates.ts
Expand Up @@ -16,9 +16,12 @@ import {
isInterfaceType,
isUnionType,
isEnumType,
isInputObjectType,
SchemaDefinitionNode,
SchemaExtensionNode,
GraphQLFieldConfigMap,
GraphQLInputObjectType,
GraphQLInputFieldConfigMap,
} from 'graphql';

import { wrapSchema } from '@graphql-tools/wrap';
Expand Down Expand Up @@ -277,6 +280,22 @@ function merge(typeName: string, candidates: Array<MergeTypeCandidate>): GraphQL
extensionASTNodes: initialCandidateType.extensionASTNodes,
};
return new GraphQLObjectType(config);
} else if (isInputObjectType(initialCandidateType)) {
const config = {
name: typeName,
fields: candidates.reduce<GraphQLInputFieldConfigMap>(
(acc, candidate) => ({
...acc,
...(candidate.type as GraphQLInputObjectType).toConfig().fields,
}),
{}
),
description: initialCandidateType.description,
extensions: initialCandidateType.extensions,
astNode: initialCandidateType.astNode,
extensionASTNodes: initialCandidateType.extensionASTNodes,
};
return new GraphQLInputObjectType(config);
} else if (isInterfaceType(initialCandidateType)) {
const config = {
name: typeName,
Expand Down
16 changes: 16 additions & 0 deletions packages/stitch/tests/alternateStitchSchemas.test.ts
Expand Up @@ -1853,6 +1853,10 @@ describe('mergeTypes', () => {

beforeEach(() => {
const typeDefs1 = `
input ObjectInput {
val: String!
}

type Query {
rootField1: Wrapper
getTest(id: ID): Test
Expand Down Expand Up @@ -1981,6 +1985,18 @@ describe('mergeTypes', () => {
},
},
});

const stitchedSchemaWithMerge = stitchSchemas({
subschemas: [subschemaConfig1, subschemaConfig2],
mergeTypes: true,
})

const result2 = await graphql(
stitchedSchemaWithMerge,
`{ rootField1 { test { id } } }`
);

expect(result2).toEqual({ data: { rootField1: { test: { id: '1' } } } })
});
});

Expand Down