Skip to content

Commit

Permalink
feat: exposes params.statsFor and params.profile.metadataSource in Le…
Browse files Browse the repository at this point in the history
…nsConfig
  • Loading branch information
cesarenaldi committed Nov 23, 2023
1 parent acfad68 commit c466b81
Show file tree
Hide file tree
Showing 40 changed files with 6,227 additions and 3,744 deletions.
7 changes: 7 additions & 0 deletions .changeset/four-squids-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/api-bindings": minor
"@lens-protocol/react": minor
"@lens-protocol/react-web": minor
---

**feat:** introduces `params.statsFor` and `params.profile.metadataSource` in `LensConfig`
6 changes: 6 additions & 0 deletions .changeset/young-mayflies-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lens-protocol/gated-content": patch
"@lens-protocol/client": patch
---

**fix:** cleanup obsolete environment configuration
13 changes: 12 additions & 1 deletion packages/api-bindings/src/apollo/__helpers__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { GraphQLRequest, NormalizedCacheObject, OperationVariables } from '@apol
import { MockedResponse, mockSingleLink } from '@apollo/client/testing';
import { DocumentNode, ExecutionResult, GraphQLError } from 'graphql';

import { SupportedFiatType } from '../../lens';
import { SafeApolloClient } from '../SafeApolloClient';
import { createLensCache, createSnapshotCache } from '../cache';
import { ApolloServerErrorCode } from '../errors';
Expand All @@ -10,7 +11,17 @@ export function mockLensApolloClient(
mocks: ReadonlyArray<MockedResponse<unknown>> = [],
): SafeApolloClient<NormalizedCacheObject> {
return new SafeApolloClient({
cache: createLensCache(),
cache: createLensCache({
fxRateFor: SupportedFiatType.Usd,
image: {
medium: {},
small: {},
},
profile: {
cover: {},
thumbnail: {},
},
}),

link: mockSingleLink(...mocks).setOnError((error) => {
throw error;
Expand Down
115 changes: 77 additions & 38 deletions packages/api-bindings/src/apollo/cache/createQueryParamsLocalFields.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,77 @@
import { FieldReadFunction } from '@apollo/client';
import { FieldFunctionOptions, FieldReadFunction } from '@apollo/client';
import { AppId } from '@lens-protocol/domain/entities';
import { UnknownObject } from '@lens-protocol/shared-kernel';

import { ImageSizeTransform, ImageTransform, SupportedFiatType } from '../../lens';

/**
* The common query parameters used across any query.
*/
export type QueryParams = {
image: {
/**
* The size of the publication image.
*
* @defaultValue see individual fields
*/
image?: {
/**
* The size of the small publication image
*
* @defaultValue width: 400px, height: auto, keepAspectRatio: true
*/
small: ImageTransform;
small?: ImageTransform;
/**
* The size of the medium publication image
*
* @defaultValue width: 700px, height: auto, keepAspectRatio: true
*/
medium: ImageTransform;
medium?: ImageTransform;
};
profile: {
/**
* Profile related fields parameters
*
* @defaultValue see individual fields
*/
profile?: {
/**
* The size of optimized profile image
*
* @defaultValue width: 256px, height: auto, keepAspectRatio: true
*/
thumbnail: ImageTransform;
thumbnail?: ImageTransform;
/**
* The size of the cover image
*
* @defaultValue width: 1100px, height: auto, keepAspectRatio: true
*/
cover?: ImageTransform;
/**
* The source to use for fetching profile metadata details.
*
* If not provided, it will default to the global profile metadata for any profile fetched.
*
* If provided and a profile does not have bespoke profile metadata it will fallback to their global profile metadata.
*
* To know more about app specific profile metadata, see example with `appId` in {@link https://lens-protocol.github.io/metadata/functions/profile.html}.
*
* @defaultValue empty, global profile metadata
*/
cover: ImageTransform;
metadataSource?: AppId;
};
/**
* The fiat currency to use for the fx rate
*
* @defaultValue USD
*/
fxRateFor?: SupportedFiatType;
/**
* The App Ids for which to fetch Publication and Profile Stats for.
*
* Affects mainly comments, mirrors, and quotes counts.
*
* @defaultValue empty, all apps
*/
fxRateFor: SupportedFiatType;
statsFor?: AppId[];
};

function buildImageTransform(
Expand Down Expand Up @@ -63,43 +105,40 @@ export const defaultQueryParams: QueryParams = {
/**
* @internal
*/
export type LocalOnlyFieldPolicies = {
fxRateFor: FieldReadFunction<SupportedFiatType>;

profileCoverSize: FieldReadFunction<ImageTransform>;

profilePictureSize: FieldReadFunction<ImageTransform>;

imageSmallSize: FieldReadFunction<ImageTransform>;
export type WithStatsForVariable = UnknownObject & {
statsFor?: AppId[];
};

imageMediumSize: FieldReadFunction<ImageTransform>;
/**
* @internal
*/
export type LocalOnlyFieldPolicies = {
queryParams: FieldReadFunction<QueryParams>;
};

/**
* @internal
*/
export function createQueryParamsLocalFields(
params: QueryParams = defaultQueryParams,
): LocalOnlyFieldPolicies {
export function createQueryParamsLocalFields({
fxRateFor,
image,
profile,
statsFor,
}: QueryParams = {}): LocalOnlyFieldPolicies {
return {
fxRateFor() {
return params.fxRateFor;
},

profileCoverSize() {
return params.profile.cover;
},

profilePictureSize() {
return params.profile.thumbnail;
},

imageSmallSize() {
return params.image.small;
},

imageMediumSize() {
return params.image.medium;
queryParams(_, { variables }: FieldFunctionOptions<UnknownObject, WithStatsForVariable>) {
return {
image: Object.assign({}, defaultQueryParams.image, image),
profile: Object.assign(
{
metadataSource: null,
},
defaultQueryParams.profile,
profile,
),
statsFor: variables?.statsFor ?? statsFor ?? defaultQueryParams.statsFor,
fxRateFor: fxRateFor ?? defaultQueryParams.fxRateFor,
};
},
};
}
2 changes: 1 addition & 1 deletion packages/api-bindings/src/apollo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ApolloClientConfig = {
uri: string;
logger: ILogger;
pollingInterval: number;
queryParams: QueryParams;
queryParams?: QueryParams;
};

export function createLensApolloClient({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function mockAnyResponse(bulk: MockedResponse) {
imageSmallSize: {},
profileCoverSize: {},
profilePictureSize: {},
profileMetadataSource: null,
},
},
result: bulk.result,
Expand Down Expand Up @@ -52,6 +53,7 @@ export function mockAnyPaginatedResponse<V extends OperationVariables, I>({
imageSmallSize: {},
profileCoverSize: {},
profilePictureSize: {},
profileMetadataSource: null,
},
},
result: {
Expand Down
56 changes: 50 additions & 6 deletions packages/api-bindings/src/lens/graphql/client.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,60 @@ extend type PaginatedResultInfo {
moreAfter: Boolean!
}

type ImageTransformParam {
type ImageTransformParams {
height: ImageSizeTransform
width: ImageSizeTransform
keepAspectRatio: Boolean
}

extend type Query {
type ImageQueryParams {
small: ImageTransformParams
medium: ImageTransformParams
}

type ProfileQueryParams {
cover: ImageTransformParams
thumbnail: ImageTransformParams
metadataSource: AppId
}

type QueryParams {
image: ImageQueryParams
profile: ProfileQueryParams
fxRateFor: SupportedFiatType
profileCoverSize: ImageTransformParam
profilePictureSize: ImageTransformParam
imageSmallSize: ImageTransformParam
imageMediumSize: ImageTransformParam
}

extend type Query {
queryParams: QueryParams!
}

fragment InjectQueryParams on Query {
queryParams @client {
image {
small @export(as: "imageSmallSize") {
height
width
keepAspectRatio
}
medium @export(as: "imageMediumSize") {
height
width
keepAspectRatio
}
}
profile {
cover @export(as: "profileCoverSize") {
height
width
keepAspectRatio
}
thumbnail @export(as: "profilePictureSize") {
height
width
keepAspectRatio
}
metadataSource @export(as: "profileMetadataSource")
}
fxRateFor @export(as: "fxRateFor")
}
}
10 changes: 6 additions & 4 deletions packages/api-bindings/src/lens/graphql/explore.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ query ExplorePublications(
$imageMediumSize: ImageTransform = {}
$profileCoverSize: ImageTransform = {}
$profilePictureSize: ImageTransform = {}
$activityOn: [AppId!]
$statsFor: [AppId!]
$fxRateFor: SupportedFiatType = USD
$profileMetadataSource: AppId = null
) {
...InjectCommonQueryParams
...InjectQueryParams
result: explorePublications(
request: { orderBy: $orderBy, where: $where, limit: $limit, cursor: $cursor }
) {
Expand All @@ -39,10 +40,11 @@ query ExploreProfiles(
$cursor: Cursor
$profileCoverSize: ImageTransform = {}
$profilePictureSize: ImageTransform = {}
$activityOn: [AppId!]
$statsFor: [AppId!]
$fxRateFor: SupportedFiatType = USD
$profileMetadataSource: AppId = null
) {
...InjectCommonQueryParams
...InjectQueryParams
result: exploreProfiles(
request: { where: $where, orderBy: $orderBy, limit: $limit, cursor: $cursor }
) {
Expand Down
10 changes: 6 additions & 4 deletions packages/api-bindings/src/lens/graphql/feed.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ query Feed(
$imageMediumSize: ImageTransform = {}
$profileCoverSize: ImageTransform = {}
$profilePictureSize: ImageTransform = {}
$activityOn: [AppId!]
$statsFor: [AppId!]
$fxRateFor: SupportedFiatType = USD
$profileMetadataSource: AppId = null
) {
result: feed(request: { where: $where, cursor: $cursor }) {
items {
Expand Down Expand Up @@ -68,10 +69,11 @@ query FeedHighlights(
$imageMediumSize: ImageTransform = {}
$profileCoverSize: ImageTransform = {}
$profilePictureSize: ImageTransform = {}
$activityOn: [AppId!]
$statsFor: [AppId!]
$fxRateFor: SupportedFiatType = USD
$profileMetadataSource: AppId = null
) {
...InjectCommonQueryParams
...InjectQueryParams
result: feedHighlights(request: { where: $where, limit: $limit, cursor: $cursor }) {
items {
...FeedHighlight
Expand All @@ -91,7 +93,7 @@ query FeedHighlights(
# $profilePictureSize: ImageTransform = {}
# $fxRateFor: SupportedFiatType = USD
#) {
# ...InjectCommonQueryParams
# ...InjectQueryParams
# result: forYou(request: $request) {
# items {
# ... on Post {
Expand Down
Loading

0 comments on commit c466b81

Please sign in to comment.