-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update gql v2 custom transformer loading logic (#9252)
* fix: update gql v2 custom transformer loading logic * test: add custom transformer v2 test Co-authored-by: Colin Ihrig <colihrig@amazon.com>
- Loading branch information
1 parent
beed4f9
commit f728b4b
Showing
8 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/amplify-e2e-tests/schemas/custom_transformers/simple_custom_model.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type Todo @model @simple { | ||
id: ID! | ||
content: String | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/amplify-e2e-tests/schemas/custom_transformers/simple_custom_transformer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { TransformerPluginBase } = require('@aws-amplify/graphql-transformer-core'); | ||
|
||
class SimpleCustomTransformer extends TransformerPluginBase { | ||
constructor() { | ||
super('simple-custom-transformer', 'directive @simple on OBJECT'); | ||
} | ||
|
||
object() {} // Must be implemented. | ||
} | ||
|
||
module.exports = { default: SimpleCustomTransformer }; |
63 changes: 63 additions & 0 deletions
63
packages/amplify-e2e-tests/src/__tests__/graphql-v2/custom-transformers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
addApiWithoutSchema, | ||
apiGqlCompile, | ||
createNewProjectDir, | ||
deleteProject, | ||
deleteProjectDir, | ||
getSchemaPath, | ||
getTransformConfig, | ||
initJSProjectWithProfile, | ||
setTransformConfig, | ||
updateApiSchema, | ||
} from 'amplify-e2e-core'; | ||
import * as path from 'path'; | ||
|
||
describe('GraphQL transformer v2 - Custom transformers', () => { | ||
let projRoot: string; | ||
let projFolderName: string; | ||
|
||
beforeEach(async () => { | ||
projFolderName = 'graphqlv2customtransformer'; | ||
projRoot = await createNewProjectDir(projFolderName); | ||
}); | ||
|
||
afterEach(async () => { | ||
try { | ||
await deleteProject(projRoot); | ||
} catch (_) { | ||
// No-op. | ||
} | ||
|
||
deleteProjectDir(projRoot); | ||
}); | ||
|
||
it('create a project including a custom transformer', async () => { | ||
const projName = 'v2customtransformer'; | ||
const schemaDir = 'custom_transformers'; | ||
const schemaFile = 'simple_custom_model.graphql'; | ||
const schemaName = path.join(schemaDir, schemaFile); | ||
const schemaPath = getSchemaPath(schemaName); | ||
const customTransformerName = 'simple_custom_transformer.js'; | ||
const customTransformerPath = schemaPath.replace(schemaFile, customTransformerName); | ||
|
||
await initJSProjectWithProfile(projRoot, { name: projName }); | ||
await addApiWithoutSchema(projRoot); | ||
await updateApiSchema(projRoot, projName, schemaName); | ||
|
||
// GQL compile should fail initially because the transformer does | ||
// not know about the custom directive. | ||
await expect(async () => { | ||
await apiGqlCompile(projRoot); | ||
}).rejects.toThrow(); | ||
|
||
// Add the custom directive. | ||
const config = getTransformConfig(projRoot, projName); | ||
config.transformers ??= []; | ||
config.transformers.push(customTransformerPath); | ||
setTransformConfig(projRoot, projName, config); | ||
|
||
// GQL compile should pass now because the transformer knows about | ||
// the custom directive. | ||
await apiGqlCompile(projRoot); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters