Skip to content

Commit

Permalink
GraphQLInputObjectType: remove check that duplicate TS types (#3875)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Apr 4, 2023
1 parent a68dc42 commit 74e51d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 44 deletions.
28 changes: 0 additions & 28 deletions src/type/__tests__/definition-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,34 +566,6 @@ describe('Type System: Input Objects', () => {
});
});

describe('Input Object fields must not have resolvers', () => {
it('rejects an Input Object type with resolvers', () => {
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
fields: {
// @ts-expect-error (Input fields cannot have resolvers)
f: { type: ScalarType, resolve: dummyFunc },
},
});
expect(() => inputObjType.getFields()).to.throw(
'SomeInputObject.f field has a resolve property, but Input Types cannot define resolvers.',
);
});

it('rejects an Input Object type with resolver constant', () => {
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
fields: {
// @ts-expect-error (Input fields cannot have resolvers)
f: { type: ScalarType, resolve: {} },
},
});
expect(() => inputObjType.getFields()).to.throw(
'SomeInputObject.f field has a resolve property, but Input Types cannot define resolvers.',
);
});
});

it('Deprecation reason is preserved on fields', () => {
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
Expand Down
25 changes: 9 additions & 16 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1550,22 +1550,15 @@ function defineInputFieldMap(
config: Readonly<GraphQLInputObjectTypeConfig>,
): GraphQLInputFieldMap {
const fieldMap = resolveObjMapThunk(config.fields);
return mapValue(fieldMap, (fieldConfig, fieldName) => {
devAssert(
!('resolve' in fieldConfig),
`${config.name}.${fieldName} field has a resolve property, but Input Types cannot define resolvers.`,
);

return {
name: assertName(fieldName),
description: fieldConfig.description,
type: fieldConfig.type,
defaultValue: fieldConfig.defaultValue,
deprecationReason: fieldConfig.deprecationReason,
extensions: toObjMap(fieldConfig.extensions),
astNode: fieldConfig.astNode,
};
});
return mapValue(fieldMap, (fieldConfig, fieldName) => ({
name: assertName(fieldName),
description: fieldConfig.description,
type: fieldConfig.type,
defaultValue: fieldConfig.defaultValue,
deprecationReason: fieldConfig.deprecationReason,
extensions: toObjMap(fieldConfig.extensions),
astNode: fieldConfig.astNode,
}));
}

export interface GraphQLInputObjectTypeConfig {
Expand Down

0 comments on commit 74e51d7

Please sign in to comment.