From 40541314251bec94030c929d4860d6229e7fbbb9 Mon Sep 17 00:00:00 2001 From: Theodor Diaconu Date: Tue, 31 Jul 2018 18:16:09 +0300 Subject: [PATCH] Fixed #3 - graphql non-null links now work --- LinkDirective.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/LinkDirective.js b/LinkDirective.js index 135170d..ca1fd2a 100644 --- a/LinkDirective.js +++ b/LinkDirective.js @@ -26,11 +26,15 @@ export default class LinkDirective extends SchemaDirectiveVisitor { referencedType = field.type; } - if (!(referencedType instanceof GraphQLObjectType)) { - throw new Meteor.Error( - 'invalid-type', - `You are trying to attach a link on a invalid type. @link directive only works with GraphQLObjectType ` - ); + if (referencedType instanceof GraphQLNonNull) { + referencedType = referencedType.ofType; + } else { + if (!(referencedType instanceof GraphQLObjectType)) { + throw new Meteor.Error( + 'invalid-type', + `You are trying to attach a link on a invalid type. @link directive only works with GraphQLObjectType ` + ); + } } let referencedCollectionName = referencedType._mongoCollectionName;