Skip to content

Commit

Permalink
[User] add toggle to avatarUrl so that we don't render data-url by de…
Browse files Browse the repository at this point in the history
…fault
  • Loading branch information
MrOrz committed Aug 14, 2021
1 parent 563f410 commit 52c272f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/graphql/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
GraphQLInt,
GraphQLNonNull,
GraphQLList,
GraphQLBoolean,
} from 'graphql';
import {
AvatarTypes,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/util/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52c272f

Please sign in to comment.