2.1.2 • Published 1 year ago

@sgohlke/graphql-server-base v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

graphql-server-base

Base package for @dreamit/graphql-server. Contains constants and interfaces that can be used in graphql-server and extensions.

Installation

npm install --save @sgohlke/graphql-server-base

TypeScript declarations are provided within the project.

Note:

If you want to publish your own extension it is advised to install @sgohlke/graphql-server-base as peerDependency. This way you can define which version range your extension supports and it might be usable in multiple major versions of @dreamit/graphql-server (if they depend on the same range of this base module). Example in package.json for peerDependencies:

"peerDependencies": {
    "@sgohlke/graphql-server-base": "^1.0.0"
  }

Compatibility

@sgohlke/graphql-server-base is compatible with graphql-js version ^16.0.0. For compatibility with @dreamit/graphql-server please check Compatibility section in the graphql-server readme.

Content of this base module

All content of this module is exported in the root index.ts file. This means you can import it using an import statement like

import {MetricsClient} from '@sgohlke/graphql-server-base'

Constants

In error/ErrorNameConstants.ts constants to identify/display errors are provided. In request/ContentType.ts the content type used by @dreamit/graphql-server is available as enum.

Interfaces

Interfaces for creating your own Logger or MetricsClient are available in this module. Additionally, the interfaces used by @dreamit/graphql-server for handling requests and responses are provided.

Example

The following example shows how a NoLogger implementation of the Logger interface could be implemented.

import {Logger} from '@sgohlke/graphql-server-base'

/**
 * Logger implementation that does not log anything.
 */
export class NoLogger implements Logger {
    loggerName: string
    serviceName: string
    debugEnabled = false

    constructor(loggerName: string, serviceName: string, debugEnabled = false) {
        this.loggerName = loggerName
        this.serviceName = serviceName
        this.debugEnabled = debugEnabled
    }

    debug(logMessage: string, context?: unknown): void {}
    logDebugIfEnabled(message: string, context?: unknown): void {}
    error(logMessage: string,
        error: Error,
        customErrorName: string,
        context?: unknown): void {}
    info(logMessage: string, context?: unknown): void {}
    warn(logMessage: string, context?: unknown): void {}
}

Contact

If you have questions or issues please visit our Issue page and open a new issue if there are no fitting issues for your topic yet.

License

graphql-server is under MIT-License.

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago