Code Monkey home page Code Monkey logo

graphql-zeus's Introduction

npm Commitizen friendly

GraphQL Zeus creates autocomplete client library for Javascript or Typescript which provides autocompletion for strongly typed queries.

How it works

Given the following schema Olympus Cards

Play with it

$ zeus https://faker.graphqleditor.com/aexol/olympus/graphql ./generated
import { Api } from "./generated/graphql-zeus"

License

MIT

How to use

Main usage of graphql zeus should be as a CLI.

As a CLI

Installation

Install globally

$ npm i -g graphql-zeus

Of course you can install locally to a project and then use as a npm command or with npx

Usage with Javascript

$ zeus schema.graphql ./

It will also generate corresponding out.d.ts file so you can have autocompletion,

Usage with TypeScript

$ zeus schema.graphql ./  --ts 

Load from URL

$ zeus https://faker.graphqleditor.com/aexol/olympus/graphql ./generated

Use generated client example

import { Api } from './graphql-zeus';

// This will return Card object with ID only
const createCards = async () => {
  let ZeusCard = await Api(
    'https://faker.graphqleditor.com/aexol/olympus/graphql'
  ).Mutation.addCard({
    card: {
      name: 'Zeus',
      description:
        "Sky and Thunder god, rules olympus. Hasn't devoured any children. Zeus' father, Cronus ate all of his children except for Zeus.",
      Attack: 10,
      Defense: 5,
      Children: 92 // YES!
    }
  })({
    id: true
  });
  let DionysusCard = await Api(
    'https://faker.graphqleditor.com/aexol/olympus/graphql'
  ).Mutation.addCard({
    card: {
      name: 'Dionysus',
      description:
        'Dionysus is the Greek god of wine, has the power to bring the dead back to life.',
      Attack: 1,
      Defense: 15,
      Children: 9
    }
  })({
    id: true,
    name: true
  });
  // How to call graphql functions on objects
  const [UpdatedDionysusCard, UpdatedZeusCard] = (await Api(
    'https://faker.graphqleditor.com/aexol/olympus/graphql'
  ).Query.cardById({
    cardId: DionysusCard.id
  })({
    attack: [
      {
        cardID: [ZeusCard.id]
      },
      {
        id: true,
        Attack: true,
        Children: true,
        Defense: true,
        description: true,
        name: true
      }
    ]
  })).attack;
  console.log(UpdatedDionysusCard);
  console.log(UpdatedZeusCard);
};

To run the example navigate to: ./example and run

$ npm i

then run

$ npm run start

Spec

PROMISE_RETURNING_OBJECT = Api.[OPERATION_NAME].[OPERATION_FIELD](
    ...OPERATION_FIELD_PARAMS
)(
    ...RETURN PARAMS
)

Internal graphql type functions

PROMISE_RETURNING_OBJECT = Api.[OPERATION_NAME].[OPERATION_FIELD](
    ...OPERATION_FIELD_PARAMS
)(
    ...RETURN_PARAMS
    [
        {
            ...FUNCTION_PARAMS
        },
        {
            ...RETURN_FUNCTION_PARAMS
        }
    ]
).then( object => object[FUNCTION_NAME] )

Use In your Project to generate code

This will be rarely used, but here you are!

import { Parser,TreeToTS } from 'graphql-zeus';

const schemaFileContents = `
type Query{
    hello: String!
}
schema{
    query: Query
}
`

const typeScriptDefinition = TreeToTS.resolveTree(Parser.parse(schemaFileContents));

const jsDefinition = TreeToTS.javascript(Parser.parse(schemaFileContents));

Support

Join our GraphQL Editor Channel

Contribute

For a complete guide to contributing to GraphQL Editor, see the Contribution Guide.

  1. Fork this repo
  2. Create your feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

Parsing

Simplier approach to GraphQL parsing. Using graphql-js library and parsing AST to simplier types.

graphql-zeus's People

Contributors

aexol 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.