mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
adapt client refactorings, v1_1 not matching
This commit is contained in:
parent
ce23bf6afd
commit
54173857ce
@ -1,91 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
|
||||
import { GraphQLError } from 'graphql/error/GraphQLError'
|
||||
import { gql } from 'graphql-request'
|
||||
|
||||
import { GraphQLGetClient } from '@/federation/client/GraphQLGetClient'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
// eslint-disable-next-line import/no-relative-parent-imports
|
||||
import { FederationClient, PublicCommunityInfo } from '../FederationClient'
|
||||
|
||||
export class FederationClientImpl implements FederationClient {
|
||||
public async requestGetPublicKey(dbCom: DbFederatedCommunity): Promise<string | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/`
|
||||
logger.info(`requestGetPublicKey with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = GraphQLGetClient.getInstance(endpoint)
|
||||
logger.debug(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const query = gql`
|
||||
query {
|
||||
getPublicKey {
|
||||
publicKey
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = {}
|
||||
|
||||
try {
|
||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(
|
||||
query,
|
||||
variables,
|
||||
)
|
||||
logger.debug(`Response-Data:`, data, errors, extensions, headers, status)
|
||||
if (data) {
|
||||
logger.debug(`Response-PublicKey:`, data.getPublicKey.publicKey)
|
||||
logger.info(`requestGetPublicKey processed successfully`)
|
||||
return data.getPublicKey.publicKey
|
||||
}
|
||||
logger.warn(`requestGetPublicKey processed without response data`)
|
||||
} catch (err) {
|
||||
if (err instanceof GraphQLError) {
|
||||
logger.error(`RawRequest-Error on {} with message {}`, endpoint, err.message)
|
||||
}
|
||||
throw new Error(`Request-Error in requestGetPublicKey.`)
|
||||
}
|
||||
}
|
||||
|
||||
public async requestGetPublicCommunityInfo(
|
||||
dbCom: DbFederatedCommunity,
|
||||
): Promise<PublicCommunityInfo | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/`
|
||||
logger.info(`requestGetPublicCommunityInfo with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = GraphQLGetClient.getInstance(endpoint)
|
||||
logger.debug(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const query = gql`
|
||||
query {
|
||||
getPublicCommunityInfo {
|
||||
name
|
||||
description
|
||||
createdAt
|
||||
publicKey
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = {}
|
||||
|
||||
try {
|
||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(
|
||||
query,
|
||||
variables,
|
||||
)
|
||||
logger.debug(`Response-Data:`, data, errors, extensions, headers, status)
|
||||
if (data) {
|
||||
logger.debug(`Response-PublicCommunityInfo:`, data.getPublicCommunityInfo)
|
||||
logger.info(`requestGetPublicCommunityInfo processed successfully`)
|
||||
return data.getPublicCommunityInfo
|
||||
}
|
||||
logger.warn(`requestGetPublicInfo processed without response data`)
|
||||
} catch (err) {
|
||||
if (err instanceof GraphQLError) {
|
||||
logger.error(`RawRequest-Error on {} with message {}`, endpoint, err.message)
|
||||
}
|
||||
throw new Error(`Request-Error in requestGetPublicCommunityInfo.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,94 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
|
||||
import { GraphQLError } from 'graphql/error/GraphQLError'
|
||||
import { gql } from 'graphql-request'
|
||||
|
||||
import { GraphQLGetClient } from '@/federation/client/GraphQLGetClient'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
// eslint-disable-next-line import/no-relative-parent-imports
|
||||
import { FederationClient, PublicCommunityInfo } from '../FederationClient'
|
||||
|
||||
export class FederationClientImpl implements FederationClient {
|
||||
async requestGetPublicKey(dbCom: DbFederatedCommunity): Promise<string | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/`
|
||||
logger.info(`requestGetPublicKey with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = GraphQLGetClient.getInstance(endpoint)
|
||||
logger.debug(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const query = gql`
|
||||
query {
|
||||
getPublicKey {
|
||||
publicKey
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = {}
|
||||
|
||||
try {
|
||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(
|
||||
query,
|
||||
variables,
|
||||
)
|
||||
logger.debug(`Response-Data:`, data, errors, extensions, headers, status)
|
||||
if (data) {
|
||||
logger.debug(`Response-PublicKey:`, data.getPublicKey.publicKey)
|
||||
logger.info(`requestGetPublicKey processed successfully`)
|
||||
return data.getPublicKey.publicKey
|
||||
}
|
||||
logger.warn(`requestGetPublicKey processed without response data`)
|
||||
} catch (err) {
|
||||
if (err instanceof GraphQLError) {
|
||||
logger.error(`RawRequest-Error on {} with message {}`, endpoint, err.message)
|
||||
}
|
||||
throw new Error(`Request-Error in requestGetPublicKey.`)
|
||||
}
|
||||
}
|
||||
|
||||
async requestGetPublicCommunityInfo(
|
||||
dbCom: DbFederatedCommunity,
|
||||
): Promise<PublicCommunityInfo | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/`
|
||||
logger.info(`requestGetPublicCommunityInfo with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = GraphQLGetClient.getInstance(endpoint)
|
||||
logger.debug(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const query = gql`
|
||||
query {
|
||||
getPublicCommunityInfo {
|
||||
name
|
||||
description
|
||||
createdAt
|
||||
publicKey
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = {}
|
||||
|
||||
try {
|
||||
const { data, errors, extensions, headers, status } = await graphQLClient.rawRequest(
|
||||
query,
|
||||
variables,
|
||||
)
|
||||
logger.debug(`Response-Data:`, data, errors, extensions, headers, status)
|
||||
if (data) {
|
||||
logger.debug(
|
||||
`Response-PublicCommunityInfo:`,
|
||||
data.getPublicCommunityInfo.publicCommunityInfo,
|
||||
)
|
||||
logger.info(`requestGetPublicInfo processed successfully`)
|
||||
return data.getPublicCommunityInfo.publicCommunityInfo
|
||||
}
|
||||
logger.warn(`requestGetPublicInfo processed without response data`)
|
||||
} catch (err) {
|
||||
if (err instanceof GraphQLError) {
|
||||
logger.error(`RawRequest-Error on {} with message {}`, endpoint, err.message)
|
||||
}
|
||||
throw new Error(`Request-Error in requestGetPublicCommunityInfo.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,47 @@
|
||||
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
|
||||
|
||||
import { getPublicCommunityInfo } from '@/federation/query/getPublicCommunityInfo'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
import { Client_1_0 } from './Client_1_0'
|
||||
|
||||
export interface PublicCommunityInfo {
|
||||
name: string
|
||||
description: string
|
||||
createdAt: Date
|
||||
publicKey: string
|
||||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
export class Client_1_1 extends Client_1_0 {}
|
||||
export class Client_1_1 extends Client_1_0 {
|
||||
constructor(dbCom: DbFederatedCommunity) {
|
||||
super(dbCom)
|
||||
}
|
||||
|
||||
getPublicCommunityInfo = async (): Promise<PublicCommunityInfo | undefined> => {
|
||||
logger.info(`getPublicCommunityInfo with endpoint='${this.endpoint}'...`)
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const { data } = await this.client.rawRequest(getPublicCommunityInfo, {})
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (!data?.getPublicCommunityInfo?.name) {
|
||||
logger.warn(
|
||||
'Federation: getPublicCommunityInfo without response data from endpoint',
|
||||
this.endpoint,
|
||||
)
|
||||
return
|
||||
}
|
||||
logger.info(
|
||||
'Federation: getPublicCommunityInfo successful from endpoint',
|
||||
this.endpoint,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
data.getPublicCommunityInfo,
|
||||
)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
|
||||
return data.getPublicCommunityInfo
|
||||
} catch (err) {
|
||||
logger.warn('Federation: getPublicCommunityInfo failed for endpoint', this.endpoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
|
||||
|
||||
export type PublicCommunityInfo = {
|
||||
name: string
|
||||
description: string
|
||||
createdAt: Date
|
||||
publicKey: string
|
||||
}
|
||||
|
||||
export interface FederationClient {
|
||||
requestGetPublicKey(dbCom: DbFederatedCommunity): Promise<string | undefined>
|
||||
requestGetPublicCommunityInfo(
|
||||
dbCom: DbFederatedCommunity,
|
||||
): Promise<PublicCommunityInfo | undefined>
|
||||
}
|
||||
12
backend/src/federation/query/getPublicCommunityInfo.ts
Normal file
12
backend/src/federation/query/getPublicCommunityInfo.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { gql } from 'graphql-request'
|
||||
|
||||
export const getPublicCommunityInfo = gql`
|
||||
query {
|
||||
getPublicCommunityInfo {
|
||||
name
|
||||
description
|
||||
createdAt
|
||||
publicKey
|
||||
}
|
||||
}
|
||||
`
|
||||
Loading…
x
Reference in New Issue
Block a user