graphql-cli

授权协议 MIT License
开发语言 JavaScript
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 蒋俊
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

GraphQL CLI

image

CI

Help us to improve new GraphQL CLI. Check out the new structure and commands below!Feel free to contact us in Discord channel. We would love to hear your feedback.

Features

  • Helpful commands to improve your workflows
  • Compatible with editors and IDEs based on graphql-config
  • Powerful plugin system to extend graphql-cli with custom commands

Install

You can install the CLI using yarn by running the following command. This will add the graphql binary to your path.

yarn global add graphql-cli

The equivalent npm global install will also work.

Migration from 3.x.x to 4.x.x

Important: many aspects of GraphQL CLI syntax and structure have changed in 4.x.x. Please check out the Migration Guide to learn more.

Usage / Initialization

At the heart of a project created using GraphQL CLI is the GraphQL Config configuration file. For starters, this configuration lets the cd CLI tools know where all of the GraphQL documents and operations are. For more information about GraphQL Config, you can click here to learn more.

The most straightforward way to launch a GraphQL CLI-capable project with a working GraphQL Config setup is to use the init command from your desired workspace:

npx graphql-cli init

After a series of questions from the command-prompt, the system will use the inputs and selected project templates to generate a working project complete with a GraphQL Config setup. The GraphQL Config file is generated referencing the necessary files and ecosystem plugins.

You can also get started with GraphQL CLI by creating your own GraphQL Config file using an editor of your choice. Starting with a filename .graphqlrc.yml, for instance, we could add:

schema: "server/src/schema/**/*.graphql"
documents: "client/src/documents/**/*.graphql"

This is now a valid YAML-syntax GraphQL Config file. Using init from the GraphQL CLI will generate a project based on the instructions in your YAML.

Finally, one of the options with graphql init is to access schema using an OpenAPI or Swagger endpoint. Choose this option at the start of the Init question tree, and then follow the instructions to navigate to the URL of your choice.

Plugin System

Each command in GraphQL CLI is a seperate package, so you can have your own plugins or use the ones we maintain. You can have those commands by installing them like @graphql-cli/[COMMAND-NAME].

To configure a command/plugin, you need to update the extensions field in your GraphQL Config file (.graphqlrc.yml). See extensions: in the example below.

schema: 
  ./server/src/schema/**/*.ts:
    require: ts-node/register
documents: ./client/src/graphql/**/*.ts
extensions:
  codegen:
    generates:
      ./server/src/generated-types.d.ts:
        plugins:
          - typescript
          - typescript-resolvers
      ./client/src/generated-types.tsx:
        plugins:
          - typescript
          - typescript-operations
          - typescript-react-apollo
      config:
        withHooks: true
  graphback:
    model: './model/*.graphql'
    plugins:
      graphback-schema:
        outputPath: './src/schema/schema.graphql'
      ...

For a detailed example check out a template file here.

Some of the available Plugins are:

  • init - Creates a GraphQL project using a template or GraphQL Config file for your existing project.
  • codegen - GraphQL Code Generator's GraphQL CLI plugin. GraphQL Code Generator is a tool that generates code from your GraphQL schema and documents for your backend or frontend with flexible support for custom plugins and templates. Learn More
  • generate - Generate schema and client-side documents for your GraphQL project by using Graphback.
  • coverage - Schema coverage based on documents. Find out how many times types and fields are used in your application using GraphQL Inspector.
  • diff - Compares schemas and finds breaking or dangerous changes using GraphQL Inspector.
    • You can also compare your current schema against a base schema using URL, Git link and local file. You can give this pointer in the command line after graphql diff or in GraphQL Config file:
# ...
extensions:
  diff:
    baseSchema: git:origin/master:schema.graphql
  • similar - Get a list of similar types in order to find duplicates using GraphQL Inspector.
  • validate - Validates documents against a schema and looks for deprecated usage using GraphQL Inspector.
  • serve - Serves a GraphQL server, using an in memory database and a defined GraphQL schema. Please read through serve documentation to learn more about this command.

More plugins are definitely welcome! Please check the existing ones to see how to use GraphQL Config and GraphQL CLI API.

Contributing

Please read through the contributing guidelines

Writing your own plugin

GraphQL CLI supports custom plugins, you can find a tutorial and example here

Help & Community

Join our Discord chat if you run into issues or have questions. We're excited to welcome you to the community!

  • GraplQL是什么?能干啥? 一种查询语言,一种是Facebook开发的API查询语言。 GraphQL 这种方式能够将原有 RESTful 风格时的多次请求聚合成一次请求,可以定制查询结果(结构)。 和REST API的区别: REST 1、返回的数据格式和类型都是定义好的,如果想前后端保持预期效果, 1)协调后端改接口(工作量/频繁改动); 2)前端自己做适配(会增加网络传输量)。 2、某前

  • 简单api GraphQL is a great alternative to REST (or other HTTP API designs). This is a quick introduction to the core concepts around consuming a GraphQL API. GraphQL是REST(或其他HTTP API设计)的绝佳替代品。 这是对使用 Gra

  • express-cli Hey guys, if you are new to OSS(open source software) development and want to get started with open source contributions, then here is the organization for you where you can initiate your

  • 一、安装vue-apollo客户端 npm install vue-apollo graphql apollo-client apollo-link apollo-link-http apollo-cache-inmemory graphql-tag 二、配置graphql预加载器 目前网上看到的方法主要针对webpack.config.js配置如下代码 { test: /\.(g

  • express-cli Hey guys, if you are new to OSS(open source software) development and want to get started with open source contributions, then here is the organization for you where you can initiate your

  • 前言 nodjs v14.16.1 (在Windows系统安装Nodejs、在Linux系统安装Nodejs) vue-cli 版本 vue-cli 已分为2个版本: @vue/cli,这是新版本(本文安装这版),文档:https://cli.vuejs.org/。 vue-cli,这是旧版本,文档:https://github.com/vuejs/vue-cli/tree/v2#vue-cli–

  • 我使用graphql,nodejs,express和sequelize(使用mysql)构建了一个小代码,但我还没有找到graphql的魔力 . 我使用sequelize-cli创建我的模型(使用sequelize model:create等),我会动态生成我的模式和类型: var types = generateModelTypes([db['User'], db['Acesso']]) var

  • 1、准备服务器 Ubuntu 20.04 CPU:4核 内存:8G 硬盘:SSD 200G 2、配置Graph Node服务器环境 root@ip-172-93-12-156:~# apt update root@ip-172-93-12-156:~# apt upgrade root@ip-172-93-12-156:~# apt-get -y install apt-transport-htt

 相关资料
  • graphql_client A typed GraphQL client library for Rust. Features Precise types for query variables and responses. Supports GraphQL fragments, objects, unions, inputs, enums, custom scalars and input o

  • 快速开始 GraphQL 是一种用于 API 的查询语言。这是 GraphQL 和 REST 之间一个很好的比较 (译者注: GraphQL 替代 REST 是必然趋势)。在这组文章中, 我们不会解释什幺是 GraphQL, 而是演示如何使用 @nestjs/GraphQL 模块。 GraphQLModule 只不过是 Apollo 服务器的包装器。我们没有造轮子, 而是提供一个现成的模块, 这让

  • GraphQL 既是一种用于 API 的查询语言也是一个满足你数据查询的运行时。 GraphQL 对你的 API 中的数据提供了一套易于理解的完整描述,使得客户端能够准确地获得它需要的数据,而且没有任何冗余,也让 API 更容易地随着时间推移而演进,还能用于构建强大的开发者工具。 向你的 API 发出一个 GraphQL 请求就能准确获得你想要的数据,不多不少。 GraphQL 查询总是返回可预测

  • Graphql editor 是一款 Graphql 的可视化编辑器和 IDE,帮助用户更容易理解 GraphQL 模式,通过使用可视化块系统创建模式。GraphQL Editor 将把它们转化为代码。通过 GraphQL Editor,用户可以在不写任何代码的情况下创建可视化的图表,或者以一种很好的方式呈现其模式。 GraphQL View Code Editor View Hierarchy View

  • Fullstack GraphQL Simple Demo Application API built with Node + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux. Written in ES6 using Babel

  • Hasura GraphQL Engine Hasura is an open source product that accelerates API development by 10x by giving you GraphQL or REST APIs with built in authorization on your data, instantly. Read more at hasu