Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit 00f98ef

Browse files
committed
fix(url): adding in url resolving
1 parent bcb33b4 commit 00f98ef

File tree

10 files changed

+45
-24
lines changed

10 files changed

+45
-24
lines changed

.run/tests.run.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="tests" type="tests" factoryName="py.test">
33
<module name="recommendation-api" />
4+
<option name="ENV_FILES" value="" />
45
<option name="INTERPRETER_OPTIONS" value="" />
56
<option name="PARENT_ENVS" value="true" />
67
<option name="SDK_HOME" value="" />
8+
<option name="SDK_NAME" value="Remote Python 3.11.2 Docker Compose (app)" />
79
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
8-
<option name="IS_MODULE_SDK" value="true" />
10+
<option name="IS_MODULE_SDK" value="false" />
911
<option name="ADD_CONTENT_ROOTS" value="true" />
1012
<option name="ADD_SOURCE_ROOTS" value="true" />
1113
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />

app/graphql/item.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
from typing import List, Optional
1+
from typing import List, Optional, NewType
22

33
import strawberry
44
from strawberry.federation.schema_directives import Key, Requires
55

66
from app.graphql.corpus_recommendation import CorpusRecommendation
77
from app.graphql.directives import CacheControl
8+
from app.graphql.link import Url
89
from app.graphql.resolvers.item2item_resolvers import resolve_similar_to_saved, resolve_after_article
910
from app.models.item import ItemModel
1011

1112

1213
@strawberry.experimental.pydantic.type(
1314
model=ItemModel,
14-
directives=[Key(fields="itemId")])
15+
directives=[Key(fields="itemId"), Key(fields="givenUrl")])
1516
class Item:
1617
item_id: str # This type is a 'str' and not an 'ID' in our graph.
18+
given_url: Url # This type is a 'str' and not an 'ID' in our graph.
1719

1820
# a field from a different subgraph
1921
# see https://www.apollographql.com/docs/federation/entities-advanced/#contributing-computed-entity-fields
2022
language: Optional[str] = strawberry.federation.field(external=True)
2123

2224
relatedAfterArticle: List[CorpusRecommendation] = strawberry.field(
2325
directives=[CacheControl(maxAge=3600),
24-
Requires(fields='language')],
26+
Requires(fields='language itemId')],
2527
resolver=resolve_after_article,
2628
description='Recommend similar articles to show in the bottom of an article.')
2729

2830
relatedAfterCreate: List[CorpusRecommendation] = strawberry.field(
2931
directives=[CacheControl(maxAge=3600),
30-
Requires(fields='language')],
32+
Requires(fields='language itemId')],
3133
resolver=resolve_similar_to_saved,
3234
description='Recommend similar articles after saving.')

app/graphql/recommendation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class Recommendation:
2020
feed_item_id: Optional[strawberry.ID] = strawberry.field(deprecation_reason="Use `id`")
2121
feed_id: auto
2222
item_id: strawberry.ID
23-
item: Item = strawberry.federation.field(shareable=True)
23+
item: Item = strawberry.federation
2424
rec_src: str
2525
publisher: auto

app/models/candidate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ class Candidate(BaseModel):
55
item_id: int
66
publisher: str
77
feed_id: Optional[int]
8+
url: str

app/models/item.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
class ItemModel(BaseModel):
55
item_id: str
6+
given_url: str

app/models/recommendation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def candidate_dict_to_recommendation(candidate: dict):
5252
feed_id=candidate.get('feed_id'),
5353
publisher=candidate.get('publisher'),
5454
item_id=candidate.get('item_id'),
55-
item=ItemModel(item_id=candidate.get('item_id'))
55+
item=ItemModel(item_id=candidate.get('item_id'), url=candidate.get('url')),
5656
)
5757
recommendation.feed_item_id = recommendation.id
5858
return recommendation

tests/functional/models/test_candidate_set_model.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ async def test_verify_candidate_set(candidate_sets_dynamodb_table, aiocache_fixt
1414
{
1515
"feed_id": 1,
1616
"item_id": 3208490410,
17-
"publisher": "hbr.org"
17+
"publisher": "hbr.org",
18+
"url": "https://hbr.org"
1819
}
1920
]
2021
})
@@ -32,7 +33,8 @@ async def test_get_candidate_set(candidate_sets_dynamodb_table, aiocache_fixture
3233
{
3334
"feed_id": 1,
3435
"item_id": 3208490410,
35-
"publisher": "hbr.org"
36+
"publisher": "hbr.org",
37+
"url": "https://hbr.org"
3638
}
3739
]
3840
})
@@ -54,7 +56,8 @@ async def test_get_cached_candidate_set(candidate_sets_dynamodb_table, aiocache_
5456
{
5557
"feed_id": 1,
5658
"item_id": 3208490410,
57-
"publisher": "hbr.org"
59+
"publisher": "hbr.org",
60+
"url": "https://hbr.org"
5861
}
5962
]
6063
})

tests/functional/models/test_slate_lineup_model.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
{
1919
"feed_id": 1,
2020
"item_id": 3208490410,
21-
"publisher": "hbr.org"
21+
"publisher": "hbr.org",
22+
"url": "https://hbr.org"
2223
}
2324
]
2425
}
@@ -31,12 +32,14 @@
3132
{
3233
"feed_id": 1,
3334
"item_id": 11,
34-
"publisher": "getpocket.com"
35+
"publisher": "getpocket.com",
36+
"url": "https://getpocket.com"
3537
},
3638
{
3739
"feed_id": 1,
3840
"item_id": 12,
39-
"publisher": "getpocket.com"
41+
"publisher": "getpocket.com",
42+
"url": "https://getpocket.com/item/test"
4043
}
4144
]
4245
}
@@ -119,17 +122,20 @@ async def test_get_slate_lineup_limited_recs(self, slate_config, slate_lineup_co
119122
{
120123
"feed_id": 1,
121124
"item_id": 3208490410,
122-
"publisher": "hbr.org"
125+
"publisher": "hbr.org",
126+
"url": "https://hbr.org"
123127
},
124128
{
125129
"feed_id": 1,
126130
"item_id": 3208650410,
127-
"publisher": "hbr.org"
131+
"publisher": "hbr.org",
132+
"url": "https://hbr.org/2"
128133
},
129134
{
130135
"feed_id": 1,
131136
"item_id": 32084925410,
132-
"publisher": "hbr.org"
137+
"publisher": "hbr.org",
138+
"url": "https://hbr.org/4"
133139
}
134140
]
135141
})
@@ -156,12 +162,14 @@ async def test_get_slate_lineup_dedupe_recs(self, slate_lineup_config):
156162
{
157163
"feed_id": 1,
158164
"item_id": 10,
159-
"publisher": "hbr.org"
165+
"publisher": "hbr.org",
166+
"url": "https://hbr.org/3"
160167
},
161168
{
162169
"feed_id": 1,
163170
"item_id": 11,
164-
"publisher": "hbr.org"
171+
"publisher": "hbr.org",
172+
"url": "https://hbr.org/123"
165173
},
166174
]
167175
})

tests/functional/models/test_slate_model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@
1010
{
1111
'feed_id': 1,
1212
'item_id': 3208490410,
13-
'publisher': 'hbr.org'
13+
'publisher': 'hbr.org',
14+
"url": "https://hbr.org/12"
1415
},
1516
{
1617
'feed_id': 1,
1718
'item_id': 32087704190,
18-
'publisher': 'hbr.org'
19+
'publisher': 'hbr.org',
20+
"url": "https://hbr.org/16"
1921
},
2022
{
2123
'feed_id': 12,
2224
'item_id': 32087904100,
23-
'publisher': 'hbr.org'
25+
'publisher': 'hbr.org',
26+
"url": "https://hbr.org/18"
2427
},
2528
{
2629
'feed_id': 2,
2730
'item_id': 32087904870,
28-
'publisher': 'hbr.org'
31+
'publisher': 'hbr.org',
32+
"url": "https://hbr.org/17"
2933
}
3034
]
3135

tests/unit/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def generate_recommendations(item_ids: List[int or str]) -> List[RecommendationM
1212
for item_id in item_ids:
1313
rec = RecommendationModel(
1414
item_id=item_id,
15-
item=ItemModel(item_id=item_id),
15+
item=ItemModel(item_id=item_id, url="https://getpocket.com"),
1616
rec_src='bowling',
1717
feed_id=random.randint(0, 101),
18-
id=random.randint(0, 101)
18+
id=random.randint(0, 101),
1919
)
2020
rec.feed_item_id = id
2121
recs.append(rec)

0 commit comments

Comments
 (0)