-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add clients UI, federation validation error logging (#148)
* add clients UI, federation validation error logging * remove clientVersions resolver & db fn as thats not used add integration test for client resolver
- Loading branch information
Showing
13 changed files
with
295 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// eslint-disable-next-line | ||
import React from 'react'; | ||
import { useQuery } from '@apollo/client'; | ||
|
||
import PersistedQuery from '../persisted-queries/PersistedQuery'; | ||
import SpinnerCenter from '../components/SpinnerCenter'; | ||
import { CLIENT_VERSION_PERSISTED_QUERIES } from '../utils/queries'; | ||
|
||
const ClientPersistedQueries = ({ selectedVersion }) => { | ||
if (!selectedVersion) { | ||
return null; | ||
} | ||
|
||
const { loading, data } = useQuery(CLIENT_VERSION_PERSISTED_QUERIES, { | ||
variables: { clientVersionId: selectedVersion }, | ||
}); | ||
|
||
if (loading) { | ||
return <SpinnerCenter />; | ||
} | ||
|
||
if (!data) { | ||
return <div style={{ padding: '10px' }}>No queries found</div>; | ||
} | ||
|
||
return ( | ||
<div style={{ padding: 10 }}> | ||
{data?.persistedQueries.length > 0 && ( | ||
<strong>Persisted Queries</strong> | ||
)} | ||
{data?.persistedQueries.map((pq) => { | ||
return ( | ||
<div key={pq.key}> | ||
<PersistedQuery key={pq.key} query={pq} /> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClientPersistedQueries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//eslint-disable-next-line | ||
import React, { useState } from 'react'; | ||
import { HashRouter as Router } from 'react-router-dom'; | ||
import { useQuery } from '@apollo/client'; | ||
import { List, ListItem, ListItemIcon, ListItemText } from '@material-ui/core'; | ||
import ChevronRightIcon from '@material-ui/icons/ChevronRight'; | ||
|
||
import SpinnerCenter from '../components/SpinnerCenter'; | ||
import { CLIENTS_LIST } from '../utils/queries'; | ||
import { ColumnPanel } from '../components/styled'; | ||
import ClientVersions from './versions'; | ||
import ClientPersistedQueries from './clientPersistedQueries'; | ||
|
||
export default function Clients() { | ||
const { loading, data } = useQuery(CLIENTS_LIST); | ||
|
||
const [selectedClient, setSelectedClient] = useState(null); | ||
const [selectedVersion, setSelectedVersion] = useState(null); | ||
|
||
if (loading) { | ||
return <SpinnerCenter />; | ||
} | ||
|
||
if (!data || data.clients.length === 0) { | ||
return <div style={{ padding: '10px' }}>No clients found</div>; | ||
} | ||
|
||
const clients = data.clients.map((client) => { | ||
return ( | ||
<ListItem | ||
selected={selectedClient === client.name} | ||
key={client.name} | ||
onClick={() => { | ||
setSelectedClient(client.name); | ||
}} | ||
> | ||
<ListItemText primary={client.name} /> | ||
<ListItemIcon> | ||
<ChevronRightIcon /> | ||
</ListItemIcon> | ||
</ListItem> | ||
); | ||
}); | ||
|
||
return ( | ||
<Router basename="/clients"> | ||
<div style={{ display: 'flex' }}> | ||
<List | ||
component="nav" | ||
style={{ borderRight: '1px solid #eeeeee' }} | ||
> | ||
{clients} | ||
</List> | ||
|
||
<ColumnPanel | ||
all="m" | ||
style={{ borderRight: '1px solid #eeeeee' }} | ||
> | ||
<ClientVersions | ||
clients={data.clients} | ||
selectedClient={selectedClient} | ||
selectedVersion={selectedVersion} | ||
setSelectedVersion={setSelectedVersion} | ||
/> | ||
</ColumnPanel> | ||
|
||
<div style={{ flexGrow: 1 }}> | ||
<ClientPersistedQueries selectedVersion={selectedVersion} /> | ||
</div> | ||
</div> | ||
</Router> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//eslint-disable-next-line | ||
import React from 'react'; | ||
import { formatDistance } from 'date-fns'; | ||
|
||
import { List, ListItem } from '@material-ui/core'; | ||
import { FlexRow, EntryGrid } from '../components/styled'; | ||
|
||
const Versions = ({ | ||
clients, | ||
selectedClient, | ||
selectedVersion, | ||
setSelectedVersion, | ||
}) => { | ||
let versions = null; | ||
|
||
if (!selectedClient) { | ||
return null; | ||
} | ||
|
||
clients.map((client) => { | ||
if (selectedClient === client.name && client.versions) { | ||
versions = client.versions.map((version) => ( | ||
<ListItem | ||
selected={selectedVersion === version.id} | ||
key={version.id} | ||
onClick={() => setSelectedVersion(version.id)} | ||
> | ||
<EntryGrid> | ||
<div style={{ cursor: 'pointer' }}> | ||
<FlexRow> | ||
<div>{version.version}</div> | ||
</FlexRow> | ||
<div> | ||
Updated{' '} | ||
{formatDistance( | ||
new Date(version.updatedTime), | ||
new Date(), | ||
{ | ||
addSuffix: true, | ||
} | ||
)} | ||
</div> | ||
</div> | ||
</EntryGrid> | ||
</ListItem> | ||
)); | ||
} | ||
}); | ||
|
||
if (!versions) { | ||
versions = <div>No versions found</div>; | ||
} | ||
|
||
return <List component="nav">{versions}</List>; | ||
}; | ||
|
||
export default Versions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ALTER TABLE `clients_persisted_queries_rel` ADD `added_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP AFTER `pq_key`; | ||
|
||
ALTER TABLE `clients_persisted_queries_rel` | ||
CHANGE `pq_key` `pq_key` VARCHAR(100) | ||
CHARACTER SET utf8mb4 | ||
COLLATE utf8mb4_general_ci NOT NULL DEFAULT ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import resolvers from './resolvers'; | ||
import { cleanTables } from '../../test/integration/database'; | ||
|
||
import clientsModel from '../database/clients'; | ||
|
||
describe('app/graphql', () => { | ||
beforeEach(async () => { | ||
await cleanTables(); | ||
}); | ||
|
||
describe('POST /graphql', () => { | ||
describe('Query { clients } ', () => { | ||
it('returns empty set', async () => { | ||
const result = await resolvers.Query.clients(); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('returns two clients', async () => { | ||
// ARRANGE | ||
clientsModel.add({ | ||
name: 'client_a', | ||
version: 'v1', | ||
persistedQueryHash: 'abc', | ||
}); | ||
clientsModel.add({ | ||
name: 'client_b', | ||
version: 'v2', | ||
persistedQueryHash: 'def', | ||
}); | ||
await clientsModel.syncUniqueClientsToDb(); | ||
|
||
// ACT | ||
const result = await resolvers.Query.clients(); | ||
|
||
// ASSERT | ||
expect(result).toEqual([ | ||
{ name: 'client_a' }, | ||
{ name: 'client_b' }, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.