gradido/backend/src/federation/client/GraphQLGetClient.ts
Claus-Peter Hübner ffe83a5d94 rework PR-comments
2023-02-07 22:19:14 +01:00

36 lines
1.0 KiB
TypeScript

import { GraphQLClient } from 'graphql-request'
import { PatchedRequestInit } from 'graphql-request/dist/types'
export class GraphQLGetClient extends GraphQLClient {
private static instance: GraphQLGetClient
/**
* The Singleton's constructor should always be private to prevent direct
* construction calls with the `new` operator.
*/
// eslint-disable-next-line no-useless-constructor
private constructor(url: string, options?: PatchedRequestInit) {
super(url, options)
}
/**
* The static method that controls the access to the singleton instance.
*
* This implementation let you subclass the Singleton class while keeping
* just one instance of each subclass around.
*/
public static getInstance(url: string): GraphQLGetClient {
if (!GraphQLGetClient.instance) {
GraphQLGetClient.instance = new GraphQLGetClient(url, {
method: 'GET',
jsonSerializer: {
parse: JSON.parse,
stringify: JSON.stringify,
},
})
}
return GraphQLGetClient.instance
}
}