Code Monkey home page Code Monkey logo

graphql-cli's Introduction

GraphQL CLI

image

CI npm version Discord Chat

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
  generate:
    db:
      dbConfig:
        user: admin
        port: 55432
      database: pg
# ...
    graphqlCRUD:
      create: true
      update: true
      findAll: true

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 DB, schema, document and resolvers 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 faked GraphQL server, you can define your own mocks for each types and scalars inside GraphQL Config like below:
extensions:
  serve:
    mocks:
      DateTime: graphql-scalars#DateTimeMock #Imports DateTimeMock function from graphql-scalars for mocking DateTimeMock

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 Discord Chat

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

graphql-cli's People

Contributors

0xcaff avatar appden avatar ardatan avatar develomark avatar dotansimha avatar felixfbecker avatar greenkeeper[bot] avatar ivangoncharov avatar jamesgeorge007 avatar jexp avatar jlengstorf avatar kamilkisiela avatar kbrandwijk avatar kuldar avatar maticzav avatar nikolasburk avatar peterdresslar avatar pokorson avatar rarkins avatar renovate-bot avatar renovate[bot] avatar romanhotsiy avatar rricard avatar sbinlondon avatar schickling avatar symm avatar timsuchanek avatar urigo avatar wtrocki avatar wuweiweiwu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.