Skip to content

Instantly share code, notes, and snippets.

@funwarioisii
Created March 9, 2023 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funwarioisii/5a5b462ff3ec4a587ef6349e0074ef09 to your computer and use it in GitHub Desktop.
Save funwarioisii/5a5b462ff3ec4a587ef6349e0074ef09 to your computer and use it in GitHub Desktop.

RubyMine でHeredoc内で GraphQL を書くときに、 <<~GRAPHQL でくくりたくなる。(特にSpec)

その中でエディタの恩恵を得られるとうれしいのだけど、サポートされていない

https://youtrack.jetbrains.com/issue/RUBY-21946/GraphQL-heredoc-highlighting

JetBrains系は文字列の上にコメントで、language=graphql など書くと、続く文字列のオブジェクトが指定した言語として扱える、言語インジェクションという機能がある https://pleiades.io/help/ruby/using-language-injections.html#use-language-injection-comments

なので、以下のように書くとIDEのサポートをHEREDOC内で受けられる

# language=graphql
query = <<~GRAPHQL
  query listPosts {
    posts {
      id
    }
  }
GRAPHQL

SQL はこの言語インジェクションコメントをわざわざ書かなくてもやってくれるので、そうなってほしいな

@funwarioisii
Copy link
Author

funwarioisii commented Mar 9, 2023

使用例

スクリーンショット 2023-03-09 15 03 28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment