Skip to content

Commit

Permalink
feat: Add additional content to third-party API (#1206)
Browse files Browse the repository at this point in the history
* Add getDocuments query

* Remove print

* Add print back

* Add InternalNews to API

* Add LandingPage articles to API

* Add tests

* Update test data

* fix bug in developing locally with test jwt issuer service

* Update name of query

* Update schema and tests

---------

Co-authored-by: Abigail Young <abbyoung@gmail.com>
  • Loading branch information
jcbcapps and abbyoung authored Feb 7, 2024
1 parent 82b3e72 commit 053cd1d
Show file tree
Hide file tree
Showing 9 changed files with 529 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export PERSONNEL_API_URL=http://localhost:4000
##############################
# Third-Party API Config #
##############################
export JWKS_URI=https://federation.test.cce.af.mil/oidc/guardian-one/keys
export ISSUER=https://federation.test.cce.af.mil/oidc/guardian-one
export JWKS_URI=http://localhost:5001/.well-known/jwks.json
export ISSUER=http://localhost:5001/.well-known/issuer.json

###################################
# Database/Services Configuration #
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ services:
build:
context: ../ussf-portal/test-jwt-service/
dockerfile: Dockerfile
env_file: ../ussf-portal/e2e/.envrc.local
environment:
ISSUER: http://test-jwt-issuer:5001/.well-known/issuer.json
JWT_DEV_CERT: ${JWT_DEV_CERT}
ISSUER: http://localhost:5001/.well-known/issuer.json
restart: always
ports:
- '5001:5001'
Expand Down
33 changes: 33 additions & 0 deletions src/pages/api/thirdparty/dataSources/thirdPartyKeystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { KeyValueCache } from '@apollo/utils.keyvaluecache'
import { DateTime } from 'luxon'
import { print } from 'graphql'
import { GET_CNOTES } from '../operations/getPublicArticles'
import { GET_DOCUMENTS } from '../operations/getDocuments'
import { GET_NEWS_ARTICLES } from '../operations/getNewsArticles'
import { GET_LANDING_PAGE_ARTICLES } from '../operations/getLandingPageArticles'

class ThirdPartyKeystoneAPI extends RESTDataSource {
override baseURL = process.env.KEYSTONE_URL
Expand All @@ -21,6 +24,36 @@ class ThirdPartyKeystoneAPI extends RESTDataSource {
},
})
}

async getDocuments() {
return this.post(`/api/graphql`, {
body: {
query: print(GET_DOCUMENTS),
},
})
}

async getNewsArticles(publishedDate: DateTime) {
return this.post(`/api/graphql`, {
body: {
query: print(GET_NEWS_ARTICLES),
variables: {
publishedDate,
},
},
})
}

async getLandingPageArticles(publishedDate: DateTime) {
return this.post(`/api/graphql`, {
body: {
query: print(GET_LANDING_PAGE_ARTICLES),
variables: {
publishedDate,
},
},
})
}
}

export default ThirdPartyKeystoneAPI
16 changes: 16 additions & 0 deletions src/pages/api/thirdparty/operations/getDocuments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { gql } from 'graphql-tag'

export const GET_DOCUMENTS = gql`
query getDocuments {
documents {
id
title
description
file {
filename
filesize
url
}
}
}
`
30 changes: 30 additions & 0 deletions src/pages/api/thirdparty/operations/getLandingPageArticles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { gql } from 'graphql-tag'

export const GET_LANDING_PAGE_ARTICLES = gql`
query GetLandingPageArticles($publishedDate: DateTime) {
articles(
where: {
status: { equals: Published }
publishedDate: { lte: $publishedDate }
category: { equals: LandingPage }
}
orderBy: [{ publishedDate: desc }]
) {
id
title
preview
publishedDate
labels {
id
name
type
}
body {
document
}
tags {
name
}
}
}
`
30 changes: 30 additions & 0 deletions src/pages/api/thirdparty/operations/getNewsArticles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { gql } from 'graphql-tag'

export const GET_NEWS_ARTICLES = gql`
query GetNewsArticles($publishedDate: DateTime) {
articles(
where: {
status: { equals: Published }
publishedDate: { lte: $publishedDate }
category: { equals: InternalNews }
}
orderBy: [{ publishedDate: desc }]
) {
id
title
preview
publishedDate
labels {
id
name
type
}
body {
document
}
tags {
name
}
}
}
`
Loading

0 comments on commit 053cd1d

Please sign in to comment.