Skip to content

Commit

Permalink
fix: pass appsync specific directives to model gen (aws-amplify#3211)
Browse files Browse the repository at this point in the history
AppSync service has some custom directives defined in the service. These directives are defiend in
transformer, so the documents that have them pass graphql validation. Passing them to model gen
plugin from transformer to keep these directives in sync
  • Loading branch information
yuth authored and Attila Hajdrik committed Jan 17, 2020
1 parent c855fbd commit c9a6ada
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Used for tests. Directive definition will be passed as part of the configuration
// Used only in tests. Directive definition will be passed as part of the configuration when modelgen is run using CLI
// TODO remove once prettier is upgraded
// prettier-ignore
export const directives = /* GraphQL */ `
Expand Down Expand Up @@ -123,7 +123,7 @@ export const directives = /* GraphQL */ `
search: String
}
directive @deprecated(reason: String!) on INPUT_FIELD_DEFINITION | ENUM
directive @deprecated(reason: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ENUM | ENUM_VALUE
`;

export const scalars = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
TRANSFORM_CONFIG_FILE_NAME,
TRANSFORM_BASE_VERSION,
CLOUDFORMATION_FILE_NAME,
getAppSyncServiceExtraDirectives,
} = TransformPackage;

const apiCategory = 'api';
Expand Down Expand Up @@ -488,9 +489,12 @@ async function getPreviousDeploymentRootKey(previouslyDeployedBackendDir) {

async function getDirectiveDefinitions(context, resourceDir) {
const transformList = await getTransformerFactory(context, resourceDir)(true);
return transformList
const appSynDirectives = getAppSyncServiceExtraDirectives();
const transformDirectives = transformList
.map(transformPluginInst => [transformPluginInst.directive, ...transformPluginInst.typeDefinitions].map(node => print(node)).join('\n'))
.join('\n');

return [appSynDirectives, transformDirectives].join('\n');
}
/**
* Check if storage exists in the project if not return undefined
Expand Down
9 changes: 9 additions & 0 deletions packages/graphql-transformer-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './polyfills/Object.assign';
import { print } from 'graphql';
import { TransformerContext } from './TransformerContext';
import { Transformer } from './Transformer';
import { ITransformer } from './ITransformer';
Expand All @@ -23,10 +24,18 @@ import {
TransformConfig,
SyncConfig,
} from './util/transformConfig';
import { EXTRA_DIRECTIVES_DOCUMENT } from './validation';

export * from './errors';
export * from './util';

/**
* Returns the extra set of directives that are supported by AppSync service
*/
export function getAppSyncServiceExtraDirectives(): string {
return print(EXTRA_DIRECTIVES_DOCUMENT);
}

export {
GraphQLTransform,
TransformConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-transformer-core/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ scalar BigInt
scalar Double
`);

const EXTRA_DIRECTIVES_DOCUMENT = parse(`
export const EXTRA_DIRECTIVES_DOCUMENT = parse(`
directive @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION
directive @aws_auth(cognito_groups: [String!]!) on FIELD_DEFINITION
directive @aws_api_key on FIELD_DEFINITION | OBJECT
Expand Down
71 changes: 14 additions & 57 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2989,11 +2989,6 @@
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-22.2.3.tgz#0157c0316dc3722c43a7b71de3fdf3acbccef10d"
integrity sha512-e74sM9W/4qqWB6D4TWV9FQk0WoHtX1X4FJpbjxucMSVJHtFjbQOH3H6yp+xno4br0AKG0wz/kPtaN599GUOvAg==

"@types/[email protected]":
version "23.1.0"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.0.tgz#8054dd838ba23dc331794d26456b86c7e50bf0f6"
integrity sha512-DlIvvYDpcFgM1Ny1uzUBGb+0UMejhPEzDGxJ2By75ndMVDa82OUzPlV+v6NOsjA7HRvB4oj/Jqsscv6eJvLxeQ==

"@types/[email protected]":
version "23.1.1"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.1.tgz#c54ab1a5f41aa693c0957222dd10414416d0c87b"
Expand Down Expand Up @@ -3023,6 +3018,13 @@
dependencies:
jest-diff "^24.3.0"

"@types/jest@^24.0.25":
version "24.9.0"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.9.0.tgz#78c6991cd1734cf0d390be24875e310bb0a9fb74"
integrity sha512-dXvuABY9nM1xgsXlOtLQXJKdacxZJd7AtvLsKZ/0b57ruMXDKCOXAC/M75GbllQX6o1pcZ5hAG4JzYy7Z/wM2w==
dependencies:
jest-diff "^24.3.0"

"@types/json-schema@^7.0.3":
version "7.0.4"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
Expand Down Expand Up @@ -6834,7 +6836,7 @@ [email protected], debug@=3.1.0:
dependencies:
ms "2.0.0"

[email protected], debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6:
[email protected], debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
Expand Down Expand Up @@ -6960,11 +6962,6 @@ deep-equal@^1.0.1, deep-equal@^1.1.1:
object-keys "^1.1.1"
regexp.prototype.flags "^1.2.0"

deep-extend@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==

deep-is@~0.1.2, deep-is@~0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
Expand Down Expand Up @@ -7117,11 +7114,6 @@ detect-indent@^5.0.0:
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d"
integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50=

detect-libc@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=

detect-newline@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-2.1.0.tgz#f41f1c10be4b00e87b5f13da680759f2c5bfd3e2"
Expand Down Expand Up @@ -10217,7 +10209,7 @@ husky@^3.0.3:
run-node "^1.0.0"
slash "^3.0.0"

[email protected], iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13:
[email protected], iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@~0.4.13:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
Expand Down Expand Up @@ -10413,7 +10405,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=

ini@^1.3.2, ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
ini@^1.3.2, ini@^1.3.4, ini@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
Expand Down Expand Up @@ -13728,15 +13720,6 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=

needle@^2.2.1:
version "2.4.0"
resolved "https://registry.yarnpkg.com/needle/-/needle-2.4.0.tgz#6833e74975c444642590e15a750288c5f939b57c"
integrity sha512-4Hnwzr3mi5L97hMYeNl8wRW/Onhy4nUKR/lVemJ8gJedxxUyBLm9kkrDColJvoSfwi0jCNhD+xCdOtiGDQiRZg==
dependencies:
debug "^3.2.6"
iconv-lite "^0.4.4"
sax "^1.2.4"

[email protected]:
version "0.6.2"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
Expand Down Expand Up @@ -13906,22 +13889,6 @@ node-notifier@^5.2.1, node-notifier@^5.4.2:
shellwords "^0.1.1"
which "^1.3.0"

node-pre-gyp@*:
version "0.14.0"
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz#9a0596533b877289bcad4e143982ca3d904ddc83"
integrity sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA==
dependencies:
detect-libc "^1.0.2"
mkdirp "^0.5.1"
needle "^2.2.1"
nopt "^4.0.1"
npm-packlist "^1.1.6"
npmlog "^4.0.2"
rc "^1.2.7"
rimraf "^2.6.1"
semver "^5.3.0"
tar "^4.4.2"

node-releases@^1.1.29, node-releases@^1.1.44:
version "1.1.45"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.45.tgz#4cf7e9175d71b1317f15ffd68ce63bce1d53e9f2"
Expand Down Expand Up @@ -14046,7 +14013,7 @@ npm-normalize-package-bin@^1.0.0, npm-normalize-package-bin@^1.0.1:
semver "^5.6.0"
validate-npm-package-name "^3.0.0"

npm-packlist@^1.1.6, npm-packlist@^1.4.4:
npm-packlist@^1.4.4:
version "1.4.7"
resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.4.7.tgz#9e954365a06b80b18111ea900945af4f88ed4848"
integrity sha512-vAj7dIkp5NhieaGZxBJB8fF4R0078rqsmhJcAfXZ6O7JJhjhPK96n5Ry1oZcfLXgfun0GWTZPOxaEyqv8GBykQ==
Expand Down Expand Up @@ -14077,7 +14044,7 @@ npm-run-path@^3.0.0:
dependencies:
path-key "^3.0.0"

npmlog@^4.0.2, npmlog@^4.1.2:
npmlog@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b"
integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==
Expand Down Expand Up @@ -16070,16 +16037,6 @@ raw-body@^2.2.0:
iconv-lite "0.4.24"
unpipe "1.0.0"

rc@^1.2.7:
version "1.2.8"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==
dependencies:
deep-extend "^0.6.0"
ini "~1.3.0"
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-app-polyfill@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/react-app-polyfill/-/react-app-polyfill-1.0.5.tgz#59c7377a0b9ed25692eeaca7ad9b12ef2d064709"
Expand Down Expand Up @@ -18197,7 +18154,7 @@ tar-stream@^2.1.0:
inherits "^2.0.3"
readable-stream "^3.1.1"

tar@^4.4.10, tar@^4.4.12, tar@^4.4.2, tar@^4.4.8:
tar@^4.4.10, tar@^4.4.12, tar@^4.4.8:
version "4.4.13"
resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525"
integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==
Expand Down Expand Up @@ -18581,7 +18538,7 @@ [email protected]:
semver "^5.5"
yargs-parser "10.x"

ts-jest@^24.0.2, ts-jest@^24.2.0:
ts-jest@^24.0.2, ts-jest@^24.2.0, ts-jest@^24.3.0:
version "24.3.0"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.3.0.tgz#b97814e3eab359ea840a1ac112deae68aa440869"
integrity sha512-Hb94C/+QRIgjVZlJyiWwouYUF+siNJHJHknyspaOcZ+OQAIdFG/UrdQVXw/0B8Z3No34xkUXZJpOTy9alOWdVQ==
Expand Down

0 comments on commit c9a6ada

Please sign in to comment.