Skip to content

Commit

Permalink
Merge pull request #149 from dreamit-de/148-prom-fix
Browse files Browse the repository at this point in the history
148 Switch to graphql-server-base
  • Loading branch information
sgohlke authored Mar 17, 2023
2 parents fb69add + 1c52dd3 commit 4f228e1
Show file tree
Hide file tree
Showing 30 changed files with 60 additions and 157 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ TypeScript declarations are provided within the project.

## Compatibility

The following table shows which version of [graphql-js][1] library is compatible with which version of
`@dreamit/graphql-server`. As `@dreamit/graphql-server` defines [graphql-js][1] as peerDependency you might want to
choose a fitting version according to the [graphql-js][1] version used in your project and by other libraries depending
on [graphql-js][1].
The following table shows which version of [graphql-js][1] and [@sgohlke/graphql-server-base][12] are compatible with which version of
`@dreamit/graphql-server`. As `@dreamit/graphql-server` defines them as peerDependency you might want to
choose a fitting version used in your project and by other libraries depending
on them.

| graphql-js version | graphql-server version | Github branch | Development Status |
|--------------------|:----------------------:|:------------------------------------------------------------------------------------------:|:------------------:|
| ~~^15.2.0~~ | ~~1.x~~ | [~~legacy-graphql15~~](https://github.com/dreamit-de/graphql-server/tree/legacy-graphql15) | end of life |
| ^16.0.0 | 2.x | [legacy-server-v2](https://github.com/dreamit-de/graphql-server/tree/legacy-server-v2) | maintenance |
| ^16.0.0 | 3.x | [main](https://github.com/dreamit-de/graphql-server) | active |
| graphql-js version | graphql-server version | graphql-server-base version | Github branch | Development Status |
|--------------------|:----------------------:|:----------------------:|:------------------------------------------------------------------------------------------:|:------------------:|
| ~~^15.2.0~~ | ~~1.x~~ | ~~n.a.~~ | [~~legacy-graphql15~~](https://github.com/dreamit-de/graphql-server/tree/legacy-graphql15) | end of life |
| ^16.0.0 | 2.x | n.a. | [legacy-server-v2](https://github.com/dreamit-de/graphql-server/tree/legacy-server-v2) | maintenance |
| ^16.0.0 | 3.x | ^1.0 | [main](https://github.com/dreamit-de/graphql-server) | active |

## Features

Expand All @@ -31,7 +31,7 @@ on [graphql-js][1].
- Uses out-of-the-box default options to ease use and keep code short
- Provides hot reloading for schema and options
- Provides out-of-the-box metrics for GraphQLServer
- Uses only 2 peerDependencies: [graphql-js][1] version 16 and [graphql-prom-metrics][11] version 1 (no other production
- Uses only 3 peerDependencies: [graphql-js][1] version 16, [graphql-prom-metrics][11] version 1 and [graphql-server-base][12] (no other production
dependencies)

## Core Functions
Expand Down Expand Up @@ -196,7 +196,7 @@ from [graphql-prom-metrics][11]
**Warning!**:
If you are using **PromMetricsClient** you should avoid creating multiple **GraphQLServer** instances that all use
the **PromMetricsClient**. Because of the usage of a global object in the [prom-client][3] library this might result
in unexpected behaviour or malfunction. You can set another metrics client like **SimpleMetricsClient**
in unexpected behavior or malfunction. You can set another metrics client like **SimpleMetricsClient**
by calling **GraphQLServer setOptions()** or **GraphQLServer setMetricsClient()**.

The **SimpleMetricsClient** provides three custom metrics for the GraphQL server:
Expand Down Expand Up @@ -467,3 +467,5 @@ graphql-server is under [MIT-License](./LICENSE).
[10]: https://hapi.dev/

[11]: https://github.com/sgohlke/graphql-prom-metrics

[12]: https://github.com/sgohlke/graphql-server-base
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dreamit/graphql-server",
"version": "3.2.3",
"version": "3.3.0",
"description": "A GraphQL server written in NodeJS/Typescript.",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down Expand Up @@ -37,6 +37,7 @@
},
"peerDependencies": {
"graphql": "^16.0.0",
"@sgohlke/graphql-prom-metrics": "^1.0.2"
"@sgohlke/graphql-prom-metrics": "^1.0.2",
"@sgohlke/graphql-server-base": "^1.0.0"
}
}
2 changes: 1 addition & 1 deletion src/error/DetermineGraphQLOrFetchError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
FETCH_ERROR,
GRAPHQL_ERROR
} from '..'
} from '@sgohlke/graphql-server-base'

/**
* Determines if an error is a GraphQLError or
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
INTROSPECTION_DISABLED_ERROR,
VALIDATION_ERROR
} from '..'
} from '@sgohlke/graphql-server-base'

/**
* Determines if an error is a ValidationError or
Expand Down
9 changes: 0 additions & 9 deletions src/error/ErrorNameConstants.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/error/GraphQLErrorWithInfo.ts

This file was deleted.

9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,32 @@
* requests and send back appropriate responses.
*/
export * from './error/AggregateError'
export * from './error/ErrorNameConstants'
export * from './error/DetermineGraphQLOrFetchError'
export * from './error/DetermineValidationOrIntrospectionDisabledError'
export * from './error/GraphQLErrorWithInfo'
export * from './error/RemoveValidationRecommendationsFromErrors'

export * from './logger/JsonLogger'
export * from './logger/LogEntry'
export * from './logger/Logger'
export * from './logger/LogHelper'
export * from './logger/LogLevel'
export * from './logger/TextLogger'

export * from './metrics/DefaultMetricsClient'
export * from './metrics/IncreaseFetchOrGraphQLErrorMetric'
export * from './metrics/MetricsClient'
export * from './metrics/NoMetricsClient'
export * from './metrics/SimpleMetricsClient'

export * from './request/ContentType'
export * from './request/DefaultRequestInformationExtractor'
export * from './request/RequestInformationExtractor'
export * from './request/GraphQLServerRequest'
export * from './request/GraphQLRequestInfo'

export * from './response/DefaultResponseHandler'
export * from './response/GraphQLExecutionResult'
export * from './response/GraphQLServerResponse'
export * from './response/ResponseHandler'

export * from './server/DefaultGraphQLServerOptions'
export * from './server/GraphQLServer'
export * from './server/GraphQLServerOptions'

// For backwards-compatibility with graphql-server v3 versions and extensions
export * from '@sgohlke/graphql-server-base'
2 changes: 1 addition & 1 deletion src/logger/JsonLogger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Logger} from '@sgohlke/graphql-server-base'
import {Console} from 'node:console'
import {
Logger,
LogEntry,
LogHelper,
LogLevel
Expand Down
14 changes: 0 additions & 14 deletions src/logger/Logger.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/logger/TextLogger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Logger} from '@sgohlke/graphql-server-base'
import {
Logger,
LogLevel,
LogEntry,
LogHelper,
Expand Down
6 changes: 4 additions & 2 deletions src/metrics/IncreaseFetchOrGraphQLErrorMetric.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
Logger,
MetricsClient
} from '@sgohlke/graphql-server-base'
import {
determineGraphQLOrFetchError,
Logger,
MetricsClient
} from '..'

/**
Expand Down
30 changes: 0 additions & 30 deletions src/metrics/MetricsClient.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/metrics/NoMetricsClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { MetricsClient } from '..'
import { MetricsClient } from '@sgohlke/graphql-server-base'

/**
* Metrics client that does not collect any metrics.
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/SimpleMetricsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SCHEMA_VALIDATION_ERROR,
SYNTAX_ERROR,
VALIDATION_ERROR
} from '..'
} from '@sgohlke/graphql-server-base'

/**
* Simple metrics client.
Expand Down
7 changes: 1 addition & 6 deletions src/request/ContentType.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
export enum ContentType {
graphql = 'application/graphql',
json = 'application/json',
unknown = '',
urlencoded = 'application/x-www-form-urlencoded'
}
import { ContentType } from '@sgohlke/graphql-server-base'

export function getContentType(contentType?: string): ContentType {
if (contentType) {
Expand Down
8 changes: 5 additions & 3 deletions src/request/DefaultRequestInformationExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {
ContentType,
getContentType,
GraphQLRequestInfo,
GraphQLServerRequest,
RequestInformationExtractor
} from '..'
import {URLSearchParams} from 'node:url'
import {GraphQLError} from 'graphql'
import {Buffer} from 'node:buffer'
import {
ContentType,
GraphQLRequestInfo,
GraphQLServerRequest
} from '@sgohlke/graphql-server-base'

/**
* Default implementation of RequestInformationExtractor interface
Expand Down
8 changes: 0 additions & 8 deletions src/request/GraphQLRequestInfo.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/request/GraphQLServerRequest.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/request/RequestInformationExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
GraphQLRequestInfo,
GraphQLServerRequest
} from '..'
} from '@sgohlke/graphql-server-base'

/**
* Interface for RequestInformationExtractor.
Expand Down
2 changes: 1 addition & 1 deletion src/response/DefaultResponseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Buffer} from 'node:buffer'
import {
GraphQLExecutionResult,
ResponseHandler,
ResponseParameters
} from '..'
import {GraphQLError} from 'graphql'
import { GraphQLExecutionResult } from '@sgohlke/graphql-server-base'

/**
* Default implementation of ResponseHandler interface
Expand Down
16 changes: 1 addition & 15 deletions src/response/GraphQLExecutionResult.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import {
ExecutionResult,
GraphQLError
} from 'graphql'
import {GraphQLRequestInfo} from '..'

/**
* Interface for execution results.
* Contains the GraphQL related ExecutionResult as well as statusCode and customHeaders that might
* contain additional information for handling responses. The requestInformation is available
* to have both the result and request information in one interface, e.g. to use it for caching.
*/
export interface GraphQLExecutionResult {
executionResult: ExecutionResult
statusCode?: number
customHeaders?: Record<string, string>
requestInformation?: GraphQLRequestInfo
}
import {GraphQLExecutionResult} from '@sgohlke/graphql-server-base'

export function getFirstErrorFromExecutionResult(result: GraphQLExecutionResult)
: GraphQLError {
Expand Down
6 changes: 0 additions & 6 deletions src/response/GraphQLServerResponse.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/response/ResponseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
GraphQLServerRequest,
GraphQLServerResponse,
Logger
} from '..'
} from '@sgohlke/graphql-server-base'
import {
ExecutionResult,
GraphQLError,
Expand Down
12 changes: 7 additions & 5 deletions src/server/DefaultGraphQLServerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import {
GraphQLServerOptions,
DefaultRequestInformationExtractor,
TextLogger,
GraphQLServerRequest,
GraphQLServerResponse,
GraphQLRequestInfo,
Logger,
RequestInformationExtractor,
MetricsClient,
SimpleMetricsClient,
DefaultResponseHandler,
ResponseHandler
Expand All @@ -31,6 +26,13 @@ import {
GraphQLFieldResolver,
GraphQLTypeResolver
} from 'graphql/type/definition'
import {
GraphQLRequestInfo,
GraphQLServerRequest,
GraphQLServerResponse,
Logger,
MetricsClient
} from '@sgohlke/graphql-server-base'

export const fallbackTextLogger = new TextLogger('fallback-logger', 'fallback-service')
export const defaultRequestInformationExtractor = new DefaultRequestInformationExtractor()
Expand Down
Loading

0 comments on commit 4f228e1

Please sign in to comment.