From cb26b819ff9d14edbdc4b7712eed0dab612fa591 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Sat, 14 Aug 2021 18:34:57 +0800 Subject: [PATCH] [User] add toggle to avatarUrl so that we don't render data-url by default --- src/graphql/models/User.js | 12 +++++++++++- src/util/user.js | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) 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