Skip to content

Commit

Permalink
feat(setup): setting up ability to run whole graph locally
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Aug 24, 2024
1 parent f96a447 commit 56caff9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions servers/parser-graphql-wrapper/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ extend type CorpusItem @key(fields: "url") {
preview: PocketMetadata!
@requires(fields: "title excerpt datePublished publisher image { url }")
}

extend type Collection @key(fields: "slug") {
"""
Provides short url for the given_url in the format: https://pocket.co/<identifier>.
Expand Down
13 changes: 10 additions & 3 deletions servers/parser-graphql-wrapper/src/apollo/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
import { SSMLModel } from '../models/SSMLModel';
import { fallbackPage } from '../readerView';
import { PocketDefaultScalars } from '@pocket-tools/apollo-utils';
import { Item, Resolvers, Videoness } from '../__generated__/resolvers-types';
import {
CorpusItem,
Item,
Resolvers,
Videoness,
} from '../__generated__/resolvers-types';
import { BoolStringParam, MediaTypeParam } from '../datasources/ParserAPI';
import {
extractSlugFromReadUrl,
Expand All @@ -27,6 +32,7 @@ export const resolvers: Resolvers = {
item,
context,
false,
{ syndicatedArticle: item.syndicatedArticle },
);
return {
url: representation.url,
Expand Down Expand Up @@ -155,6 +161,7 @@ export const resolvers: Resolvers = {
parent as Item,
context,
clearCache,
{ syndicatedArticle: parent.syndicatedArticle },
);
return { ...preview, item: parent as Item };
},
Expand Down Expand Up @@ -215,15 +222,15 @@ export const resolvers: Resolvers = {
return null;
}
},
preview: async (parent: { url: string }, _, context) => {
console.log(parent);
preview: async (parent, _, context) => {
const item = await context.dataSources.parserAPI.getItemData(parent.url);

const preview =
await context.dataSources.pocketMetadataModel.derivePocketMetadata(
item,
context,
false,
{ corpusItem: parent as CorpusItem },
);
return { ...preview, item };
},
Expand Down
37 changes: 27 additions & 10 deletions servers/parser-graphql-wrapper/src/models/PocketMetadataModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {
PocketMetadataSource,
PocketMetadata,
ItemSummary,
SyndicatedArticle,
CorpusItem,
Collection,
} from '../__generated__/resolvers-types';
import config from '../config';
import { DateTime } from 'luxon';
Expand Down Expand Up @@ -36,31 +39,42 @@ export class PocketMetadataModel {
item: Item,
context: IContext,
refresh: boolean,
extraData: {
corpusItem?: CorpusItem;
syndicatedArticle?: SyndicatedArticle;
collection?: Collection;
} = {},
): Promise<PocketMetadata> {
const { corpusItem, syndicatedArticle, collection } = extraData;

Check failure on line 48 in servers/parser-graphql-wrapper/src/models/PocketMetadataModel.ts

View workflow job for this annotation

GitHub Actions / lint

'collection' is assigned a value but never used
const url = item.givenUrl; // the url we are going to key everything on.
const fallbackParserPocketMetadata: ItemSummary = {
id: item.id,
image: item.syndicatedArticle?.mainImage
image: syndicatedArticle?.mainImage
? {
url: item.syndicatedArticle?.mainImage,
url: syndicatedArticle?.mainImage,
imageId: 0,
src: item.syndicatedArticle?.mainImage,
src: syndicatedArticle?.mainImage,
}
: (item.topImage ?? item.images?.[0]),
excerpt: item.syndicatedArticle?.excerpt ?? item.excerpt,
title: item.syndicatedArticle?.title ?? item.title ?? item.givenUrl,
authors: item.syndicatedArticle?.authorNames
? item.syndicatedArticle.authorNames.map((author, index) => {
excerpt:
syndicatedArticle?.excerpt ?? corpusItem?.excerpt ?? item.excerpt,
title:
syndicatedArticle?.title ??
corpusItem?.title ??
item.title ??
item.givenUrl,
authors: syndicatedArticle?.authorNames
? syndicatedArticle.authorNames.map((author, index) => {
return {
name: author,
id: index.toFixed(),
};
})
: item.authors,
domain: item.syndicatedArticle?.publisher
domain: syndicatedArticle?.publisher
? {
logo: item.syndicatedArticle.publisher.logo,
name: item.syndicatedArticle.publisher.name,
logo: syndicatedArticle.publisher.logo,
name: syndicatedArticle.publisher.name,
}
: item.domainMetadata,
datePublished: item.datePublished
Expand All @@ -69,9 +83,12 @@ export class PocketMetadataModel {
}).toJSDate()
: null,
url: url,
//TODO: when we have a native pocket type, change the type and source
source: PocketMetadataSource.PocketParser,
__typename: 'ItemSummary',
};
//TODO: re-enable the other parsers once the main data is setup
return fallbackParserPocketMetadata;

// First we filter to our sources.
// We do this first because some sources could be behind a feature flag or not enabled
Expand Down

0 comments on commit 56caff9

Please sign in to comment.