简体   繁体   中英

Format/Prettyprint gql `template strings` in GraphQL Apollo-client (PhpStorm)

When I have

query: gql`query FetchUsers { users {  id   email }}`

What is a fast way to make it look like this:

 query: gql`query FetchUsers {
                users {
                    id
                    email
                }
            }`

Or do I need to insert GraphQL expressions in another way in order to get readable formatting?

You can install and configure prettier to your project. Then install the Prettier plugin for Webstorm , which will add a Reformat with Prettier action and keyboard shortcut to Webstorm. You can also configure it to work with a file watcher to automatically reformat your file when you save it.

Barring that, if your GraphQL server is running either GraphiQL or GraphQL Playground, both of those tools have a "prettify" function to reformat the query. Or you could use some online tool like this one from Sangria.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM