-
Notifications
You must be signed in to change notification settings - Fork 25
Fed search cleanup typings #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b79999f
435e5e3
6448fab
6eea8e0
5a2280f
a69f9d1
c0a45cb
5d9a4df
dd9e463
15eed70
2c98afc
9a7aea5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ type QueryVariables = { | |
| */ | ||
| const fetchData = async <SuccessType>( | ||
| query: NetworkQuery, | ||
| ): Promise<Result<SuccessType, typeof CONNECTION_STATUS.error>> => { | ||
| ): Promise<Result<SuccessType, typeof CONNECTION_STATUS.ERROR>> => { | ||
| const { url, gqlQuery, queryVariables } = query; | ||
|
|
||
| console.log(`Fetch data starting for ${url}`); | ||
|
|
@@ -45,10 +45,12 @@ const fetchData = async <SuccessType>( | |
| // axios response "data" field, graphql response "data" field | ||
| const responseData = response.data?.data; | ||
| if (response.status === 200 && response.statusText === 'OK') { | ||
| console.log(`Fetch data completing for ${query.url}`); | ||
| return success(responseData); | ||
| } | ||
| } catch (error) { | ||
| if (axios.isCancel(error)) { | ||
| console.log(`Fetch data cancelled for ${query.url}`); | ||
| return failure(CONNECTION_STATUS.ERROR, `Request cancelled: ${url}`); | ||
| } | ||
|
|
||
|
|
@@ -61,9 +63,9 @@ const fetchData = async <SuccessType>( | |
| } | ||
| } | ||
| return failure(CONNECTION_STATUS.ERROR, `Unknown error`); | ||
| } finally { | ||
| console.log(`Fetch data completing for ${query.url}`); | ||
| } | ||
| // TS would like a return value outside of try/catch handling | ||
| return failure(CONNECTION_STATUS.ERROR, `Unknown error`); | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -129,12 +131,12 @@ export const createNodeQueryString = ( | |
| * | ||
| * @param config | ||
| * @param requestedFields | ||
| * @returns | ||
| * @returns a GQL document node or undefined if a valid GQL document node cannot be created | ||
| */ | ||
| export const createNetworkQuery = ( | ||
| config: NodeConfig, | ||
| requestedFields: RequestedFieldsMap, | ||
| ): DocumentNode => { | ||
| ): DocumentNode | undefined => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this may return undefined, and this funciton is exported for use by other modules, it would be good to include a description in the TSDoc about when this will return |
||
| const availableFields = config.aggregations; | ||
| const documentName = config.documentName; | ||
|
|
||
|
|
@@ -161,6 +163,7 @@ export const createNetworkQuery = ( | |
| return gqlQuery; | ||
| } catch (err) { | ||
| console.error('invalid gql', err); | ||
| return undefined; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS doesn't like implicit undefined |
||
| } | ||
| }; | ||
|
|
||
|
|
@@ -184,11 +187,13 @@ export const aggregationPipeline = async ( | |
|
|
||
| const aggregationResultPromises = configs.map(async (config) => { | ||
| const gqlQuery = createNetworkQuery(config, requestedAggregationFields); | ||
| const response = await fetchData<SuccessResponse>({ | ||
| url: config.graphqlUrl, | ||
| gqlQuery, | ||
| queryVariables, | ||
| }); | ||
| const response = gqlQuery | ||
| ? await fetchData<SuccessResponse>({ | ||
| url: config.graphqlUrl, | ||
| gqlQuery, | ||
| queryVariables, | ||
| }) | ||
| : failure(CONNECTION_STATUS.ERROR, 'Invalid GQL query'); | ||
|
|
||
| const nodeName = config.displayName; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| import { AllAggregations } from '../types/types'; | ||
| import { NetworkNode } from './networkNode'; | ||
|
|
||
| /** | ||
| * Format response object to match gql type defs | ||
| * Format response object to match GQL type defs | ||
| */ | ||
| export const createResponse = ({ aggregationResults, nodeInfo }) => { | ||
| export const createResponse = ({ | ||
| aggregationResults, | ||
| nodeInfo, | ||
| }: { | ||
| aggregationResults: AllAggregations; | ||
| nodeInfo: NetworkNode[]; | ||
| }) => { | ||
| return { remoteConnections: nodeInfo, aggregations: aggregationResults }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,7 @@ | ||
| import { mergeTypeDefs } from '@graphql-tools/merge'; | ||
| import { SupportedNetworkFieldType } from '../types/types'; | ||
| import { createNetworkAggregationTypeDefs } from './aggregations'; | ||
| import { remoteConnectionTypes } from './remoteConnections'; | ||
|
|
||
| export const createTypeDefs = (networkFieldTypes: SupportedNetworkFieldType[]) => { | ||
| const aggregationTypes = createNetworkAggregationTypeDefs(networkFieldTypes); | ||
| const typeDefs = mergeTypeDefs([remoteConnectionTypes, aggregationTypes]); | ||
| const typeDefs = createNetworkAggregationTypeDefs(networkFieldTypes); | ||
| return typeDefs; | ||
| }; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though results are handled in the
try/catchblock, TS doesn't like the implicit undefined from the function.It is a tsconfig setting, but I think it's best to return something rather than tweak the project setting.
TS also doesn't like nothing returned in a
finallyblock, and returning something here would override the returned values in thecatchblock