Skip to content

Commit

Permalink
fix(amplify-provider-awscloudformation): custom transformer imports (#…
Browse files Browse the repository at this point in the history
…3236)

* fix(amplify-provider-awscloudformation): custom transformer imports
* fix: transformer loading to use existing packages and use global prefix
  • Loading branch information
hirochachacha committed May 6, 2020
1 parent 3f6036b commit 7794d73
Show file tree
Hide file tree
Showing 8 changed files with 756 additions and 718 deletions.
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('./')) {
// 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.

0 comments on commit 7794d73

Please sign in to comment.