Which Category is your question related to?
Newbie question. Not sure whether it is a bug, or I don't understand how to use the tool
What AWS Services are you utilizing?
amplify init, api add, codegen
Provide additional details e.g. code snippets
In this demo video there is clearly graphql-tag generated for queries and mutations, however it was removed in this PR https://github.com/aws-amplify/amplify-cli/pull/206.
If I follow Building a ReactJS Client App tutorial, which includes wrapping queries and mutations in gql, I get a working React app. However, if I use amplify init && amplify api add I get plain objects like export const createPost = 'mutation CreatePost()' and React app throws following error.
Argument of mutation CreatePost($input: CreatePostInput!) { createPost(input: $input) { id title content keywords categories } } passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document
The goal is to create and edit schema locally (not in AppSync console), and I can't seem to find a way to do it.
Thanks!
Yes that video was made before the production release was launched. You'll need to have import gql from 'graphql-tag' and then wrap your statements with gql(listTodos) (as an example).
The reason for this is because not all of the clients require the graphql-tag like the Apollo client does, so Codegen implements this in a generic manner to support any client.
Thanks @undefob. This is a BIG deal! And yet it is buried here in a github issue. Nine months later - does this appear in any AWS documentation? Nader Dabit @dabit3 are you listening? Amplify or AppSync team??
We opted to go without graphql-tag by default because the Amplify GraphQL client does not use it and, when using the Apollo client, their documentation shows that it needs to be added manually anyway.
It would be great if we could configure this in a local template somehow. That way those that want to modify what the output of the codegen looks like have the ability to do so. Manually wrapping gql is not the end of the world, but it could save a lot of redundancy to have it generated if it was needed. This becomes especially true for adding things like type safety in TS projects without manually linking the gql.ts file to the queries/mutations files which creates a lot of extra work. Much appreciated feature request!
Most helpful comment
Yes that video was made before the production release was launched. You'll need to have
import gql from 'graphql-tag'and then wrap your statements withgql(listTodos)(as an example).The reason for this is because not all of the clients require the
graphql-taglike the Apollo client does, so Codegen implements this in a generic manner to support any client.