diff --git a/src/graphql/models/User.js b/src/graphql/models/User.js index 69db7f91..11e81d54 100644 --- a/src/graphql/models/User.js +++ b/src/graphql/models/User.js @@ -4,6 +4,7 @@ import { GraphQLInt, GraphQLNonNull, GraphQLList, + GraphQLBoolean, } from 'graphql'; import { AvatarTypes, @@ -44,7 +45,16 @@ const User = new GraphQLObjectType({ avatarUrl: { type: GraphQLString, description: 'returns avatar url from facebook, github or gravatar', - resolve: avatarUrlResolver(), + args: { + renderAvatarData: { + desription: + 'Renders data-url from avatarData for users with avatarType is OpenPeeps. When false (default), OpenPeeps avatars will return null for avatarUrl directly', + type: GraphQLBoolean, + }, + }, + resolve(user, args) { + return avatarUrlResolver(args.renderAvatarData)(user); + }, }, avatarData: { type: GraphQLString, diff --git a/src/util/user.js b/src/util/user.js index 4d08d028..e5d42829 100644 --- a/src/util/user.js +++ b/src/util/user.js @@ -62,13 +62,14 @@ export const AvatarTypes = { * Returns avatar url based on avatarType. */ export const avatarUrlResolver = ( + renderAvatarData = false, s = 100, d = 'identicon', r = 'g' ) => user => { switch (user.avatarType) { case AvatarTypes.OpenPeeps: - return renderOpenPeepsDataUrl(user.avatarData); + return renderAvatarData ? renderOpenPeepsDataUrl(user.avatarData) : null; case AvatarTypes.Facebook: return `https://graph.facebook.com/v9.0/${ user.facebookId