Skip to content

Commit 8cdd9fe

Browse files
tests: interface list
1 parent 89b24f7 commit 8cdd9fe

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

__tests__/gql/schema.gql

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Query {
2929
testInterface(id: ID, label: String): TestInterface
3030
testInterfaceNonNull(id: ID, label: String): TestInterface!
3131
testInterfaceOptional(id: ID!): TestInterface
32+
testInterfaceMultiple(id: ID, label: String): [TestInterface]
3233
testObject(id: ID!): TestObject
3334
testObjectNonNull(id: ID!): TestObject!
3435
testObjects(size: String): [TestObject]

__tests__/integration/queries/object-kitchen-sink-test.js

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ describe("Integration | queries | object", function () {
2828
server.create("test-union-one", { oneName: "foo" }),
2929
server.create("test-union-two", { twoName: "bar" }),
3030
];
31+
const testInterfaces = [
32+
server.create("test-impl-one", {
33+
description: "description",
34+
label: "impl",
35+
}),
36+
server.create("test-impl-two", { label: "impl" }),
37+
];
3138

3239
seedUnassociatedRecords(server);
3340

@@ -41,6 +48,7 @@ describe("Integration | queries | object", function () {
4148
hasManyNonNullField: testOptions,
4249
hasManyNestedNonNullField: testOptions,
4350
interfaceField: testImpl,
51+
interfaceNestedNonNullField: testInterfaces,
4452
interfaceNonNullField: testImpl,
4553
relayConnectionField: testRelayNodes,
4654
relayConnectionFilteredField: testRelayNodes,
@@ -66,6 +74,10 @@ describe("Integration | queries | object", function () {
6674
hasManyNonNullField: [{ id: "1", name: "opt" }],
6775
hasManyNestedNonNullField: [{ id: "1", name: "opt" }],
6876
interfaceField: { id: "1", label: "impl" },
77+
interfaceNestedNonNullField: [
78+
{ id: "2", label: "impl", description: "description" },
79+
{ id: "1", label: "impl" },
80+
],
6981
interfaceNonNullField: { id: "1", label: "impl" },
7082
relayConnectionField: {
7183
edges: [{ cursor: "VGVzdFJlbGF5Tm9kZToy", node: { id: "2" } }],

__tests__/unit/resolvers/mirage-field-resolver-test.js

+17
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ describe("Unit | resolvers | mirage field resolver", function () {
106106
args,
107107
context,
108108
info,
109+
false,
110+
type
111+
);
112+
});
113+
114+
it("can resolve interface list types", function () {
115+
const type = typeMap.TestInterface;
116+
const info = { returnType: queryFields.testInterfaceMultiple.type };
117+
118+
mirageGraphQLFieldResolver(obj, args, context, info);
119+
120+
expect(resolveInterface).toHaveBeenCalledWith(
121+
obj,
122+
args,
123+
context,
124+
info,
125+
true,
109126
type
110127
);
111128
});

lib/resolvers/interface.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import resolveList from "./list";
12
import resolveObject from "./object";
23

34
function getTypeFromInlineFragment(info) {
@@ -39,15 +40,25 @@ function resolveFromImplementations(obj, args, context, info, type) {
3940
* @param {Object} args
4041
* @param {Object} context
4142
* @param {Object} info
43+
* @param {Boolean} isList
4244
* @param {Object} type An unwrapped type.
4345
* @see {@link https://graphql.org/learn/execution/#root-fields-resolvers}
4446
* @see resolveObject
4547
* @returns {Object} A record from Mirage's database.
4648
*/
47-
export default function resolveInterface(obj, args, context, info, type) {
49+
export default function resolveInterface(
50+
obj,
51+
args,
52+
context,
53+
info,
54+
isList,
55+
type
56+
) {
4857
const implType = getTypeFromInlineFragment(info);
4958

50-
return implType
59+
return isList
60+
? resolveList(obj, args, context, info, type)
61+
: implType
5162
? resolveObject(obj, args, context, info, implType)
5263
: resolveFromImplementations(obj, args, context, info, type);
5364
}

lib/resolvers/mirage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function mirageGraphQLFieldResolver(obj, args, context, info) {
3030
let { isList, type } = unwrapType(info.returnType);
3131

3232
return isInterfaceType(type)
33-
? resolveInterface(obj, args, context, info, type)
33+
? resolveInterface(obj, args, context, info, isList, type)
3434
: isUnionType(type)
3535
? resolveUnion(obj, args, context, info, isList, type)
3636
: !isObjectType(type)

0 commit comments

Comments
 (0)