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

feat: add custom transformer docs #992

Closed
wants to merge 4 commits into from
Closed

feat: add custom transformer docs #992

wants to merge 4 commits into from

Conversation

attilah
Copy link
Contributor

@attilah attilah commented Oct 29, 2019

Description of changes:

Adding a paragraph about custom GraphQL transformer registration.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@attilah attilah added the amplify/cli Issues tied to CLI label Oct 31, 2019
@hisham
Copy link

hisham commented Nov 21, 2019

If it helps, I just released a simple @lowercase graphql transformer to convert strings to lower case before saving to dynamodb. Should serve as a good "hello world" type example of a standalone graphql transformer but does something actually useful:

https://github.com/hisham/graphql-lowercase-transformer
https://www.npmjs.com/package/graphql-lowercase-transformer

DynamoDB does not support case insensitive string search, so this transformer forces searchable strings to be in lowercase in the backend (see aws-amplify/amplify-cli#526).

@hisham
Copy link

hisham commented Nov 21, 2019

I also had the following feedback when building this transformer. I followed your documentation plus the VersionedModelTransformer as my example but ran into the following issues:

@hisham
Copy link

hisham commented Nov 21, 2019

Also graphql transformers to be looked up via npm registry need to be installed globally or else you'll get Cannot find module error:

i.e. npm install -g lowercase-graphql-transformer

This wasn't immediately clear to me.

@ambientlight
Copy link

ambientlight commented Nov 25, 2019

I could not get my transformer to work if it called any class methods. I would get errors such as 'assertModelDirective' is not a method. All functions had to be property arrow functions. See my code https://github.com/hisham/graphql-lowercase-transformer/blob/master/src/LowercaseTransformer.ts. It's probably some kind of ts/js/es5 nuance but I wasn't able to resolve. So I converted all my private methods to private property arrow functions

@hisham: same thing for me, will be great to have these docs mentioning this.
@attilah: I am wondering, since the deployment target is node, are we really required ts to emit es5?

Also graphql transformers to be looked up via npm registry need to be installed globally or else you'll get Cannot find module error

@hisham: hm strange, you are using globally installed amplify right? I wonder if this changes if you use amplify as local project dependency

Can you also run:
$ node module.paths

to check the paths that node looks up when resolving modules.

@hisham
Copy link

hisham commented Nov 25, 2019

@ambientlight yes I am using globally installed amplify. If amplify was installed locally I think it would look it it up locally. Looks like @attilah recently did a PR offering option for both globally installed and locally installed custom transformer packages, see aws-amplify/amplify-cli#2814

@attilah
Copy link
Contributor Author

attilah commented Nov 25, 2019

@hisham @ambientlight Yes, I changed the loading a bit, it has issues about location and initialization as you also faced, I even enabled the pojo scenario, a single object with a method on it and a required properties to work. I've more ideas around it that will come in future changes.

@mauerbac
Copy link
Member

Outdated. Closing

@mauerbac mauerbac closed this Jul 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify/cli Issues tied to CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants