diff --git a/CHANGELOG.md b/CHANGELOG.md index 6464057dd..bbfb27020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - fix transforming and validating nested inputs and arrays (#462) - remove duplicated entries for resolver classes that use inheritance (#499) - **Breaking Change**: stop returning null for `GraphQLTimestamp` and `GraphQLISODateTime` scalars when returned value is not a `Date` instance - now it throws explicit error instead +- fix using `name` option on interface fields (#567) ### Others - **Breaking Change**: change build config to ES2018 - drop support for Node.js < 10.3 - **Breaking Change**: remove deprecated `DepreciationOptions` interface diff --git a/src/schema/schema-generator.ts b/src/schema/schema-generator.ts index 3afa5655b..af11cc89b 100644 --- a/src/schema/schema-generator.ts +++ b/src/schema/schema-generator.ts @@ -234,6 +234,7 @@ export abstract class SchemaGenerator { fieldsMap[field.schemaName] = { description: field.description, type: this.getGraphQLOutputType(field.name, field.getType(), field.typeOptions), + resolve: createBasicFieldResolver(field), }; return fieldsMap; }, diff --git a/tests/functional/interfaces-and-inheritance.ts b/tests/functional/interfaces-and-inheritance.ts index 052776e63..4812f9afb 100644 --- a/tests/functional/interfaces-and-inheritance.ts +++ b/tests/functional/interfaces-and-inheritance.ts @@ -473,10 +473,14 @@ describe("Interfaces and inheritance", () => { abstract class BaseInterface { @Field() baseInterfaceField: string; + + @Field({ name: "renamedInterfaceField", nullable: true }) + interfaceFieldToBeRenamed?: string; } @ObjectType({ implements: BaseInterface }) class FirstImplementation implements BaseInterface { baseInterfaceField: string; + interfaceFieldToBeRenamed?: string; @Field() firstField: string; } @@ -624,6 +628,15 @@ describe("Interfaces and inheritance", () => { secondField: "secondField", }; } + + @Query() + renamedFieldInterfaceQuery(): BaseInterface { + const obj = new FirstImplementation(); + obj.baseInterfaceField = "baseInterfaceField"; + obj.firstField = "firstField"; + obj.interfaceFieldToBeRenamed = "interfaceFieldToBeRenamed"; + return obj; + } } schema = await buildSchema({ @@ -745,6 +758,21 @@ describe("Interfaces and inheritance", () => { expect(data.firstField).toEqual("firstField"); }); + it("should allow interfaces to specify custom schema names", async () => { + const query = `query { + renamedFieldInterfaceQuery { + renamedInterfaceField + } + }`; + + const { data, errors } = await graphql(schema, query); + + expect(errors).toBeUndefined(); + expect(data!.renamedFieldInterfaceQuery.renamedInterfaceField).toEqual( + "interfaceFieldToBeRenamed", + ); + }); + it("should pass args data of extended args class", async () => { const query = `query { queryWithArgs(