Skip to content

Commit cb26b81

Browse files
committed
[User] add toggle to avatarUrl so that we don't render data-url by default
1 parent 6235b51 commit cb26b81

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/graphql/models/User.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
GraphQLInt,
55
GraphQLNonNull,
66
GraphQLList,
7+
GraphQLBoolean,
78
} from 'graphql';
89
import {
910
AvatarTypes,
@@ -44,7 +45,16 @@ const User = new GraphQLObjectType({
4445
avatarUrl: {
4546
type: GraphQLString,
4647
description: 'returns avatar url from facebook, github or gravatar',
47-
resolve: avatarUrlResolver(),
48+
args: {
49+
renderAvatarData: {
50+
desription:
51+
'Renders data-url from avatarData for users with avatarType is OpenPeeps. When false (default), OpenPeeps avatars will return null for avatarUrl directly',
52+
type: GraphQLBoolean,
53+
},
54+
},
55+
resolve(user, args) {
56+
return avatarUrlResolver(args.renderAvatarData)(user);
57+
},
4858
},
4959
avatarData: {
5060
type: GraphQLString,

src/util/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ export const AvatarTypes = {
6262
* Returns avatar url based on avatarType.
6363
*/
6464
export const avatarUrlResolver = (
65+
renderAvatarData = false,
6566
s = 100,
6667
d = 'identicon',
6768
r = 'g'
6869
) => user => {
6970
switch (user.avatarType) {
7071
case AvatarTypes.OpenPeeps:
71-
return renderOpenPeepsDataUrl(user.avatarData);
72+
return renderAvatarData ? renderOpenPeepsDataUrl(user.avatarData) : null;
7273
case AvatarTypes.Facebook:
7374
return `https://graph.facebook.com/v9.0/${
7475
user.facebookId

0 commit comments

Comments
 (0)