Skip to content

Commit 1ed8c26

Browse files
GQL-109: Make cmr-grahphql calls to graphdb easier to use and make cmr-graphql more resistant to a graphdb outage
* GQL-109: Add env var to not require running graphdb instance, fix searching by provider * GQL-109: Rename graphdb data source to graphDbRelatedCollections * GQL-109: Move logic to resolver update README.md
1 parent 3eb64af commit 1ed8c26

10 files changed

Lines changed: 304 additions & 57 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ This application will be available at [http://127.0.0.1:3013/api](http://127.0.0
7878
#### Local graph database
7979

8080
We use a graph database to query against related collections and duplicate collections. To send queries to a locally running graph database, we can use a docker gremlin-server that exposes an HTTP endpoint. This is launched by running
81+
You can optionally not require a graphdb server to be running locally by setting the `GRAPHDB_ENABLED` to false in the `.env` for the env you are running against. If it is set to false this will return empty responses from graphdb.
8182

8283
`docker run -it -p 8182:8182 tinkerpop/gremlin-server conf gremlin-server-rest-modern.yaml`
8384

bin/deploy-bamboo.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dockerRun() {
4343
-e "GRAPHDB_HOST=$bamboo_GRAPHDB_HOST" \
4444
-e "GRAPHDB_PATH=$bamboo_GRAPHDB_PATH" \
4545
-e "GRAPHDB_PORT=$bamboo_GRAPHDB_PORT" \
46+
-e "GRAPHDB_ENABLED=$bamboo_GRAPHDB_ENABLED" \
4647
-e "GTM_ID=$bamboo_GTM_ID" \
4748
-e "LAMBDA_TIMEOUT=$bamboo_LAMBDA_TIMEOUT" \
4849
-e "LOG_DESTINATION_ARN=$bamboo_LOG_DESTINATION_ARN" \

cdk/graphql/lib/graphql-stack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const environment = {
3232
edlJwk: process.env.EDL_JWK!,
3333
edlKeyId: process.env.EDL_KEY_ID!,
3434
graphdbHost: process.env.GRAPHDB_HOST || 'http://localhost',
35+
graphdbEnabled: process.env.GRAPHDB_ENABLED || 'true',
3536
graphdbPath: process.env.GRAPHDB_PATH!,
3637
graphdbPort: process.env.GRAPHDB_PORT || '8182',
3738
maxRetries: process.env.MAX_RETRIES || '1',

src/datasources/__tests__/graphDb.test.js renamed to src/datasources/__tests__/graphDbRelatedCollections.test.js

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nock from 'nock'
22

3-
import graphDbDatasource from '../graphDb'
3+
import graphDbRelatedCollectionsDatasource from '../graphDbRelatedCollections'
44

55
import relatedCollectionsGraphDbPlatformInstrumentGraphdbResponseMocks from './__mocks__/relatedCollections.graphDbPlatformInstrument.graphdbResponse.mocks'
66
import relatedCollectionsGraphDbPlatformInstrumentResponseMocks from './__mocks__/relatedCollections.graphDbPlatformInstrument.response.mocks'
@@ -168,7 +168,7 @@ describe('graphDb', () => {
168168
})
169169
.reply(200, relatedCollectionsRelatedUrlTypeGraphdbResponseMocks)
170170

171-
const response = await graphDbDatasource(
171+
const response = await graphDbRelatedCollectionsDatasource(
172172
{ conceptId: 'C100000-EDSC' },
173173
{
174174
limit: 1,
@@ -207,7 +207,7 @@ describe('graphDb', () => {
207207
})
208208
.reply(200, relatedCollectionsRelatedUrlSubtypeGraphdbResponseMocks)
209209

210-
const response = await graphDbDatasource(
210+
const response = await graphDbRelatedCollectionsDatasource(
211211
{ conceptId: 'C100000-EDSC' },
212212
{
213213
limit: 1,
@@ -251,7 +251,7 @@ describe('graphDb', () => {
251251
})
252252
.reply(200, relatedCollectionsRelatedUrlTypeAndSubtypeGraphdbResponseMocks)
253253

254-
const response = await graphDbDatasource(
254+
const response = await graphDbRelatedCollectionsDatasource(
255255
{ conceptId: 'C100000-EDSC' },
256256
{
257257
limit: 1,
@@ -354,7 +354,7 @@ describe('graphDb', () => {
354354
})
355355
.reply(200, relatedCollectionsGraphDbProjectGraphdbResponseMocks)
356356

357-
const response = await graphDbDatasource(
357+
const response = await graphDbRelatedCollectionsDatasource(
358358
{ conceptId: 'C100000-EDSC' },
359359
{
360360
limit: 1
@@ -459,7 +459,7 @@ describe('graphDb', () => {
459459
})
460460
.reply(200, relatedCollectionsGraphDbPlatformInstrumentGraphdbResponseMocks)
461461

462-
const response = await graphDbDatasource(
462+
const response = await graphDbRelatedCollectionsDatasource(
463463
{ conceptId: 'C100000-EDSC' },
464464
{
465465
limit: 1
@@ -576,7 +576,7 @@ describe('graphDb', () => {
576576
})
577577
.reply(200, relatedCollectionsGraphDbRelatedUrlGraphdbResponseMocks)
578578

579-
const response = await graphDbDatasource(
579+
const response = await graphDbRelatedCollectionsDatasource(
580580
{ conceptId: 'C100000-EDSC' },
581581
{
582582
limit: 1
@@ -696,7 +696,7 @@ describe('graphDb', () => {
696696
})
697697
.reply(200, relatedCollectionsGraphDbRelatedUrlGraphdbResponseMocks)
698698

699-
const response = await graphDbDatasource(
699+
const response = await graphDbRelatedCollectionsDatasource(
700700
{ conceptId: 'C100000-EDSC' },
701701
{
702702
limit: 1,
@@ -827,7 +827,7 @@ describe('graphDb', () => {
827827
})
828828
.reply(200, relatedCollectionsGraphDbRelatedUrlProjectGraphdbResponseMocks)
829829

830-
const response = await graphDbDatasource(
830+
const response = await graphDbRelatedCollectionsDatasource(
831831
{ conceptId: 'C100000-EDSC' },
832832
{
833833
limit: 1,
@@ -957,7 +957,7 @@ describe('graphDb', () => {
957957
})
958958
.reply(200, relatedCollectionsGraphDbRelatedUrlRelationshipTypeGraphdbResponseMocks)
959959

960-
const response = await graphDbDatasource(
960+
const response = await graphDbRelatedCollectionsDatasource(
961961
{ conceptId: 'C100000-EDSC' },
962962
{
963963
limit: 1,
@@ -1063,7 +1063,7 @@ describe('graphDb', () => {
10631063
})
10641064
.reply(200, relatedCollectionsGraphDbCitationGraphdbResponseMocks)
10651065

1066-
const response = await graphDbDatasource(
1066+
const response = await graphDbRelatedCollectionsDatasource(
10671067
{ conceptId: 'C100000-EDSC' },
10681068
{
10691069
limit: 1
@@ -1174,7 +1174,7 @@ describe('graphDb', () => {
11741174
})
11751175
.reply(200, relatedCollectionsGraphDbScienceKeywordGraphdbResponseMocks)
11761176

1177-
const response = await graphDbDatasource(
1177+
const response = await graphDbRelatedCollectionsDatasource(
11781178
{ conceptId: 'C100000-EDSC' },
11791179
{
11801180
limit: 1
@@ -1305,7 +1305,7 @@ describe('graphDb', () => {
13051305
})
13061306
.reply(200, relatedCollectionsGraphDbRelatedUrlCitationGraphdbResponseMocks)
13071307

1308-
const response = await graphDbDatasource(
1308+
const response = await graphDbRelatedCollectionsDatasource(
13091309
{ conceptId: 'C100000-EDSC' },
13101310
{
13111311
limit: 1
@@ -1403,7 +1403,7 @@ describe('graphDb', () => {
14031403
})
14041404
.reply(200, relatedCollectionsRelationshipTypeGraphdbResponseMocks)
14051405

1406-
const response = await graphDbDatasource(
1406+
const response = await graphDbRelatedCollectionsDatasource(
14071407
{ conceptId: 'C100000-EDSC' },
14081408
{
14091409
limit: 1
@@ -1480,7 +1480,7 @@ describe('graphDb', () => {
14801480
})
14811481
.reply(200, relatedCollectionsNoRelationshipsGraphDbResponseMock)
14821482

1483-
const response = await graphDbDatasource(
1483+
const response = await graphDbRelatedCollectionsDatasource(
14841484
{ conceptId: 'C100000-EDSC' },
14851485
{
14861486
limit: 1
@@ -1500,8 +1500,8 @@ describe('graphDb', () => {
15001500
})
15011501
})
15021502

1503-
describe('Testing permitted groups on related collections', () => {
1504-
test('Testing that permitted groups is in the post request', async () => {
1503+
describe('When the related collections are behind permitted groups', () => {
1504+
test('Testing that permitted groups are in the gremlin request', async () => {
15051505
nock(/example-graphdb/)
15061506
.post('/', (body) => {
15071507
const parsedBody = typeof body === 'string' ? JSON.parse(body) : body
@@ -1539,7 +1539,7 @@ describe('graphDb', () => {
15391539
]
15401540
})
15411541

1542-
const response = await graphDbDatasource(
1542+
const response = await graphDbRelatedCollectionsDatasource(
15431543
{ conceptId: 'C100000-EDSC' },
15441544
{
15451545
limit: 1
@@ -1556,40 +1556,42 @@ describe('graphDb', () => {
15561556
expect(response).toEqual(relatedCollectionsRelationshipTypeResponseMocks)
15571557
})
15581558

1559-
test('Mocking the response for a client not being in any groups, and retrieving no related collections', async () => {
1560-
nock(/example-graphdb/)
1561-
.post('/', (body) => {
1562-
const parsedBody = typeof body === 'string' ? JSON.parse(body) : body
1563-
const gremlinQuery = parsedBody?.gremlin || ''
1559+
describe('when the user is in no groups', () => {
1560+
test('the response contains no related collections', async () => {
1561+
nock(/example-graphdb/)
1562+
.post('/', (body) => {
1563+
const parsedBody = typeof body === 'string' ? JSON.parse(body) : body
1564+
const gremlinQuery = parsedBody?.gremlin || ''
15641565

1565-
const hasCorrectPermittedGroups = gremlinQuery.includes('within(\'registered\',\'guest\')')
1566-
const hasOtherV = gremlinQuery.includes('.otherV()')
1566+
const hasCorrectPermittedGroups = gremlinQuery.includes('within(\'registered\',\'guest\')')
1567+
const hasOtherV = gremlinQuery.includes('.otherV()')
15671568

1568-
return hasCorrectPermittedGroups && hasOtherV
1569-
})
1570-
.reply(200, relatedCollectionsResponseEmptyMocks)
1569+
return hasCorrectPermittedGroups && hasOtherV
1570+
})
1571+
.reply(200, relatedCollectionsResponseEmptyMocks)
15711572

1572-
nock(/example-urs/)
1573-
.get(/groups_for_user/)
1574-
.reply(200, {})
1573+
nock(/example-urs/)
1574+
.get(/groups_for_user/)
1575+
.reply(200, {})
15751576

1576-
const response = await graphDbDatasource(
1577-
{ conceptId: 'C100000-EDSC' },
1578-
{
1579-
limit: 1
1580-
},
1581-
{
1582-
headers: {
1583-
'Client-Id': 'eed-test-graphql',
1584-
'CMR-Request-Id': 'abcd-1234-efgh-5678'
1577+
const response = await graphDbRelatedCollectionsDatasource(
1578+
{ conceptId: 'C100000-EDSC' },
1579+
{
1580+
limit: 1
15851581
},
1586-
edlUsername: 'someEdlUsername'
1587-
},
1588-
parsedInfo
1589-
)
1590-
expect(response).toEqual({
1591-
count: 0,
1592-
items: []
1582+
{
1583+
headers: {
1584+
'Client-Id': 'eed-test-graphql',
1585+
'CMR-Request-Id': 'abcd-1234-efgh-5678'
1586+
},
1587+
edlUsername: 'someEdlUsername'
1588+
},
1589+
parsedInfo
1590+
)
1591+
expect(response).toEqual({
1592+
count: 0,
1593+
items: []
1594+
})
15931595
})
15941596
})
15951597
})

src/datasources/graphDbDuplicateCollections.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default async (
2222

2323
const { doi: doiDescription } = doi || {}
2424

25-
// If doi or shorName don't exist, return 0 duplicateCollections
25+
// If doi or shortName don't exist, return 0 duplicateCollections
2626
if (!doiDescription || !shortName) {
2727
return {
2828
count: 0,

src/datasources/graphDb.js renamed to src/datasources/graphDbRelatedCollections.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,17 @@ export default async (
175175
headers,
176176
query
177177
})
178-
179178
const { result } = data
180179

181180
// Useful for debugging!
182181
// console.log('GraphDB query', JSON.parse(query))
183182
// console.log('GraphDB Response result: ', JSON.stringify(result, null, 2))
184183

185184
const { data: resultData } = result
186-
const { '@value': dataValues } = resultData
185+
const { '@value': dataValues = [] } = resultData
187186

188187
const collectionsList = []
189-
let totalRelatedCollectionsCount
188+
let totalRelatedCollectionsCount = 0
190189

191190
dataValues.forEach((dataValue) => {
192191
const { '@value': dataValueMap } = dataValue
@@ -288,7 +287,6 @@ export default async (
288287
count: totalRelatedCollectionsCount,
289288
items: collectionsList
290289
}
291-
292290
// Useful for debugging!
293291
// console.log('graphDb.js response', JSON.stringify(returnObject, null, 2))
294292

src/graphql/handler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import dataQualitySummarySource from '../datasources/dataQualitySummary'
3737
import granuleSource from '../datasources/granule'
3838
import graphDbAssociatedCitations from '../datasources/graphDbAssociatedCitations'
3939
import graphDbDuplicateCollectionsSource from '../datasources/graphDbDuplicateCollections'
40-
import graphDbSource from '../datasources/graphDb'
40+
import graphDbRelatedCollectionsSource from '../datasources/graphDbRelatedCollections'
4141
import gridSource from '../datasources/grid'
4242
import maxItemsPerOrderSource from '../datasources/maxItemsPerOrder'
4343
import permissionSource from '../datasources/permission'
@@ -249,7 +249,7 @@ export default startServerAndCreateLambdaHandler(
249249
granuleSource,
250250
graphDbAssociatedCitations,
251251
graphDbDuplicateCollectionsSource,
252-
graphDbSource,
252+
graphDbRelatedCollectionsSource,
253253
gridSource,
254254
groupSourceCreate,
255255
groupSourceDelete,

src/resolvers/__tests__/__mocks__/mockServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import dataQualitySummarySource from '../../../datasources/dataQualitySummary'
2020
import granuleSource from '../../../datasources/granule'
2121
import graphDbAssociatedCitations from '../../../datasources/graphDbAssociatedCitations'
2222
import graphDbDuplicateCollectionsSource from '../../../datasources/graphDbDuplicateCollections'
23-
import graphDbSource from '../../../datasources/graphDb'
23+
import graphDbRelatedCollectionsSource from '../../../datasources/graphDbRelatedCollections'
2424
import gridSource from '../../../datasources/grid'
2525
import maxItemsPerOrderSource from '../../../datasources/maxItemsPerOrder'
2626
import permissionSource from '../../../datasources/permission'
@@ -122,7 +122,7 @@ export const buildContextValue = (extraContext) => ({
122122
granuleSource,
123123
graphDbAssociatedCitations,
124124
graphDbDuplicateCollectionsSource,
125-
graphDbSource,
125+
graphDbRelatedCollectionsSource,
126126
gridSource,
127127
groupSourceCreate,
128128
groupSourceDelete,

0 commit comments

Comments
 (0)