Skip to content

Commit

Permalink
fix: resolve interface list types
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryThePenguin committed Jun 7, 2022
1 parent 64c7870 commit d82f525
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
17 changes: 17 additions & 0 deletions __tests__/unit/resolvers/mirage-field-resolver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ describe("Unit | resolvers | mirage field resolver", function () {
args,
context,
info,
false,
type
);
});

it("can resolve interface list types", function () {
const type = typeMap.TestInterface;
const info = { returnType: queryFields.testInterfaceMultiple.type };

mirageGraphQLFieldResolver(obj, args, context, info);

expect(resolveInterface).toHaveBeenCalledWith(
obj,
args,
context,
info,
true,
type
);
});
Expand Down
15 changes: 13 additions & 2 deletions lib/resolvers/interface.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import resolveList from "./list";
import resolveObject from "./object";

function getTypeFromInlineFragment(info) {
Expand Down Expand Up @@ -39,15 +40,25 @@ function resolveFromImplementations(obj, args, context, info, type) {
* @param {Object} args
* @param {Object} context
* @param {Object} info
* @param {Boolean} isList
* @param {Object} type An unwrapped type.
* @see {@link https://graphql.org/learn/execution/#root-fields-resolvers}
* @see resolveObject
* @returns {Object} A record from Mirage's database.
*/
export default function resolveInterface(obj, args, context, info, type) {
export default function resolveInterface(
obj,
args,
context,
info,
isList,
type
) {
const implType = getTypeFromInlineFragment(info);

return implType
return isList
? resolveList(obj, args, context, info, type)
: implType
? resolveObject(obj, args, context, info, implType)
: resolveFromImplementations(obj, args, context, info, type);
}
2 changes: 1 addition & 1 deletion lib/resolvers/mirage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function mirageGraphQLFieldResolver(obj, args, context, info) {
let { isList, type } = unwrapType(info.returnType);

return isInterfaceType(type)
? resolveInterface(obj, args, context, info, type)
? resolveInterface(obj, args, context, info, isList, type)
: isUnionType(type)
? resolveUnion(obj, args, context, info, isList, type)
: !isObjectType(type)
Expand Down

0 comments on commit d82f525

Please sign in to comment.