diff --git a/client/src/api/albumDetail.ts b/client/src/api/albumDetail.ts index 415d064..642b463 100644 --- a/client/src/api/albumDetail.ts +++ b/client/src/api/albumDetail.ts @@ -45,7 +45,6 @@ export const ALBUM_DETAIL = graphql(` comment createdAt user { - id displayName } } diff --git a/client/src/api/client.ts b/client/src/api/client.ts index 2224901..0d22546 100644 --- a/client/src/api/client.ts +++ b/client/src/api/client.ts @@ -21,6 +21,8 @@ type CachedCrate = { // InMemoryCache stores server results and shares album records by their IDs. export const cache = new InMemoryCache({ typePolicies: { + // Public User objects intentionally omit the internal identity UUID. + User: { merge: true }, Query: { fields: { // Each response is the complete recent list, including [] after clear. diff --git a/client/src/generated/gql.ts b/client/src/generated/gql.ts index a641b0f..ded4f8d 100644 --- a/client/src/generated/gql.ts +++ b/client/src/generated/gql.ts @@ -14,7 +14,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/ * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size */ type Documents = { - "\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n id\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n": typeof types.AlbumDetailDocument, + "\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n": typeof types.AlbumDetailDocument, "\n mutation AddToCrate($albumId: ID!) {\n addToCrate(albumId: $albumId) {\n item {\n id\n }\n album {\n id\n isInCrate\n }\n }\n }\n": typeof types.AddToCrateDocument, "\n mutation RemoveFromCrate($albumId: ID!) {\n removeFromCrate(albumId: $albumId) {\n removedAlbumId\n album {\n id\n isInCrate\n }\n }\n }\n": typeof types.RemoveFromCrateDocument, "\n query MyCrate($first: Int!, $after: String) {\n myCrate(first: $first, after: $after) {\n edges {\n cursor\n node {\n id\n addedAt\n album {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n averageRating\n reviewCount\n isInCrate\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n }\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n totalCount\n }\n }\n": typeof types.MyCrateDocument, @@ -26,7 +26,7 @@ type Documents = { "\n mutation ClearSearchHistory {\n clearSearchHistory\n }\n": typeof types.ClearSearchHistoryDocument, }; const documents: Documents = { - "\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n id\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n": types.AlbumDetailDocument, + "\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n": types.AlbumDetailDocument, "\n mutation AddToCrate($albumId: ID!) {\n addToCrate(albumId: $albumId) {\n item {\n id\n }\n album {\n id\n isInCrate\n }\n }\n }\n": types.AddToCrateDocument, "\n mutation RemoveFromCrate($albumId: ID!) {\n removeFromCrate(albumId: $albumId) {\n removedAlbumId\n album {\n id\n isInCrate\n }\n }\n }\n": types.RemoveFromCrateDocument, "\n query MyCrate($first: Int!, $after: String) {\n myCrate(first: $first, after: $after) {\n edges {\n cursor\n node {\n id\n addedAt\n album {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n averageRating\n reviewCount\n isInCrate\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n }\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n totalCount\n }\n }\n": types.MyCrateDocument, @@ -55,7 +55,7 @@ export function graphql(source: string): unknown; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n id\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n"): (typeof documents)["\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n id\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n"]; +export function graphql(source: "\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n"): (typeof documents)["\n query AlbumDetail($id: ID!, $reviewFirst: Int!, $reviewAfter: String) {\n album(id: $id) {\n id\n title\n releaseYear\n musicBrainzReleaseGroupId\n artists {\n id\n name\n }\n genres {\n id\n name\n }\n tracks {\n id\n title\n trackNumber\n durationSeconds\n }\n averageRating\n reviewCount\n isInCrate\n myReview {\n id\n rating\n comment\n }\n reviews(first: $reviewFirst, after: $reviewAfter) {\n edges {\n cursor\n node {\n id\n rating\n comment\n createdAt\n user {\n displayName\n }\n }\n }\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/client/src/generated/graphql.ts b/client/src/generated/graphql.ts index 8bb9849..8df5fb5 100644 --- a/client/src/generated/graphql.ts +++ b/client/src/generated/graphql.ts @@ -35,7 +35,7 @@ export type AlbumDetailQueryVariables = Exact<{ }>; -export type AlbumDetailQuery = { album: { id: string, title: string, releaseYear: number | null, musicBrainzReleaseGroupId: string | null, averageRating: number | null, reviewCount: number, isInCrate: boolean, artists: Array<{ id: string, name: string }>, genres: Array<{ id: string, name: string }>, tracks: Array<{ id: string, title: string, trackNumber: number, durationSeconds: number | null }>, myReview: { id: string, rating: number, comment: string } | null, reviews: { totalCount: number, edges: Array<{ cursor: string, node: { id: string, rating: number, comment: string, createdAt: string, user: { id: string, displayName: string } } }>, pageInfo: { hasNextPage: boolean, endCursor: string | null } } } | null }; +export type AlbumDetailQuery = { album: { id: string, title: string, releaseYear: number | null, musicBrainzReleaseGroupId: string | null, averageRating: number | null, reviewCount: number, isInCrate: boolean, artists: Array<{ id: string, name: string }>, genres: Array<{ id: string, name: string }>, tracks: Array<{ id: string, title: string, trackNumber: number, durationSeconds: number | null }>, myReview: { id: string, rating: number, comment: string } | null, reviews: { totalCount: number, edges: Array<{ cursor: string, node: { id: string, rating: number, comment: string, createdAt: string, user: { displayName: string } } }>, pageInfo: { hasNextPage: boolean, endCursor: string | null } } } | null }; export type AddToCrateMutationVariables = Exact<{ albumId: string | number; @@ -100,7 +100,7 @@ export type ClearSearchHistoryMutationVariables = Exact<{ [key: string]: never; export type ClearSearchHistoryMutation = { clearSearchHistory: boolean }; -export const AlbumDetailDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AlbumDetail"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"reviewFirst"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"reviewAfter"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"album"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"releaseYear"}},{"kind":"Field","name":{"kind":"Name","value":"musicBrainzReleaseGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"artists"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"genres"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"tracks"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"trackNumber"}},{"kind":"Field","name":{"kind":"Name","value":"durationSeconds"}}]}},{"kind":"Field","name":{"kind":"Name","value":"averageRating"}},{"kind":"Field","name":{"kind":"Name","value":"reviewCount"}},{"kind":"Field","name":{"kind":"Name","value":"isInCrate"}},{"kind":"Field","name":{"kind":"Name","value":"myReview"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"rating"}},{"kind":"Field","name":{"kind":"Name","value":"comment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"reviews"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"reviewFirst"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"reviewAfter"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cursor"}},{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"rating"}},{"kind":"Field","name":{"kind":"Name","value":"comment"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"user"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"totalCount"}},{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}}]}}]}}]}}]} as unknown as DocumentNode; +export const AlbumDetailDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AlbumDetail"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"reviewFirst"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"reviewAfter"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"album"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"releaseYear"}},{"kind":"Field","name":{"kind":"Name","value":"musicBrainzReleaseGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"artists"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"genres"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"tracks"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"trackNumber"}},{"kind":"Field","name":{"kind":"Name","value":"durationSeconds"}}]}},{"kind":"Field","name":{"kind":"Name","value":"averageRating"}},{"kind":"Field","name":{"kind":"Name","value":"reviewCount"}},{"kind":"Field","name":{"kind":"Name","value":"isInCrate"}},{"kind":"Field","name":{"kind":"Name","value":"myReview"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"rating"}},{"kind":"Field","name":{"kind":"Name","value":"comment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"reviews"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"reviewFirst"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"reviewAfter"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cursor"}},{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"rating"}},{"kind":"Field","name":{"kind":"Name","value":"comment"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"user"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"displayName"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"totalCount"}},{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const AddToCrateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"AddToCrate"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"albumId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"addToCrate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"albumId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"albumId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"item"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"album"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isInCrate"}}]}}]}}]}}]} as unknown as DocumentNode; export const RemoveFromCrateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RemoveFromCrate"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"albumId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"removeFromCrate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"albumId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"albumId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"removedAlbumId"}},{"kind":"Field","name":{"kind":"Name","value":"album"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isInCrate"}}]}}]}}]}}]} as unknown as DocumentNode; export const MyCrateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyCrate"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myCrate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cursor"}},{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"addedAt"}},{"kind":"Field","name":{"kind":"Name","value":"album"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"releaseYear"}},{"kind":"Field","name":{"kind":"Name","value":"musicBrainzReleaseGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"averageRating"}},{"kind":"Field","name":{"kind":"Name","value":"reviewCount"}},{"kind":"Field","name":{"kind":"Name","value":"isInCrate"}},{"kind":"Field","name":{"kind":"Name","value":"artists"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"genres"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}},{"kind":"Field","name":{"kind":"Name","value":"totalCount"}}]}}]}}]} as unknown as DocumentNode; diff --git a/client/src/pages/AlbumDetailPage.test.tsx b/client/src/pages/AlbumDetailPage.test.tsx index 57b0c29..9656303 100644 --- a/client/src/pages/AlbumDetailPage.test.tsx +++ b/client/src/pages/AlbumDetailPage.test.tsx @@ -33,7 +33,7 @@ const detail = { rating: 5, comment: 'A classic.', createdAt: '2026-10-20T12:00:00.000Z', - user: { id: 'user-1', displayName: 'Listener user-1' }, + user: { displayName: 'Velvet Groove' }, }, }, ], @@ -87,7 +87,7 @@ it('renders an album tracklist and its first page of reviews', async () => { expect(within(tracklist).getByText('Something')).toBeInTheDocument(); const reviews = screen.getByRole('region', { name: 'Ratings & reviews' }); expect(within(reviews).queryByText(/out of 5/)).not.toBeInTheDocument(); - expect(within(reviews).getByText('Listener user-1')).toBeInTheDocument(); + expect(within(reviews).getByText('Velvet Groove')).toBeInTheDocument(); expect(within(reviews).getByText('A classic.')).toBeInTheDocument(); expect(within(reviews).getByLabelText('5 out of 5 stars')).toBeInTheDocument(); }); @@ -219,7 +219,7 @@ it('preserves the empty-tracklist message', async () => { it.each([ ['1', 'You'], - ['2', 'Listener user-1'], + ['2', 'Velvet Groove'], ])('labels a review with own review ID %s as %s', async (ownReviewId, authorLabel) => { render( rating: 4, comment: 'Still brilliant.', createdAt: '2026-10-19T12:00:00.000Z', - user: { id: 'user-2', displayName: 'Listener user-2' }, + user: { displayName: 'Amber Needle' }, }, }, ], @@ -326,7 +326,7 @@ it('loads the next page of reviews and labels an own review as You', async () => ); await screen.findByRole('heading', { name: 'Abbey Road' }); - expect(screen.getByText('Listener user-1')).toBeInTheDocument(); + expect(screen.getByText('Velvet Groove')).toBeInTheDocument(); expect(screen.queryByText('You')).not.toBeInTheDocument(); const more = screen.getByRole('button', { name: 'Load more reviews' }); more.focus(); @@ -342,8 +342,8 @@ it('loads the next page of reviews and labels an own review as You', async () => expect(articles).toHaveLength(2); expect(within(articles[1]!).getByText('Still brilliant.')).toBeInTheDocument(); expect(screen.getByText('A classic.')).toBeInTheDocument(); - expect(screen.getByText('Listener user-1')).toBeInTheDocument(); - expect(screen.queryByText('Listener user-2')).not.toBeInTheDocument(); + expect(screen.getByText('Velvet Groove')).toBeInTheDocument(); + expect(screen.queryByText('Amber Needle')).not.toBeInTheDocument(); expect( screen.queryByRole('button', { name: 'Load more reviews' }), ).not.toBeInTheDocument(); @@ -367,7 +367,7 @@ it('keeps long authors and comments in full with an accessible rating and date', const node = { ...detail.reviews.edges[0]!.node, comment, - user: { id: 'u1', displayName: author }, + user: { displayName: author }, }; const { container } = renderDetail({ reviews: { ...detail.reviews, edges: [{ cursor: 'r1', node }] }, diff --git a/docs/AI-USAGE.md b/docs/AI-USAGE.md index 28ed354..745f626 100644 --- a/docs/AI-USAGE.md +++ b/docs/AI-USAGE.md @@ -103,6 +103,7 @@ the part that matters most. | 2026-11-13 | rachelks | Codex (ChatGPT) | Assisted with #24 frontend integration, dropdown keyboard navigation, accessibility and tests, as well as debugging React/Apollo warnings and simplifying the SearchForm/DiscoveryPage responsibilities. All changes were thoroughly reviewed and tested before committing. | | 2026-11-13 | robertky | Codex (ChatGPT) | Assisted me with #26: polished the README, added screenshots and project-document links, and verified the local setup from a clean clone. I reviewed the changes and updated the implementation notes to reflect merged browsing and country-filter features. | | 2026-11-17 | erikhfj | Antigravity | #91, E2E search helper fix: updated `e2e/tests/search.spec.ts` to match the `Search` and `Filters` buttons with `exact: true` so `Clear recent searches` does not trigger a strict-mode violation, and cleared `E2E_USER_ID`'s recorded search history during cleanup. Verified locally with two consecutive full `pnpm test:e2e` runs against a throwaway seeded PostgreSQL stack. | +| 2026-11-20 | erikhfj | Antigravity | #100, review author privacy: removed `User.id` from `schema.graphql` and the `AlbumDetail` query, replaced `Listener ` with deterministic SHA-256 music pseudonyms in `server/src/userIdentity.ts` (including read-time sanitization of legacy labels in `Review.user`), added `User` cache merge policy, and updated schema/unit/client tests and `docs/architecture.md`. Verified with `pnpm codegen`, `pnpm format:check`, `pnpm lint`, `pnpm typecheck`, `pnpm test`, and `pnpm build`. | ## Notes diff --git a/docs/architecture.md b/docs/architecture.md index f852e13..1142252 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -105,12 +105,14 @@ Reads never fail because of identity state, so a bad header cannot take the search page down. Writes require it and say so rather than attributing the change to nobody. -**Consequences:** Much less to build, and no security. Sending someone else's +**Consequences:** Much less to build, and no authentication. Sending someone else's UUID in `X-User-Id` writes as that user, so this separates visitors rather than -authenticating them. Deriving `displayName` from the UUID stops the client -choosing an arbitrary name string and stops a review claiming a display name -the sender did not hold, but it does **not** stop impersonation: the UUID is -the whole identity and it is client-supplied. Clearing `localStorage` resets the user's identity in the browser, but their existing reviews and crate items remain in the database. +authenticating them. To avoid leaking simulated identity tokens, the GraphQL +`User` type only exposes `displayName` (never the internal UUID) and derives a +deterministic pseudonym via a one-way SHA-256 hash of the UUID rather than +embedding UUID characters. Deriving `displayName` server-side stops the client +choosing an arbitrary name string, though it is still not an authentication +guarantee. Clearing `localStorage` resets the user's identity in the browser, but their existing reviews and crate items remain in the database. ## 6. Plain CSS, Apollo Client cache, URL as search state diff --git a/schema.graphql b/schema.graphql index 03ab862..219167b 100644 --- a/schema.graphql +++ b/schema.graphql @@ -66,8 +66,11 @@ type Genre { name: String! } +""" +Public author metadata for a review. Internal simulated user IDs are never +exposed through the GraphQL API. +""" type User { - id: ID! displayName: String! } diff --git a/server/src/resolvers.ts b/server/src/resolvers.ts index aaf8948..8b08acb 100644 --- a/server/src/resolvers.ts +++ b/server/src/resolvers.ts @@ -19,6 +19,7 @@ import { } from './search/search.js'; import { removeReview, saveReview, type UpsertReviewInput } from './reviews.js'; import { addToCrate, removeFromCrate } from './crate.js'; +import { publicDisplayName } from './userIdentity.js'; import { clearSearchHistory, historyForUser, recordSearch } from './searchHistory.js'; export type Context = { db: Db; loaders: Loaders; userId: string | null }; @@ -345,7 +346,7 @@ export const resolvers = { user: async (review: { userId: string }, _: unknown, ctx: Context) => { const user = await ctx.loaders.userById.load(review.userId); if (!user) throw new Error('Review owner is missing.'); - return user; + return { displayName: publicDisplayName(user.id, user.displayName) }; }, }, Mutation: { diff --git a/server/src/reviews.test.ts b/server/src/reviews.test.ts index 6f19814..2fa16cc 100644 --- a/server/src/reviews.test.ts +++ b/server/src/reviews.test.ts @@ -1,8 +1,15 @@ +import { readFileSync } from 'node:fs'; +import { buildSchema, validate, parse } from 'graphql'; import { describe, expect, it } from 'vitest'; +import { resolvers, type Context } from './resolvers.js'; import { removeReview, saveReview } from './reviews.js'; +import { displayNameFor } from './userIdentity.js'; const userId = '550e8400-e29b-41d4-a716-446655440000'; +const schema = buildSchema( + readFileSync(new URL('../../schema.graphql', import.meta.url), 'utf8'), +); describe('review input validation', () => { it.each([0, 6, 1.5])('rejects rating %s before database work', async (rating) => { @@ -25,3 +32,45 @@ describe('review input validation', () => { ).rejects.toThrow('Comment must be at most 2000 characters'); }); }); + +describe('public review author privacy', () => { + it('does not expose User.id in the GraphQL schema', () => { + const errors = validate( + schema, + parse(` + query { + album(id: "1") { + reviews(first: 1) { + edges { + node { + user { + id + displayName + } + } + } + } + } + } + `), + ); + + expect(errors.map((error) => error.message)).toContain( + 'Cannot query field "id" on type "User".', + ); + }); + + it('omits user id and upgrades legacy UUID-prefix labels in Review.user', async () => { + const ctx = { + loaders: { + userById: { + load: async () => ({ id: userId, displayName: 'Listener 550e8400' }), + }, + }, + } as unknown as Context; + + const author = await resolvers.Review.user({ userId }, {}, ctx); + expect(author).toEqual({ displayName: displayNameFor(userId) }); + expect('id' in author).toBe(false); + }); +}); diff --git a/server/src/userIdentity.test.ts b/server/src/userIdentity.test.ts index 0744664..f64a086 100644 --- a/server/src/userIdentity.test.ts +++ b/server/src/userIdentity.test.ts @@ -1,8 +1,14 @@ import { describe, expect, it } from 'vitest'; -import { displayNameFor, parseUserId, requireUserId } from './userIdentity.js'; +import { + displayNameFor, + parseUserId, + publicDisplayName, + requireUserId, +} from './userIdentity.js'; const userId = '550e8400-e29b-41d4-a716-446655440000'; +const otherUserId = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; describe('parseUserId', () => { it('accepts UUIDs and normalises their casing', () => { @@ -18,8 +24,18 @@ describe('parseUserId', () => { }); describe('simulated users', () => { - it('derives a stable display name from the UUID', () => { - expect(displayNameFor(userId)).toBe('Listener 550e8400'); + it('derives a stable, friendly pseudonym without revealing UUID characters', () => { + const label = displayNameFor(userId); + expect(label).toMatch(/^[A-Z][a-z]+ [A-Z][a-z]+$/); + expect(displayNameFor(userId.toUpperCase())).toBe(label); + expect(label.toLowerCase()).not.toContain(userId.slice(0, 8)); + expect(displayNameFor(otherUserId)).not.toBe(label); + }); + + it('replaces legacy UUID-prefix labels while preserving custom display names', () => { + expect(publicDisplayName(userId, 'Listener 550e8400')).toBe(displayNameFor(userId)); + expect(publicDisplayName(userId, ' ')).toBe(displayNameFor(userId)); + expect(publicDisplayName(userId, 'Warm Vinyl')).toBe('Warm Vinyl'); }); it('rejects writes without a valid identity', () => { diff --git a/server/src/userIdentity.ts b/server/src/userIdentity.ts index a596c80..8b23b0c 100644 --- a/server/src/userIdentity.ts +++ b/server/src/userIdentity.ts @@ -1,3 +1,4 @@ +import { createHash } from 'node:crypto'; import { eq } from 'drizzle-orm'; import { GraphQLError } from 'graphql'; @@ -12,12 +13,97 @@ export type UserIdentity = { const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; +// Legacy labels embedded the first 8 hex characters of the simulated user UUID. +const LEGACY_DISPLAY_NAME_PATTERN = /^Listener [0-9a-f]{8}$/i; + +const PSEUDONYM_ADJECTIVES = [ + 'Amber', + 'Analog', + 'Brass', + 'Bright', + 'Cedar', + 'Cobalt', + 'Copper', + 'Crisp', + 'Deep', + 'Dusk', + 'Echo', + 'Golden', + 'Harbor', + 'Indigo', + 'Ivory', + 'Lunar', + 'Mellow', + 'Midnight', + 'Moss', + 'Muted', + 'Nordic', + 'Ochre', + 'Pine', + 'Quiet', + 'Saffron', + 'Silver', + 'Slate', + 'Solar', + 'Steady', + 'Velvet', + 'Warm', + 'Woven', +] as const; + +const PSEUDONYM_NOUNS = [ + 'Bassline', + 'Beat', + 'Bridge', + 'Cadence', + 'Chord', + 'Chorus', + 'Crate', + 'Drift', + 'Groove', + 'Harmony', + 'Harp', + 'Hihat', + 'Horn', + 'Liner', + 'Loop', + 'Melody', + 'Meter', + 'Needle', + 'Note', + 'Octave', + 'Organ', + 'Platter', + 'Pressing', + 'Pulse', + 'Record', + 'Refrain', + 'Rhythm', + 'Sleeve', + 'Spindle', + 'Stylus', + 'Tempo', + 'Vinyl', +] as const; + export function parseUserId(value: string | null): string | null { return value && UUID_PATTERN.test(value) ? value.toLowerCase() : null; } export function displayNameFor(userId: string): string { - return `Listener ${userId.slice(0, 8)}`; + const digest = createHash('sha256').update(userId.toLowerCase()).digest(); + const adjective = + PSEUDONYM_ADJECTIVES[digest.readUInt16BE(0) % PSEUDONYM_ADJECTIVES.length]!; + const noun = PSEUDONYM_NOUNS[digest.readUInt16BE(2) % PSEUDONYM_NOUNS.length]!; + return `${adjective} ${noun}`; +} + +export function publicDisplayName(userId: string, storedDisplayName: string): string { + const trimmed = storedDisplayName.trim(); + if (!trimmed || LEGACY_DISPLAY_NAME_PATTERN.test(trimmed)) { + return displayNameFor(userId); + } + return trimmed; } export function requireUserId(userId: string | null): string {