|
1 | | -from typing import List, Optional |
| 1 | +from typing import List, Optional, NewType |
2 | 2 |
|
3 | 3 | import strawberry |
4 | 4 | from strawberry.federation.schema_directives import Key, Requires |
5 | 5 |
|
6 | 6 | from app.graphql.corpus_recommendation import CorpusRecommendation |
7 | 7 | from app.graphql.directives import CacheControl |
| 8 | +from app.graphql.link import Url |
8 | 9 | from app.graphql.resolvers.item2item_resolvers import resolve_similar_to_saved, resolve_after_article |
9 | 10 | from app.models.item import ItemModel |
10 | 11 |
|
11 | 12 |
|
12 | 13 | @strawberry.experimental.pydantic.type( |
13 | 14 | model=ItemModel, |
14 | | - directives=[Key(fields="itemId")]) |
| 15 | + directives=[Key(fields="itemId"), Key(fields="givenUrl")]) |
15 | 16 | class Item: |
16 | 17 | 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. |
17 | 19 |
|
18 | 20 | # a field from a different subgraph |
19 | 21 | # see https://www.apollographql.com/docs/federation/entities-advanced/#contributing-computed-entity-fields |
20 | 22 | language: Optional[str] = strawberry.federation.field(external=True) |
21 | 23 |
|
22 | 24 | relatedAfterArticle: List[CorpusRecommendation] = strawberry.field( |
23 | 25 | directives=[CacheControl(maxAge=3600), |
24 | | - Requires(fields='language')], |
| 26 | + Requires(fields='language itemId')], |
25 | 27 | resolver=resolve_after_article, |
26 | 28 | description='Recommend similar articles to show in the bottom of an article.') |
27 | 29 |
|
28 | 30 | relatedAfterCreate: List[CorpusRecommendation] = strawberry.field( |
29 | 31 | directives=[CacheControl(maxAge=3600), |
30 | | - Requires(fields='language')], |
| 32 | + Requires(fields='language itemId')], |
31 | 33 | resolver=resolve_similar_to_saved, |
32 | 34 | description='Recommend similar articles after saving.') |
0 commit comments