Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Add an abstraction layer to the API (#117)
Browse files Browse the repository at this point in the history
- Added graphql-codegen packages to generate types and custom Apollo hooks
for both local and remote APIs.

- Refactored all of the AppSync API to use the new generated types.

- Set up queries for the local API and a way to switch between the two APIs.

- Reorganised component and page imports throughout.

- Fixed bug with author field updates never making it to the backend on prospect
approval.

Closes #99.
  • Loading branch information
nina-py authored Feb 4, 2021
1 parent 0e3efd4 commit 8b1d734
Show file tree
Hide file tree
Showing 60 changed files with 5,086 additions and 458 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ yarn-error.log*
.eslintcache

# local API - generated data
/local-api/db.json
/local-api-server/db.json

aws-appsync.codegen.yml

35 changes: 22 additions & 13 deletions local-api/generateData.js → local-api-server/generateData.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ jsf.extend('faker', () => {
// Note that some of the entries will have different states
// (i.e. REJECTED, APPROVED), so only a handful will appear
// in the Snoozed tab (PENDING state + snoozedUntil in the future)
const options = [null, null, date.toISOString()];
const random = Math.floor(Math.random() * options.length);
return options[random];
return faker.random.arrayElement[(null, null, date.toISOString())];
},
imageUrl: () => {
const random = Math.round(Math.random() * 1000);
return faker.random.arrayElement([
`${faker.image.nature()}?random=${random}`,
`${faker.image.city()}?random=${random}`,
`${faker.image.food()}?random=${random}`,
]);
},
itemId: () => {
return faker.random
Expand All @@ -34,9 +40,12 @@ jsf.extend('faker', () => {
},
updatedAt: () => {
// not too many updated entries
const options = [null, null, null, faker.date.recent(0).toISOString()];
const random = Math.floor(Math.random() * options.length);
return options[random];
return faker.random.arrayElement([
null,
null,
null,
faker.date.recent(0).toISOString(),
]);
},
};

Expand All @@ -60,8 +69,8 @@ const schema = {
},
prospects: {
type: 'array',
minItems: 200,
maxItems: 300,
minItems: 1000,
maxItems: 1500,
items: { $ref: '#/definitions/prospects' },
},
},
Expand All @@ -76,7 +85,7 @@ const schema = {
},
name: {
type: 'string',
enum: ['en-US', 'en-UK', 'de-DE'],
enum: ['en-US', 'en-GB', 'de-DE'],
},
},
},
Expand Down Expand Up @@ -118,15 +127,15 @@ const schema = {
},
title: {
type: 'string',
faker: 'hacker.phrase',
faker: 'lorem.sentence',
},
excerpt: {
type: 'string',
faker: 'lorem.paragraph',
},
imageUrl: {
type: 'string',
faker: 'image.people',
faker: 'custom.imageUrl',
},
altText: {
type: 'string',
Expand Down Expand Up @@ -159,15 +168,15 @@ const schema = {
},
sourceName: {
type: 'string',
faker: 'lorem.word',
enum: ['Syndication', 'Manual Entry', 'Other'],
},
sourceScore: {
type: 'float',
faker: 'random.float',
},
syndicationArticleId: {
type: 'string',
faker: 'random.alphaNumeric',
faker: 'random.hexaDecimal',
},
createdAt: {
type: 'string',
Expand Down
9 changes: 9 additions & 0 deletions local-api.codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
overwrite: true
schema: "http://localhost:4000"
documents: ["src/api/local/queries/*.ts", "src/api/local/mutations/*.ts", "src/api/local/fragments/*.ts"]
generates:
src/api/local/generatedTypes.ts:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
Loading

0 comments on commit 8b1d734

Please sign in to comment.