Skip to content

Commit

Permalink
Merge pull request #576 from lens-protocol/fix/missing__typename
Browse files Browse the repository at this point in the history
fix: missing __typename(s) and profile.invitedBy fields
  • Loading branch information
cesarenaldi authored Oct 7, 2023
2 parents 05afd45 + ef89713 commit ad478bf
Show file tree
Hide file tree
Showing 30 changed files with 1,164 additions and 414 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fixed": [["@lens-protocol/react", "@lens-protocol/react-web"]],
"linked": [],
"access": "public",
"baseBranch": "main",
"baseBranch": "lens-v2",
"updateInternalDependencies": "patch",
"ignore": ["example-*"]
}
6 changes: 6 additions & 0 deletions .changeset/new-doors-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lens-protocol/api-bindings": patch
"@lens-protocol/react": patch
---

**fix:** adds missing `__typename` and expose `ProfileFields` from `Profile.invitedBy`
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"large-cars-know",
"lemon-drinks-exercise",
"long-carpets-marry",
"new-doors-sip",
"old-carrots-breathe",
"shaggy-carrots-cry",
"shy-pugs-taste",
Expand Down
37 changes: 32 additions & 5 deletions examples/web/src/publications/components/PublicationCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
import { Comment, Mirror, Post, Quote, isPostPublication } from '@lens-protocol/react';
import { Comment, Post, AnyPublication, PublicationMetadata } from '@lens-protocol/react';

import { ProfilePicture } from '../../profiles/components/ProfilePicture';

function MetadataSwitch({ metadata }: { metadata: PublicationMetadata }) {
switch (metadata.__typename) {
case 'ArticleMetadataV3':
case 'TextOnlyMetadataV3':
return <p>{metadata.content}</p>;

default:
return <p>{metadata.__typename} not supported in this example</p>;
}
}

function PublicationContent({ publication }: { publication: Post | Comment }) {
return (
<section>
<MetadataSwitch metadata={publication.metadata} />
</section>
);
}

function PublicationSwitch({ publication }: { publication: AnyPublication }) {
switch (publication.__typename) {
case 'Post':
case 'Comment':
return <PublicationContent publication={publication} />;
default:
return null;
}
}

type PublicationCardProps = {
publication: Post | Comment | Mirror | Quote;
publication: AnyPublication;
};

export function PublicationCard({ publication }: PublicationCardProps) {
Expand All @@ -14,9 +43,7 @@ export function PublicationCard({ publication }: PublicationCardProps) {
{publication.__typename} by{' '}
{publication.by.metadata?.displayName ?? publication.by.handle ?? publication.by.id}
</p>
{isPostPublication(publication) && 'content' in publication.metadata && (
<p>{publication.metadata.content}</p>
)}
<PublicationSwitch publication={publication} />
</article>
);
}
6 changes: 6 additions & 0 deletions packages/api-bindings/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @lens-protocol/api-bindings

## 0.11.0-alpha.2

### Patch Changes

- 6f51659c: **fix:** adds missing `__typename` and expose `ProfileFields` from `Profile.invitedBy`

## 0.11.0-alpha.1

### Patch Changes
Expand Down
2 changes: 2 additions & 0 deletions packages/api-bindings/codegen-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ generates:
skipTypename: true
immutableTypes: false
inlineFragmentTypes: combine
exportFragmentSpreadSubTypes: false # we do not want odd named fragment types ProfilePicture_ImageSet_
omitOperationSuffix: true
operationResultSuffix: 'Data'
dedupeFragments: true
- 'typescript-react-apollo':
pureMagicComment: true # keep
omitOperationSuffix: true # MUST goes with typescript-operations.omitOperationSuffix
Expand Down
2 changes: 1 addition & 1 deletion packages/api-bindings/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lens-protocol/api-bindings",
"version": "0.11.0-alpha.1",
"version": "0.11.0-alpha.2",
"description": "Graphql fragments, react hooks, typescript types of lens API.",
"repository": {
"directory": "packages/api-bindings",
Expand Down
36 changes: 36 additions & 0 deletions packages/api-bindings/src/lens/MetadataAttribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
MetadataBooleanAttribute,
MetadataDateAttribute,
MetadataJsonAttribute,
MetadataNumberAttribute,
MetadataStringAttribute,
} from './graphql/generated';

/**
* Convenience type for metadata attributes.
*
* @example
* Use this type as prop type for a component that renders metadata attributes.
* ```tsx
*
* function PublicationAttribute({ attribute }: { attribute: MetadataAttribute }) {
* switch (attribute.__typename) {
* case 'MetadataBooleanAttribute':
* return <p><strong>{attribute.key}</strong>{attribute.value === 'true' ? 'Yes' : 'No'}</p>;
*
* case 'MetadataDateAttribute':
* return <p><strong>{attribute.key}</strong>{new Date(attribute.value).toLocaleString()}</p>;
*
* case 'MetadataNumberAttribute':
* return <p><strong>{attribute.key}</strong>{parseFloat(attribute.value).toFixed(2)}</p>;
*
* // ...
* }
* ```
*/
export type MetadataAttribute =
| MetadataBooleanAttribute
| MetadataDateAttribute
| MetadataNumberAttribute
| MetadataJsonAttribute
| MetadataStringAttribute;
128 changes: 89 additions & 39 deletions packages/api-bindings/src/lens/__helpers__/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { mockProfileId, mockPublicationId, mockTransactionHash } from '@lens-pro
import { mockEvmAddress } from '@lens-protocol/shared-kernel/mocks';

import {
CanDecryptResponse,
Comment,
FeedItem,
Mirror,
NetworkAddress,
OptimisticStatusResult,
PaginatedResultInfo,
Post,
Profile,
ProfileActionHistory,
ProfileActionHistoryType,
ProfileOnchainIdentity,
ProfileOperations,
ProfileReactionResult,
ProfileStats,
ProfileWhoReactedResult,
Expand All @@ -21,6 +26,62 @@ import {
TriStateValue,
} from '../graphql/generated';

function mockNetworkAddressFragment(overrides?: Partial<NetworkAddress>): NetworkAddress {
return {
address: mockEvmAddress(),
chainId: 1,
...overrides,
__typename: 'NetworkAddress',
};
}

function mockOptimisticStatusResultFragment(
overrides?: Partial<OptimisticStatusResult>,
): OptimisticStatusResult {
return {
value: true,
isFinalisedOnchain: false,
...overrides,
__typename: 'OptimisticStatusResult',
};
}

function mockProfileOperationsFragment(overrides?: Partial<ProfileOperations>): ProfileOperations {
return {
id: mockProfileId(),
canBlock: false,
canUnblock: false,
canFollow: TriStateValue.Unknown,
canUnfollow: false,
isBlockedByMe: mockOptimisticStatusResultFragment(),
isFollowedByMe: mockOptimisticStatusResultFragment(),
isFollowingMe: mockOptimisticStatusResultFragment(),
...overrides,
__typename: 'ProfileOperations',
};
}

function mockProfileOnchainIdentityFragment(
overrides?: Partial<ProfileOnchainIdentity>,
): ProfileOnchainIdentity {
return {
proofOfHumanity: false,
ens: null,
sybilDotOrg: {
source: {
twitter: {
handle: null,
},
},
},
worldcoin: {
isHuman: false,
},
...overrides,
__typename: 'ProfileOnchainIdentity',
};
}

export function mockProfileFragment(overrides?: Partial<Profile>): Profile {
const firstName = faker.name.firstName();
const lastName = faker.name.lastName();
Expand All @@ -34,39 +95,11 @@ export function mockProfileFragment(overrides?: Partial<Profile>): Profile {
invitesLeft: 0,
sponsor: false,
lensManager: false,
ownedBy: {
address: mockEvmAddress(),
chainId: 1,
},
operations: {
id: mockProfileId(),
canBlock: false,
canUnblock: false,
canFollow: TriStateValue.Unknown,
canUnfollow: false,
isBlockedByMe: { value: false, isFinalisedOnchain: false },
isFollowedByMe: { value: false, isFinalisedOnchain: false },
isFollowingMe: { value: false, isFinalisedOnchain: false },
},
ownedBy: mockNetworkAddressFragment(),
operations: mockProfileOperationsFragment(),
guardian: null,
onchainIdentity: {
proofOfHumanity: false,
ens: null,
sybilDotOrg: {
source: {
twitter: {
handle: null,
},
},
},
worldcoin: {
isHuman: false,
},
},
followNftAddress: {
address: mockEvmAddress(),
chainId: 1,
},
onchainIdentity: mockProfileOnchainIdentityFragment(),
followNftAddress: mockNetworkAddressFragment(),
followModule: null,
metadata: null,
invitedBy: null,
Expand Down Expand Up @@ -139,7 +172,9 @@ export function mockMirrorFragment(overrides?: Partial<Omit<Mirror, '__typename'
};
}

export function mockPublicationTextOnlyMetadata(overrides: Partial<TextOnlyMetadataV3> = {}) {
export function mockPublicationTextOnlyMetadata(
overrides: Partial<TextOnlyMetadataV3> = {},
): TextOnlyMetadataV3 {
return {
id: faker.helpers.unique(faker.datatype.uuid),
rawURI: faker.internet.url(),
Expand All @@ -154,6 +189,19 @@ export function mockPublicationTextOnlyMetadata(overrides: Partial<TextOnlyMetad
encryptedWith: null,

...overrides,
__typename: 'TextOnlyMetadataV3',
};
}

function mockCanDecryptResponseFragment(
overrides?: Partial<ProfileOperations>,
): CanDecryptResponse {
return {
result: false,
reasons: null,
extraDetails: null,
...overrides,
__typename: 'CanDecryptResponse',
};
}

Expand All @@ -170,14 +218,11 @@ export function mockPublicationOperationsFragment(
hasMirrored: false,
hasUpvoted: false,
hasDownvoted: false,
hasCollected: { value: false, isFinalisedOnchain: false },
canDecrypt: {
result: false,
reasons: null,
extraDetails: null,
},
hasCollected: mockOptimisticStatusResultFragment(),
canDecrypt: mockCanDecryptResponseFragment(),

...overrides,
__typename: 'PublicationOperations',
};
}

Expand Down Expand Up @@ -207,6 +252,7 @@ export function mockPublicationStatsFragment(
downvotes: faker.datatype.number(),

...overrides,
__typename: 'PublicationStats',
};
}

Expand All @@ -227,6 +273,7 @@ export function mockProfileStatsFragment(overrides: Partial<ProfileStats> = {}):
downvoted: faker.datatype.number(),

...overrides,
__typename: 'ProfileStats',
};
}

Expand All @@ -239,6 +286,7 @@ export function mockFeedItemFragment(overrides?: Partial<FeedItem>): FeedItem {
reactions: [],

...overrides,
__typename: 'FeedItem',
};
}

Expand All @@ -264,6 +312,7 @@ export function mockProfileReactionResultFragment(
reactionAt: faker.date.past().toISOString(),

...overrides,
__typename: 'ProfileReactionResult',
};
}

Expand All @@ -275,5 +324,6 @@ export function mockProfileWhoReactedResultFragment(
reactions: [mockProfileReactionResultFragment()],

...overrides,
__typename: 'ProfileWhoReactedResult',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SearchPublicationsDocument,
SearchPublicationsVariables,
} from '../../graphql/generated';
import { AnyPublication, PrimaryPublication } from '../../utils';
import { AnyPublication, PrimaryPublication } from '../../publication';
import { mockPaginatedResultInfo } from '../fragments';
import { mockAnyPaginatedResponse } from './mockAnyPaginatedResponse';

Expand Down
5 changes: 3 additions & 2 deletions packages/api-bindings/src/lens/graphql/auth.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
fragment AuthChallenge on AuthChallengeResult {
fragment AuthChallengeResult on AuthChallengeResult {
__typename
id
text
}

query AuthChallenge($request: ChallengeRequest!) {
result: challenge(request: $request) {
...AuthChallenge
...AuthChallengeResult
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/api-bindings/src/lens/graphql/feed.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fragment ReactionEvent on ReactionEvent {
}

fragment FeedItem on FeedItem {
__typename
id
root {
... on Post {
Expand Down
Loading

0 comments on commit ad478bf

Please sign in to comment.