Skip to content

Commit

Permalink
fix: interfaces can implement interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Aug 12, 2021
1 parent e0ae677 commit a88aeb2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/nexusDecorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function gatherRecursiveMeta<O extends MetaClass>(cls: O) {
fields = fields.concat(currentFields);
}
if (Array.isArray(currentInterfaces)) {
interfaces = currentInterfaces.concat(currentInterfaces);
interfaces = interfaces.concat(currentInterfaces);
}
walkingProto = Object.getPrototypeOf(walkingProto);
}
Expand Down
28 changes: 28 additions & 0 deletions test/__snapshots__/nexusDecorators.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@ type Query {
"
`;

exports[`nexus-decorators allows interfaces to implement interfaces 1`] = `
"interface Node {
id: ID!
}
type Post implements Node & Something {
id: ID!
name: String
title: String
}
type Query {
ok: Boolean!
}
interface Something implements Node {
id: ID!
name: String
}
type User implements Node & Something {
email: String
id: ID!
name: String
}
"
`;

exports[`nexus-decorators creates a schema 1`] = `
"\\"\\"\\"Implements the Node id\\"\\"\\"
interface Node {
Expand Down
43 changes: 43 additions & 0 deletions test/nexusDecorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,47 @@ describe("nexus-decorators", () => {
});
expect(printSchema(lexicographicSortSchema(out.schema))).toMatchSnapshot();
});

it("allows interfaces to implement interfaces", async () => {
@nxs.interfaceType({
resolveType() {},
})
abstract class Node {
@nxs.field.nonNull.id()
id() {
return "ID";
}
}

@nxs.interfaceType({
resolveType() {},
})
abstract class Something extends Node {
@nxs.field.string()
get name() {
return "Something";
}
}

@nxs.objectType()
class User extends Something {
@nxs.field.string()
get email() {
return "ok";
}
}

@nxs.objectType()
class Post extends Something {
@nxs.field.string()
get title() {
return "ok";
}
}

const out = core.makeSchemaInternal({
types: [User, Post, User],
});
expect(printSchema(lexicographicSortSchema(out.schema))).toMatchSnapshot();
});
});

0 comments on commit a88aeb2

Please sign in to comment.