How To use CLI?

GraphQL Editor CLI

Make your GraphQL schema your one and only source of truth by translating it to literally anything. The main goal is to provide an interactive experience creating GraphQL as a service. Our CLI is compatible with GraphQL editor projects (free and paid tiers).

Installation

Global

npm i -g graphql-editor-cli

Inside Repo

npm i -D graphql-editor-cli

then use with (for example) npx or as a package.json script.

Usage

All commands work in 3 ways:

  • you can provide all arguments with flags

  • you can get the arguments from a local config file

  • complete the arguments in interactive modes

In this exact order, CLI will try to get an argument.

Common Options

All commands also take these options which refer to your GraphQL Editor project:

Option

type

description

namespace

string

Your namespace name

project

string

Project name

version

string

version name

Commands

Schema

Fetch schema from a GraphQL Editor project. The schema will be compiled with GraphQL libraries you are using for this project.

Additional options

Option

type

description

schemaDir

string

Directory to generate schema file

Typings

Generate TypeScript or Javascript typings from GraphQL Editor project.

Additional options

Option

type

description

typingsDir

string

Path where to store generated typings files

typingsGen

"Javascript" or "TypeScript"

Generation language

typingsEnv

"browser" or "node

Environment for typings to work with

typingsHost

string

GraphQL Server URL

Backend

Bootstrap

Bootstrap a backend stucco project. It will create folder with package.json stucco.json and eslint (and prettier configuration). It is an interactive command. It will create a folder with project name you will provide.

Additional options

Option

type

description

system

"backend" or "frontend"

Type of your project

Models

Generate TypeScript Models from GraphQL types. They are very useful to use with popular Databases

type Person {
firstName: String!
lastName: String!
email: String
phone: String
friends: [Person!]!
}

will be transformed to a model file

import type { ModelTypes } from '@/zeus';
export type Person = ModelTypes['Person'];

later on you may want to transform it so it is a database model.

import type { ModelTypes } from '@/zeus';
export type Person = Omit<ModelTypes['Person'], 'friends'> & { friends: string[] };

So you see the concept.

MongoDB

Here is an example how you can use your model in MongoDB.

db.collection<MyModel>.find({})

Resolvers

CLI tool to generate Stucco resolvers in TypeScript from GraphQL fields.

Given the following schema:

type Person {
firstName: String!
}
type Query {
people: [Person]!
}
schema {
query: Query
}

After chosing:

  1. Query

  2. people

It should generate TypeScript resolver placed in $src/Query/people.ts

import { FieldResolveInput, FieldResolveOutput } from 'stucco-js';
import { PersonCollection } from '../db/collections';
import { DB } from '../db/mongo';
import { Utils } from '../Utils';
import { Person, ResolverType, ValueTypes } from '../graphql-zeus';
‚Äč
export const handler = async (): Promise<FieldResolveOutput> => {};

and append correct entries to stucco.json file.

{
"resolvers": {
"Query.people": {
"resolve": {
"name": "lib/Query/people"
}
}
}
}

and after running stucco your resolver should work out of the box. However, some resolver types need little code to make them work the way you want.

Frontend pages

CLI tool to generate GraphQL SSG Frontend Pages.

Roadmap

  • Prisma models from GraphQL types interactive CLI

  • More use cases with other databases and ORMs

  • Deployment of microservices

  • Add colours

  • Push files to editor