Skip to content

Fix interface resolvers with custom schemaName #567

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

Merged
merged 4 commits into from
Mar 14, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/schema/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
28 changes: 28 additions & 0 deletions tests/functional/interfaces-and-inheritance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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(
Expand Down