简体   繁体   English

GraphQL Apollo客户端(PhpStorm)中的Format / Prettyprint gql`template strings'

[英]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? 还是我需要以其他方式插入GraphQL表达式才能获得可读的格式?

You can install and configure prettier to your project. 您可以安装和配置prettier的项目。 Then install the Prettier plugin for Webstorm , which will add a Reformat with Prettier action and keyboard shortcut to Webstorm. 然后安装用于Webstorm的Prettier插件,它将为Webstorm添加Reformat with Prettier操作和键盘快捷键的重新格式化。 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. 除非您的GraphQL服务器正在运行GraphiQL或GraphQL Playground,否则这两个工具都具有“整理”功能来重新格式化查询。 Or you could use some online tool like this one from Sangria. 或者,您可以使用Sangria 这类在线工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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