Git Product home page Git Product logo

graphql-cli-prepare'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
  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 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-prepare's People

Contributors

kbrandwijk avatar renovate-bot avatar renovate[bot] avatar schickling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

graphql-cli-prepare's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency @types/node to v9.6.61
  • chore(deps): update dependency @types/inquirer to v9
  • chore(deps): update dependency @types/node to v20
  • chore(deps): update dependency graphql to v16
  • chore(deps): update dependency graphql-config to v5
  • chore(deps): update dependency tslint to v6
  • chore(deps): update dependency typescript to v5
  • fix(deps): update dependency chalk to v5
  • fix(deps): update dependency fs-extra to v11 (fs-extra, @types/fs-extra)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
npm
package.json
  • chalk 2.3.1
  • fs-extra 5.0.0
  • graphql-import 0.4.5
  • graphql-static-binding 0.9.3
  • lodash 4.17.5
  • @types/fs-extra 5.0.1
  • @types/inquirer 0.0.36
  • @types/node 9.4.6
  • @types/yargs 11.0.0
  • graphql 0.13.1
  • graphql-config 2.0.1
  • tslint 5.9.1
  • typescript 2.7.2

  • Check this box to trigger a request for Renovate to run again on this repository

Dependency Vulnerability

So... this seems almost needlessly complicated but here it goes.

The dependency graphql-static-binding has a dependency cucumber-html-reporter and the version of cucumber-html-reporter that graphql-static-binding uses has a dependency "open" which was replaced by "opn". The "open" repo has a security vulnerability. "cucumber-html-reporter" has already fixed it, so "graphql-static-binding" would just need to update the version of "cucumber-html-reporter" it uses, but "graphql-static-binding" has been archived and so will not be updated.

I'm much too junior a dev to know how to fix this. My best guess is that "graphql-static-binding" be forked, updated, and have this repo use the fork in-lieu of the original? Or should this repo re-write schema code generation to use a different repro, one that is active? Or am I entirely wrong?

Hide unconfigured prepare options by default

Currently the CLI logs both configured and unconfigured options when running graphql prepare like this:

$ graphql prepare
โˆš Bundled schema for project app written to src/generated/app.graphql
i Binding not configured for project app. Skipping
i Bundling not configured for project database. Skipping
โˆš Bindings for project database written to src/generated/database.ts

I suggest to hide the i lines by default and just show them when --verbose is provided.

Global install with yarn not working

I am having trouble installing this package and getting the graphql cli to pick up the extension.

The following bash session leads me to believe that yarn fails to install graphql-cli-prepare

What is the best way for me to investigate?

โฏ sudo yarn global add graphql-cli-prepare
yarn global v1.3.2
warning package.json: No license field
warning ../../package.json: No license field
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
warning "serverless > [email protected]" has unmet peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0".
warning "jest > jest-cli > jest-environment-jsdom > jsdom > [email protected]" has unmet peer dependency "request@^2.34".
warning "jest > jest-cli > jest-environment-jsdom > jsdom > request-promise-native > [email protected]" has unmet peer dependency "request@^2.34".
[4/4] ๐Ÿ“ƒ  Building fresh packages...
warning "[email protected]" has no binaries
โœจ  Done in 2.89s.

~/c/gc
โฏ sudo yarn global list
yarn global v1.3.2
warning package.json: No license field
warning ../../package.json: No license field
warning "serverless > [email protected]" has unmet peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0".
warning "jest > jest-cli > jest-environment-jsdom > jsdom > [email protected]" has unmet peer dependency "request@^2.34".
warning "jest > jest-cli > jest-environment-jsdom > jsdom > request-promise-native > [email protected]" has unmet peer dependency "request@^2.34".
info "[email protected]" has binaries:
   - create-react-app
info "[email protected]" has binaries:
   - graphcool
   - gc
info "[email protected]" has binaries:
   - graphql
   - gql
info "[email protected]" has binaries:
   - node-gyp
info "[email protected]" has binaries:
   - serverless
   - slss
   - sls
info "[email protected]" has binaries:
   - ts-node
   - _ts-node
info "[email protected]" has binaries:
   - jest
โœจ  Done in 2.60s.

~/c/gc
โฏ sudo graphql prepare
Usage: graphql [command]

Commands:
  graphql init                Setup .graphqlconfig file
  graphql add-endpoint        Add new endpoint to .graphqlconfig
  graphql get-schema          Download schema from endpoint
  graphql schema-status       Show source & timestamp of local schema
  graphql create [directory]  Bootstrap a new GraphQL project
  graphql ping                Ping GraphQL endpoint
  graphql query <file>        Run query/mutation
  graphql diff                Show a diff between two schemas
  graphql playground          Open interactive GraphQL Playground
  graphql lint                Check schema for linting errors

Options:
  --dotenv       Path to .env file                                      [string]
  -p, --project  Project name                                           [string]
  -h, --help     Show help                                             [boolean]
  -v, --version  Show version number                                   [boolean]

Examples:
  graphql init                 Interactively setup .graphqlconfig file
  graphql get-schema -e dev    Update local schema to match "dev" endpoint
  graphql diff -e dev -t prod  Show schema diff between "dev" and "prod"
                               endpoints

For more information go to https://github.com/graphcool/graphql-cli

Unknown argument: prepare

warning command prepare both exists in plugin

post-deploy:
warning command prepare both exists in plugin /Users/steida/dev/este/node_modules/graphql-cli-prepare and is shipped with the graphql-cli.
The plugin is being ignored.

Support GraphQL 14

Please update the dependencies to support GraphQL 14. I'm getting incorrect peer dependency errors while using graphql-cli.

graphql-cli > graphql-cli-prepare > [email protected]" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
graphql-cli > graphql-cli-prepare > [email protected]" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
graphql-cli > tmp-graphql-config-extension-openapi > @kbrandwijk/[email protected]" has incorrect peer dependency "graphql@^0.12.0 || ^0.13.0".

Cannot find module 'bindings-ts'

When I run graphql prepare I get this error:
Cannot find module 'bindings-ts'

My .graphqlconfig.yml:

projects:
  api:
    schemaPath: "src/schema/schema.graphql"
    extensions:
      endpoints:
        default: "http://localhost:4000"
      prepare-bundle: src/generated/api.graphql
      prepare-binding:
        output: src/generated/api.ts
        generator: bindings-ts
  database:
    schemaPath: "src/generated/prisma.graphql"
    extensions:
      prisma: database/prisma.yml
      prepare-binding:
        output: src/generated/prisma.ts
        generator: prisma-ts

Nested mutation argument not aligned with TypeScript type definitions

I just encountered that the TypeScript type definitions are not aligned with the actual schema. Consider this screenshot from the Playground:

screen shot 2018-03-13 at 13 44 13

Unfortunately, the generated TypeScript type definition does not ship with the connect attribute:

screen shot 2018-03-13 at 13 39 08

The type defs has been generated with "graphql-cli": "^2.15.8".

graphcool.yml should have required property 'stage'. missingProperty: stage

Hi Kim,

When running graphql prepare I am getting the following error:

 yaml {"missingProperty":"stage"} +0ms

[ERROR] in graphcool.yml:
graphcool.yml should have required property 'stage'. missingProperty: stage

If I add in

stages:
  default: dev
  dev: local

I get the following error:

[ERROR] in graphcool.yml:
graphcool.yml should NOT have a "stages" property anymore. Stages are now just provided as CLI args.
Read more here: https://goo.gl/SUD5i5

versions:
"graphql-cli": "^2.3.0",
"graphql-cli-prepare": "^1.4.2",
"graphcool": "1.0.0-beta2.1.1" -> global

Many thanks,
Mark

-o flag is ignored

$ node_modules/.bin/graphql prepare -p test-dosvit-app-prisma-local -o src/experiments -g graphcool-ts --bindings --save
โœ” Bindings for project database written to src/generated/prisma.ts

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.