LoginSignup
5
2

More than 3 years have passed since last update.

GraphQL Javaでのスキーマ定義ファイルのコメントの書き方とGraphiQLやGraphQL Playgroundへの反映

Posted at

初めてのGraphQL Webサービスを作って学ぶ新世代APIによると、スキーマ定義ファイルにて各スキーマにコメントをする場合は、以下のようにダブルクォーテーション3つで囲むということになっています。

scheme.graphqls
"""本"""
type Book {

    """ID"""
    id: ID

    """名前"""
    name: String

    """ページ数"""
    pageCount: Int

    """著者"""
    author: Author![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/23101/6f44c6e0-4691-8ca9-a029-0d5ef55f6d7e.png)

}

上記のように書くことで、GraphiQLやGraphQL PlaygroundのDescriptionにもダブルクォーテーション3つで囲ったコメントが表示されるようになるとのことでした。
ただ、当方Java + Spring BootでGraphQLを軽く書いている中で、上記の書きっぷりだとGraphiQLやGraphQL Playgroundへは反映されず、No Descriptionとなってしまうことに気付きました。

そのため、以下のように先頭に#を置く書くことで解決しました。

scheme.graphqls
# 本
type Book {

    # ID
    id: ID

    # 名前
    name: String

    # ページ数
    pageCount: Int

    # 著者
    author: Author
}

GraphiQLとGraphQL Playgroundで確認すると以下の通り表示されるようになりました。
image.png
image.png
以上です。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2