diff --git a/.changeset/config.json b/.changeset/config.json index fdc459be6e19a..c250cde96edf5 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -5,7 +5,7 @@ "access": "restricted", "baseBranch": "master", "updateInternalDependencies": "patch", - "ignore": ["website"], + "ignore": ["website", "@graphql-mesh/container"], "changelog": ["@changesets/changelog-github", { "repo": "urigo/graphql-mesh" }], "snapshot": { "useCalculatedVersion": true, diff --git a/.changeset/smooth-rocks-retire.md b/.changeset/smooth-rocks-retire.md new file mode 100644 index 0000000000000..3924d72d9481c --- /dev/null +++ b/.changeset/smooth-rocks-retire.md @@ -0,0 +1,10 @@ +--- +'@graphql-mesh/apollo-link': patch +'@graphql-mesh/grpc': patch +'@omnigraph/json-schema': patch +'@graphql-mesh/plugin-newrelic': patch +'@graphql-mesh/string-interpolation': patch +'@graphql-mesh/types': patch +--- + +Fixes for ESM diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3749d85297043..0b288c4672cc8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,10 +34,7 @@ jobs: POSTGRES_PASSWORD: docker # Set health checks to wait until postgres has started options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 + --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: # Maps tcp port 5432 on service container to the host - 5432:5432 @@ -47,7 +44,9 @@ jobs: MYSQL_ROOT_PASSWORD: passwd ports: - 33306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + options: + --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s + --health-retries=3 steps: - name: Checkout @@ -67,7 +66,10 @@ jobs: ${{runner.os}}-${{matrix.node-version}}-jest- - name: Download Postgres Dump - run: 'curl https://raw.githubusercontent.com/morenoh149/postgresDBSamples/master/worldDB-1.0/world.sql -o /tmp/backup.sql' + run: + 'curl + https://raw.githubusercontent.com/morenoh149/postgresDBSamples/master/worldDB-1.0/world.sql + -o /tmp/backup.sql' - name: Load Postgres Data uses: tj-actions/pg-restore@v4.7 with: @@ -84,3 +86,5 @@ jobs: NODE_TLS_REJECT_UNAUTHORIZED: 0 GH_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} LC_ALL: en-US + - name: Node.js integrity check + run: yarn bob check diff --git a/.gitignore b/.gitignore index 4b8e91c0edc76..29078805a2ef0 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ package-lock.json /.husky/_/ newrelic-agent.log website/public/_redirects +packages/types/src/config-schema.ts diff --git a/package.json b/package.json index f11ba9b8dac95..bba852fa37c9e 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,10 @@ "clean": "rm -rf packages/**/dist packages/**/**/dist examples/**/node_modules/.bin/*mesh* .bob", "copy-config-schema": "cp ./packages/types/src/config-schema.json ./packages/types/dist/esm && cp ./packages/types/src/config-schema.json ./packages/types/dist/cjs", "fix-bin": "node scripts/fix-bin.js", - "generate-config-schema": "yarn graphql-to-config-schema --schema ./**/yaml-config.graphql --json ./packages/types/src/config-schema.json --typings ./packages/types/src/config.ts --markdown ./website/src/generated-markdown && npx prettier --write ./packages/types/src", + "generate-config-schema": "yarn graphql-to-config-schema --schema ./**/yaml-config.graphql --json ./packages/types/src/config-schema.json --typings ./packages/types/src/config.ts --markdown ./website/src/generated-markdown", "lint": "eslint --ext .ts \"./packages/**/src/**/*.ts\"", "postbuild": "yarn copy-config-schema && yarn fix-bin", + "postgenerate-config-schema": "node scripts/create-config-schema-ts.js && npx prettier --write ./packages/types/src", "postinstall": "patch-package && husky install", "prebuild": "yarn clean && yarn generate-config-schema", "prebuild:website": "yarn build", diff --git a/packages/apollo-link/package.json b/packages/apollo-link/package.json index 4bd4562a14401..6692f97af02d8 100644 --- a/packages/apollo-link/package.json +++ b/packages/apollo-link/package.json @@ -45,6 +45,9 @@ "directory": "dist" }, "sideEffects": false, + "bob": { + "check": false + }, "typescript": { "definition": "dist/typings/index.d.ts" } diff --git a/packages/container/package.json b/packages/container/package.json index aca9c7a8cb1e4..e13d925f230cf 100644 --- a/packages/container/package.json +++ b/packages/container/package.json @@ -8,26 +8,6 @@ "directory": "packages/container" }, "license": "MIT", - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", - "exports": { - ".": { - "require": { - "types": "./dist/typings/index.d.cts", - "default": "./dist/cjs/index.js" - }, - "import": { - "types": "./dist/typings/index.d.ts", - "default": "./dist/esm/index.js" - }, - "default": { - "types": "./dist/typings/index.d.ts", - "default": "./dist/esm/index.js" - } - }, - "./package.json": "./package.json" - }, - "typings": "dist/typings/index.d.ts", "scripts": { "start": "graphql-mesh dev" }, @@ -53,11 +33,5 @@ "graphql": "16.6.0", "tslib": "2.4.1" }, - "publishConfig": { - "access": "public", - "directory": "dist" - }, - "typescript": { - "definition": "dist/typings/index.d.ts" - } + "bob": false } diff --git a/packages/handlers/grpc/src/index.ts b/packages/handlers/grpc/src/index.ts index 04f738740e6b0..0bdf30012db87 100644 --- a/packages/handlers/grpc/src/index.ts +++ b/packages/handlers/grpc/src/index.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-duplicates */ -import './patchLongJs'; +import './patchLongJs.js'; import { MeshHandlerOptions, Logger, MeshHandler, YamlConfig } from '@graphql-mesh/types'; import { stringInterpolator } from '@graphql-mesh/string-interpolation'; import { ChannelCredentials, credentials, loadPackageDefinition } from '@grpc/grpc-js'; @@ -18,7 +18,6 @@ import { AnyNestedObject, IParseOptions, Message, RootConstructor } from 'protob import protobufjs from 'protobufjs'; import grpcReflection from '@ardatan/grpc-reflection-js'; import { IFileDescriptorSet } from 'protobufjs/ext/descriptor'; -import { FileDescriptorSet } from 'protobufjs/ext/descriptor/index.js'; import descriptor from 'protobufjs/ext/descriptor/index.js'; import { addIncludePathResolver, addMetaDataToCall, getTypeName } from './utils.js'; @@ -57,7 +56,7 @@ export default class GrpcHandler implements MeshHandler { this.rootJsonAndDecodedDescriptorSets = store.proxy('descriptorSet.proto', { codify: rootJsonAndDecodedDescriptorSets => ` -import { FileDescriptorSet } from 'protobufjs/ext/descriptor/index.js'; +import descriptor from 'protobufjs/ext/descriptor/index.js'; export default [ ${rootJsonAndDecodedDescriptorSets @@ -65,7 +64,7 @@ ${rootJsonAndDecodedDescriptorSets ({ name, rootJson, decodedDescriptorSet }) => ` { name: ${JSON.stringify(name)}, - decodedDescriptorSet: FileDescriptorSet.fromObject(${JSON.stringify( + decodedDescriptorSet: descriptor.FileDescriptorSet.fromObject(${JSON.stringify( decodedDescriptorSet.toJSON(), null, 2, @@ -81,7 +80,7 @@ ${rootJsonAndDecodedDescriptorSets return jsonData.map(({ name, rootJson, decodedDescriptorSet }: any) => ({ name, rootJson, - decodedDescriptorSet: FileDescriptorSet.fromObject(decodedDescriptorSet), + decodedDescriptorSet: descriptor.FileDescriptorSet.fromObject(decodedDescriptorSet), })); }, toJSON: rootJsonAndDecodedDescriptorSets => { diff --git a/packages/loaders/json-schema/src/addExecutionLogicToComposer.ts b/packages/loaders/json-schema/src/addExecutionLogicToComposer.ts index 43a3b15350653..6e925ae6477f3 100644 --- a/packages/loaders/json-schema/src/addExecutionLogicToComposer.ts +++ b/packages/loaders/json-schema/src/addExecutionLogicToComposer.ts @@ -9,8 +9,8 @@ import { JSONSchemaLinkConfig, JSONSchemaOperationConfig, OperationHeadersConfiguration, -} from './types'; -import { getOperationMetadata, isPubSubOperationConfig } from './utils'; +} from './types.js'; +import { getOperationMetadata, isPubSubOperationConfig } from './utils.js'; import { IStringifyOptions } from 'qs'; import { getNamedType, GraphQLInt, GraphQLObjectType, GraphQLString } from 'graphql'; import { process } from '@graphql-mesh/cross-helpers'; diff --git a/packages/loaders/json-schema/src/addRootFieldResolver.ts b/packages/loaders/json-schema/src/addRootFieldResolver.ts index c7c532cb855de..fdda3dd88e4f6 100644 --- a/packages/loaders/json-schema/src/addRootFieldResolver.ts +++ b/packages/loaders/json-schema/src/addRootFieldResolver.ts @@ -13,9 +13,9 @@ import { } from 'graphql'; import lodashSet from 'lodash.set'; import urlJoin from 'url-join'; -import { resolveDataByUnionInputType } from './resolveDataByUnionInputType'; -import { HTTPMethod } from './types'; -import { isFileUpload } from './utils'; +import { resolveDataByUnionInputType } from './resolveDataByUnionInputType.js'; +import { HTTPMethod } from './types.js'; +import { isFileUpload } from './utils.js'; import { stringify as qsStringify, parse as qsParse, IStringifyOptions } from 'qs'; import { createGraphQLError, memoize1 } from '@graphql-tools/utils'; import { getHeadersObj } from '@graphql-mesh/utils'; diff --git a/packages/loaders/json-schema/src/directives.ts b/packages/loaders/json-schema/src/directives.ts index 1af7b243a24c0..e0364d072eed9 100644 --- a/packages/loaders/json-schema/src/directives.ts +++ b/packages/loaders/json-schema/src/directives.ts @@ -29,9 +29,9 @@ import { addHTTPRootFieldResolver, GlobalOptions, HTTPRootFieldResolverOpts, -} from './addRootFieldResolver'; -import { getTypeResolverFromOutputTCs } from './getTypeResolverFromOutputTCs'; -import { ObjMapScalar } from './scalars'; +} from './addRootFieldResolver.js'; +import { getTypeResolverFromOutputTCs } from './getTypeResolverFromOutputTCs.js'; +import { ObjMapScalar } from './scalars.js'; import { resolvers as scalarResolvers } from 'graphql-scalars'; export const LengthDirective = new GraphQLDirective({ diff --git a/packages/loaders/json-schema/src/getComposerFromJSONSchema.ts b/packages/loaders/json-schema/src/getComposerFromJSONSchema.ts index 486b1c68b2442..664cfaedeb6e6 100644 --- a/packages/loaders/json-schema/src/getComposerFromJSONSchema.ts +++ b/packages/loaders/json-schema/src/getComposerFromJSONSchema.ts @@ -65,7 +65,7 @@ import { ResolveRootDirective, ResolveRootFieldDirective, TypeScriptDirective, -} from './directives'; +} from './directives.js'; import { GraphQLFile, GraphQLVoid } from './scalars.js'; export interface TypeComposers { diff --git a/packages/plugins/newrelic/src/index.ts b/packages/plugins/newrelic/src/index.ts index 71c6540c9832d..731013bcc9163 100644 --- a/packages/plugins/newrelic/src/index.ts +++ b/packages/plugins/newrelic/src/index.ts @@ -2,18 +2,21 @@ import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types'; import { useNewRelic } from '@envelop/newrelic'; import { stringInterpolator } from '@graphql-mesh/string-interpolation'; import { process } from '@graphql-mesh/cross-helpers'; -import recordExternal from 'newrelic/lib/metrics/recorders/http_external'; -import NAMES from 'newrelic/lib/metrics/names'; -import cat from 'newrelic/lib/util/cat'; +import recordExternal from 'newrelic/lib/metrics/recorders/http_external.js'; +import NAMES from 'newrelic/lib/metrics/names.js'; +import cat from 'newrelic/lib/util/cat.js'; import { getHeadersObj } from '@graphql-mesh/utils'; -import { shim as instrumentationApi } from 'newrelic'; +import newRelic from 'newrelic'; const EnvelopAttributeName = 'Envelop_NewRelic_Plugin'; -export default function useMeshNewrelic(options: MeshPluginOptions): MeshPlugin { +export default function useMeshNewrelic( + options: MeshPluginOptions, +): MeshPlugin { + const instrumentationApi = newRelic?.shim; if (!instrumentationApi?.agent) { options.logger.error( - 'Agent unavailable. Please check your New Relic Agent configuration and ensure New Relic is enabled.' + 'Agent unavailable. Please check your New Relic Agent configuration and ensure New Relic is enabled.', ); return {}; } @@ -38,11 +41,12 @@ export default function useMeshNewrelic(options: MeshPluginOptions (val.indexOf(sym) > 0 ? this.removeAfter(val, sym) : val), match) + removeReservedSymbols.reduce( + (val, sym) => (val.indexOf(sym) > 0 ? this.removeAfter(val, sym) : val), + match, + ), ); } removeDelimiter(val) { - return val.replace(new RegExp(this.delimiterStart(), 'g'), '').replace(new RegExp(this.delimiterEnd(), 'g'), ''); + return val + .replace(new RegExp(this.delimiterStart(), 'g'), '') + .replace(new RegExp(this.delimiterEnd(), 'g'), ''); } removeAfter(str, val) { @@ -121,7 +128,10 @@ export class Interpolator { if (dataToReplace) { return str.replace(rule.replace, this.applyModifiers(rule.modifiers, dataToReplace, data)); } else if (rule.alternativeText) { - return str.replace(rule.replace, this.applyModifiers(rule.modifiers, rule.alternativeText, data)); + return str.replace( + rule.replace, + this.applyModifiers(rule.modifiers, rule.alternativeText, data), + ); } const defaultModifier = this.applyModifiers(rule.modifiers, rule.key, data); @@ -158,7 +168,10 @@ export class Interpolator { applyModifiers(modifiers, str, rawData) { try { const transformers = modifiers.map(modifier => modifier && modifier.transform); - return transformers.reduce((str, transform) => (transform ? transform(str, rawData) : str), str); + return transformers.reduce( + (str, transform) => (transform ? transform(str, rawData) : str), + str, + ); } catch (e) { console.error(`An error occurred while applying modifiers to ${str}`, modifiers, e); return str; diff --git a/packages/string-interpolation/src/modifiers/index.js b/packages/string-interpolation/src/modifiers/index.js index 2d979cb592982..86013b71f819b 100644 --- a/packages/string-interpolation/src/modifiers/index.js +++ b/packages/string-interpolation/src/modifiers/index.js @@ -1,6 +1,6 @@ -import { uppercase } from './uppercase'; -import { lowercase } from './lowercase'; -import { titlecase } from './title'; +import { uppercase } from './uppercase.js'; +import { lowercase } from './lowercase.js'; +import { titlecase } from './title.js'; export const defaultModifiers = [ { diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 14fa11ce201d9..2031134bb2aed 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -11,12 +11,11 @@ import { } from '@graphql-tools/delegate'; import { TypedDocumentNode } from '@graphql-typed-document-node/core'; import { MeshStore } from '@graphql-mesh/store'; -import configSchema from './config-schema.json'; import type { Plugin } from '@envelop/core'; import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue'; import { BatchDelegateOptions } from '@graphql-tools/batch-delegate'; -export const jsonSchema: any = configSchema; +export { jsonSchema } from './config-schema.js'; export { YamlConfig }; diff --git a/scripts/create-config-schema-ts.js b/scripts/create-config-schema-ts.js new file mode 100644 index 0000000000000..89f0f8fd0d184 --- /dev/null +++ b/scripts/create-config-schema-ts.js @@ -0,0 +1,11 @@ +const { readFileSync, writeFileSync } = require('fs-extra'); + +const { join } = require('path'); + +const absoluteConfigSchemaPath = join(__dirname, '../packages/types/src/config-schema.json'); +const absoluteConfigSchemaTsPath = join(__dirname, '../packages/types/src/config-schema.ts'); + +const configSchemaStr = readFileSync(absoluteConfigSchemaPath, 'utf-8'); +const configSchemaTs = `export const jsonSchema: any = ${configSchemaStr} as any;`; + +writeFileSync(absoluteConfigSchemaTsPath, configSchemaTs);