Skip to content

extendSchema incorrectly throws "multiple types" error when input type used as a query argument. #1355

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/utilities/__tests__/extendSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { describe, it } from 'mocha';
import { expect } from 'chai';
import dedent from '../../jsutils/dedent';
import { extendSchema } from '../extendSchema';
import { buildASTSchema } from '../buildASTSchema';
import { parse, print } from '../../language';
import { printSchema } from '../schemaPrinter';
import { Kind } from '../../language/kinds';
import { graphqlSync } from '../../';
import {
GraphQLSchema,
GraphQLInputObjectType,
GraphQLObjectType,
GraphQLInterfaceType,
GraphQLUnionType,
Expand All @@ -37,6 +39,13 @@ const SomeInterfaceType = new GraphQLInterfaceType({
}),
});

const FooInput = new GraphQLInputObjectType({
name: 'FooInput',
fields: {
name: { type: new GraphQLNonNull(GraphQLString) },
},
});

const FooType = new GraphQLObjectType({
name: 'Foo',
interfaces: [SomeInterfaceType],
Expand Down Expand Up @@ -81,7 +90,10 @@ const testSchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
foo: { type: FooType },
foo: {
type: FooType,
args: { where: { type: FooInput } },
},
someUnion: { type: SomeUnionType },
someEnum: { type: SomeEnumType },
someInterface: {
Expand Down Expand Up @@ -200,6 +212,33 @@ describe('extendSchema', () => {
`);
});

it('extends schemas generated from SDL by adding new fields', () => {
const originalSDL = `
type Foo {
name: String
}
type FooInput {
name: String!
}
type Query {
foo(where: FooInput): Foo
}
`;
const schemaFromSDL = buildASTSchema(parse(originalSDL));
const extendedAst = parse(`
extend type Foo {
newField: String
}
`);
const extendedSchema = extendSchema(schemaFromSDL, extendedAst);
expect(printTestSchemaChanges(extendedSchema)).to.equal(dedent`
type Foo {
name: String
newField: String
}
`);
});

it('correctly assign AST nodes to new and extended types', () => {
const extendedSchema = extendTestSchema(`
extend type Query {
Expand Down