#graphql-schema #graphql #graphviz #graph #terminal #cli-tool #data-structures

bin+lib craftql

一个 CLI 工具,用于可视化 GraphQL 模式,并将图数据结构以 graphviz .dot 格式输出

26 个版本

0.2.20 2023年5月18日
0.2.19 2023年2月2日
0.2.18 2022年12月18日
0.2.17 2022年9月10日
0.2.7 2020年10月15日

开发工具 中排名第 192

Download history 2/week @ 2024-03-09 1/week @ 2024-03-16 91/week @ 2024-03-30 27/week @ 2024-04-06

每月下载量 72

MIT 许可证 MIT

68KB
1.5K SLoC

CraftQL

GitHub Workflow Status Crates.io

一个 CLI 工具,用于可视化 GraphQL 模式,并将图数据结构以 graphviz .dot 格式输出

安装

cargo install craftql

使用方法

USAGE:
    craftql [FLAGS] [OPTIONS] <path>

ARGS:
    <path>
            Path to get files from

FLAGS:
    -h, --help
            Prints help information

    -m, --missing-definitions
            Finds and displays missing definition(s)

    -O, --orphans
            Finds and displays orphan(s) node(s)

    -V, --version
            Prints version information


OPTIONS:
    -f, --filter <filter>...
            Filter nodes by GraphQL type(s)

            - directive
            - enum
            - enum_extension
            - input_object
            - input_object_extension
            - interface
            - interface_extension
            - object
            - object_extension
            - scalar
            - scalar_extension
            - schema
            - union
            - union_extension
    -i, --incoming-dependencies <incoming-dependencies>
            Finds and displays incoming dependencies of a node

    -n, --node <node>
            Finds and displays one node

    -N, --nodes <nodes>...
            Finds and displays multiple nodes

    -o, --outgoing-dependencies <outgoing-dependencies>
            Finds and displays outgoing dependencies of a node

输出 graphviz .dot 格式

craftql tests/fixtures

digraph {
    0 [ label = "DateTime (Scalar)" ]
    1 [ label = "Character (Interface extension)\l\l[Boolean, Character]" ]
    2 [ label = "Human (Object)\l\l[Character, Episode, Float, FriendsConnection, ID, Int, LengthUnit, Starship, String]" ]
    3 [ label = "Droid (Object)\l\l[Character, Episode, FriendsConnection, ID, Int, String]" ]
    4 [ label = "FriendsConnection (Object)\l\l[Character, FriendsEdge, Int, PageInfo]" ]
    5 [ label = "FriendsEdge (Object)\l\l[Character, ID]" ]
    6 [ label = "PageInfo (Object)\l\l[Boolean, ID, test]" ]
    7 [ label = "Review (Object)\l\l[DateTime, Episode, Int, String, test]" ]
    8 [ label = "Orphan (Object)\l\l[ID]" ]
    9 [ label = "ColorInput (InputObject extension)\l\l[ColorInput, Int]" ]
    10 [ label = "Episode (Enum extension)\l\l[Episode]" ]
    11 [ label = "deprecated (Directive)\l\l[String]" ]
    12 [ label = "DateTime (Scalar extension)\l\l[DateTime, test]" ]
    13 [ label = "SearchResult (Union extension)\l\l[Ewok, SearchResult]" ]
    14 [ label = "test (Directive)\l\l[Letter]" ]
    15 [ label = "Episode (Enum)\l\l[deprecated, test]" ]
    16 [ label = "LengthUnit (Enum)" ]
    17 [ label = "Starship (Object extension)\l\l[Boolean, Starship]" ]
    18 [ label = "Query (Object)\l\l[Character, Droid, Episode, Human, ID, Review, SearchResult, Starship, String]" ]
    19 [ label = "Mutation (Object)\l\l[Episode, Review, ReviewInput]" ]
    20 [ label = "Subscription (Object)\l\l[Episode, Review]" ]
    21 [ label = "schema (Schema)\l\l[Mutation, Query, Subscription]" ]
    22 [ label = "ReviewInput (InputObject)\l\l[ColorInput, Int, ReviewInput, String]" ]
    23 [ label = "ColorInput (InputObject)\l\l[ColorInput, deprecated, Int, test]" ]
    24 [ label = "Letter (Enum)" ]
    25 [ label = "Starship (Object)\l\l[deprecated, Float, ID, LengthUnit, String]" ]
    26 [ label = "Character (Interface)\l\l[Bool, Character, deprecated, Episode, FriendsConnection, ID, Int, String, test]" ]
    27 [ label = "SearchResult (Union)\l\l[Droid, Human, Starship, test]" ]
    13 -> 27 [ ]
    14 -> 6 [ ]
    26 -> 4 [ ]
    5 -> 4 [ ]
    6 -> 4 [ ]
    11 -> 25 [ ]
    16 -> 25 [ ]
    26 -> 26 [ ]
    11 -> 26 [ ]
    15 -> 26 [ ]
    4 -> 26 [ ]
    14 -> 26 [ ]
    26 -> 3 [ ]
    15 -> 3 [ ]
    4 -> 3 [ ]
    17 -> 25 [ ]
    15 -> 20 [ ]
    7 -> 20 [ ]
    19 -> 21 [ ]
    18 -> 21 [ ]
    20 -> 21 [ ]
    9 -> 23 [ ]
    26 -> 18 [ ]
    3 -> 18 [ ]
    15 -> 18 [ ]
    2 -> 18 [ ]
    7 -> 18 [ ]
    27 -> 18 [ ]
    25 -> 18 [ ]
    26 -> 2 [ ]
    15 -> 2 [ ]
    4 -> 2 [ ]
    16 -> 2 [ ]
    25 -> 2 [ ]
    1 -> 26 [ ]
    15 -> 19 [ ]
    7 -> 19 [ ]
    22 -> 19 [ ]
    23 -> 22 [ ]
    22 -> 22 [ ]
    23 -> 23 [ ]
    11 -> 23 [ ]
    14 -> 23 [ ]
    24 -> 14 [ ]
    12 -> 0 [ ]
    12 -> 14 [ ]
    11 -> 15 [ ]
    14 -> 15 [ ]
    10 -> 15 [ ]
    0 -> 7 [ ]
    15 -> 7 [ ]
    14 -> 7 [ ]
    26 -> 5 [ ]
    3 -> 27 [ ]
    2 -> 27 [ ]
    25 -> 27 [ ]
    14 -> 27 [ ]
}

graph

按 GraphQL 类型(s) 过滤节点

craftql tests/fixtures --filter object object_extension

digraph {
    0 [ label = "Orphan (Object)\l\l[ID]" ]
    1 [ label = "Human (Object)\l\l[Character, Episode, Float, FriendsConnection, ID, Int, LengthUnit, Starship, String]" ]
    2 [ label = "Droid (Object)\l\l[Character, Episode, FriendsConnection, ID, Int, String]" ]
    3 [ label = "FriendsConnection (Object)\l\l[Character, FriendsEdge, Int, PageInfo]" ]
    4 [ label = "FriendsEdge (Object)\l\l[Character, ID]" ]
    5 [ label = "PageInfo (Object)\l\l[@test, Boolean, ID]" ]
    6 [ label = "Review (Object)\l\l[@test, DateTime, Episode, Int, String]" ]
    7 [ label = "Query (Object)\l\l[Character, Droid, Episode, Human, ID, Review, SearchResult, Starship, String]" ]
    8 [ label = "Mutation (Object)\l\l[Episode, Review, ReviewInput]" ]
    9 [ label = "Subscription (Object)\l\l[Episode, Review]" ]
    10 [ label = "Starship (Object extension)\l\l[Boolean, Starship]" ]
    11 [ label = "Starship (Object)\l\l[@deprecated, Float, ID, LengthUnit, String]" ]
    4 -> 3 [ ]
    5 -> 3 [ ]
    10 -> 11 [ ]
    2 -> 7 [ ]
    1 -> 7 [ ]
    6 -> 7 [ ]
    11 -> 7 [ ]
    6 -> 9 [ ]
    3 -> 2 [ ]
    6 -> 8 [ ]
    3 -> 1 [ ]
    11 -> 1 [ ]
}

查找并显示一个节点

craftql tests/fixtures --node Character

# tests/fixtures/Types/Interfaces/Character.graphql
interface Character @test {
  id: ID!
  name: String!
  friends: [Character]
  friendsConnection(first: Int, after: ID): FriendsConnection!
  appearsIn: [Episode]!
  cute: Bool! @deprecated
}

查找并显示多个节点

craftql tests/fixtures --nodes Character Episode

# tests/fixtures/Types/Interfaces/Character.graphql
interface Character @test {
  id: ID!
  name: String!
  friends: [Character]
  friendsConnection(first: Int, after: ID): FriendsConnection!
  appearsIn: [Episode]!
  cute: Bool! @deprecated
}


# tests/fixtures/Types/Enums/Episode.gql
enum Episode @test(letter: B) {
  NEWHOPE @deprecated
  EMPIRE
  JEDI
}

查找并显示孤立节点

craftql tests/fixtures --orphans

# tests/fixtures/Types/Types/orphan.gql
type Orphan {
  id: ID!
}

查找并显示节点的传入依赖关系

craftql tests/fixtures --incoming-dependencies Starship

# tests/fixtures/Types/Types/extension.graphql
extend type Starship {
  antiGravity: Boolean!
}


# tests/fixtures/Types/Enums/LengthUnit.graphql
enum LengthUnit {
  METER
  FOOT
}


# tests/fixtures/Directives/deprecated.graphql
directive @deprecated(reason: String = "No longer supported") on FIELD_DEFINITION | ENUM_VALUE

查找并显示节点的传出依赖关系

craftql tests/fixtures --outgoing-dependencies Starship

# tests/fixtures/Types/Types/b.graphql
type Human implements Character {
  id: ID!
  name: String!
  homePlanet: String
  height(unit: LengthUnit = METER): Float
  mass: Float
  friends: [Character]
  friendsConnection(first: Int, after: ID): FriendsConnection!
  appearsIn: [Episode]!
  starships: [Starship]
}


# tests/fixtures/Types/Unions/SearchResults.graphql
union SearchResult @test = Human | Droid | Starship


# tests/fixtures/Types/Types/a.gql
type Query {
  hero(episode: Episode): Character
  reviews(episode: Episode!): [Review]
  search(text: String): [SearchResult]
  character(id: ID!): Character
  droid(id: ID!): Droid
  human(id: ID!): Human
  starship(id: ID!): Starship
}

查找并显示缺失的定义

craftql tests/fixtures --orphans

# Color is not defined in:
# tests/fixtures/Types/Interfaces/Character.graphql
interface Character @test {
  id: ID!
  name: String!
  friends: [Character]
  friendsConnection(first: Int, after: ID): FriendsConnection!
  appearsIn: [Episode]!
  cute: Boolean! @deprecated
  preferedColor: Color
}


# Ewok, Gungan are not defined in:
# tests/fixtures/Types/Unions/SearchResultExtension.graphql
extend union SearchResult = Ewok | Gungan

依赖

~9–22MB
~280K SLoC