Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose post language #2628

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions __tests__/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6910,3 +6910,81 @@ describe('query fetchSmartTitle', () => {
});
});
});

describe('field language', () => {
const QUERY = /* GraphQL */ `
query Post($id: ID!) {
post(id: $id) {
language
}
}
`;

beforeEach(async () => {
await saveFixtures(con, ArticlePost, [
{
id: 'lp1',
shortId: 'slp1',
title: 'LP1',
url: 'http://lp1.com',
canonicalUrl: 'http://lp1c.com',
image: 'https://daily.dev/image.jpg',
score: 1,
sourceId: 'a',
tagsStr: 'javascript,webdev',
type: PostType.Article,
contentCuration: ['c1', 'c2'],
language: 'en',
},
{
id: 'lp2',
shortId: 'slp2',
title: 'LP2',
url: 'http://lp2.com',
canonicalUrl: 'http://lp2c.com',
image: 'https://daily.dev/image.jpg',
score: 1,
sourceId: 'a',
tagsStr: 'javascript,webdev',
type: PostType.Article,
contentCuration: ['c1', 'c2'],
language: 'de',
},
{
id: 'lp3',
shortId: 'slp3',
title: 'LP3',
url: 'http://lp3.com',
canonicalUrl: 'http://lp3c.com',
image: 'https://daily.dev/image.jpg',
score: 1,
sourceId: 'a',
tagsStr: 'javascript,webdev',
type: PostType.Article,
contentCuration: ['c1', 'c2'],
},
]);
});

it('should return the post language', async () => {
const res = await client.query(QUERY, {
variables: { id: 'lp1' },
});
expect(res.errors).toBeFalsy();
expect(res.data.post.language).toEqual('en');

const resDe = await client.query(QUERY, {
variables: { id: 'lp2' },
});
expect(resDe.errors).toBeFalsy();
expect(resDe.data.post.language).toEqual('de');
});

it('should default to en when language is not set', async () => {
const res = await client.query(QUERY, {
variables: { id: 'lp3' },
});
expect(res.errors).toBeFalsy();
expect(res.data.post.language).toEqual('en');
});
});
5 changes: 5 additions & 0 deletions src/schema/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ export const typeDefs = /* GraphQL */ `
List of available translations for the post
"""
translation: PostTranslation

"""
Language of the post
"""
language: String
Comment on lines +673 to +676
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick test (or update existing one) that it actually returns?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}

type PostConnection {
Expand Down
Loading