Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amplify-provider-awscloudformation): custom transformer imports #3236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createServer, Server } from 'http';
import { URL, URLSearchParams } from 'url';
import WS from 'ws';
import portFinder from 'portfinder';
import { PubSub } from 'graphql-subscriptions';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { URLSearchParams } from 'url';
import { decodeHeaderFromQueryParam } from '../../../../../server/subscription/websocket-server/utils/decode-header';

describe('decodeHeaderFromQueryParam', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('runQueryAndMutation', () => {
});

it('should run subscription resolver to ensure auth checks', async () => {
const name = 'John Doe';
const doc = parse(/* GraphQL */ `
subscription onSetName {
onSetName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'url';
import { parse, URLSearchParams } from 'url';
export function decodeHeaderFromQueryParam(rawUrl: string, paramName: string = 'header'): Record<string, any> {
const url = parse(rawUrl);
const params = new URLSearchParams(url.query);
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-appsync-simulator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"esModuleInterop": true,
"sourceMap": true,
"outDir": "lib",
"lib": ["dom", "es2015", "es2016.array.include", "esnext.asynciterable"],
"lib": ["es2015", "es2016.array.include", "esnext.asynciterable"],
"declaration": true
},
"exclude": ["node_modules", "lib"]
"exclude": ["node_modules", "lib", "**/__mocks__/**/*", "**/__tests__/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const inquirer = require('inquirer');
const importGlobal = require('import-global');
const importFrom = require('import-from');
const { DynamoDBModelTransformer } = require('graphql-dynamodb-transformer');
const { ModelAuthTransformer } = require('graphql-auth-transformer');
const { ModelConnectionTransformer } = require('graphql-connection-transformer');
Expand Down Expand Up @@ -86,26 +88,17 @@ function getTransformerFactory(context, resourceDir, authConfig) {
importedModule = require(modulePath);
} else {
const projectRootPath = context.amplify.pathManager.searchProjectRootPath();
const { createRequireFromPath } = require('module');
const projectRequire = createRequireFromPath(projectRootPath);

if (tempModulePath.startsWith('./')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that there is no concept like global require and local require.
module.paths is calculated by caller's path and NODE_PATH.
https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package

// Lookup 'locally' within project's node_modules with require mechanism
importedModule = projectRequire(tempModulePath);
} else {
const prefixedModuleName = `./${tempModulePath}`;

try {
// Lookup 'locally' within project's node_modules with require mechanism
importedModule = projectRequire(prefixedModuleName);
} catch (_) {
// Intentionally left blank to try global
}

if (!importedModule) {
// Lookup in global with require
importedModule = require(tempModulePath);
}
const projectNodeModules = path.join(projectRootPath, 'node_modules');

try {
importedModule = importFrom(projectNodeModules, modulePath);
} catch (_) {
// Intentionally left blank to try global
}

// Try global package install
if (!importedModule) {
importedModule = importGlobal(modulePath);
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-provider-awscloudformation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"graphql-predictions-transformer": "2.3.3",
"graphql-transformer-core": "6.17.0",
"graphql-versioned-transformer": "4.15.3",
"import-from": "^3.0.0",
"import-global": "^0.1.0",
"ini": "^1.3.5",
"inquirer": "^7.0.3",
"lodash": "^4.17.15",
Expand Down
1,430 changes: 735 additions & 695 deletions yarn.lock

Large diffs are not rendered by default.