Skip to content

Commit

Permalink
Fix generating logger import code and improve documentation (#7118)
Browse files Browse the repository at this point in the history
Co-authored-by: Denis Badurina <[email protected]>
  • Loading branch information
kamilkowalski and enisdenjo authored Jun 20, 2024
1 parent 41e73b9 commit 4c75671
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .changeset/orange-seas-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-mesh/config': patch
'@graphql-mesh/types': patch
---

`logger` configuration option only accepts a string
9 changes: 7 additions & 2 deletions packages/legacy/config/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,22 @@ export async function resolveLogger(
code: string;
logger: Logger;
}> {
if (typeof loggerConfig === 'string') {
if (loggerConfig) {
const { moduleName, resolved: logger } = await getPackage<Logger>({
name: loggerConfig,
type: 'logger',
importFn,
cwd,
additionalPrefixes: additionalPackagePrefixes,
});

const processedModuleName = moduleName.startsWith('.')
? path.join('..', moduleName)
: moduleName;

return {
logger,
importCode: `import logger from ${JSON.stringify(moduleName)};`,
importCode: `import logger from ${JSON.stringify(processedModuleName)};`,
code: '',
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy/config/yaml-config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type Query {
"""
persistedOperations: PersistedOperationsConfig
"""
Logger instance that matches `Console` interface of NodeJS
Path to a file exporting a logger instance compatible with the `Logger` type from `@graphql-mesh/types`
"""
logger: Any
logger: String
"""
Path to a custom W3 Compatible Fetch Implementation
"""
Expand Down
16 changes: 2 additions & 14 deletions packages/legacy/types/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4382,20 +4382,8 @@
"description": "Configure persisted operations options"
},
"logger": {
"anyOf": [
{
"type": "object",
"additionalProperties": true
},
{
"type": "string"
},
{
"type": "array",
"additionalItems": true
}
],
"description": "Logger instance that matches `Console` interface of NodeJS"
"type": "string",
"description": "Path to a file exporting a logger instance compatible with the `Logger` type from `@graphql-mesh/types`"
},
"customFetch": {
"anyOf": [
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export interface Config {
documents?: string[];
persistedOperations?: PersistedOperationsConfig;
/**
* Logger instance that matches `Console` interface of NodeJS
* Path to a file exporting a logger instance compatible with the `Logger` type from `@graphql-mesh/types`
*/
logger?: any;
logger?: string;
/**
* Path to a custom W3 Compatible Fetch Implementation
*/
Expand Down

0 comments on commit 4c75671

Please sign in to comment.