Code Monkey home page Code Monkey logo

gqlmerge's Introduction

gqlmerge

A tool to merge and stitch modularized GraphQL files into one schema file

Demo

Demo

Stack

  • Built in Go
  • No 3rd party dependency

Features

  • Fast, blasing fast
  • Find *.graphql and *.gql files in recursive way
  • Merge and stitch schema from several directories
  • CLI to use in shell or script

How to use

Install to use in CLI

Homebrew

$ brew install mununki/tools/gqlmerge

Using go get

$ go get -u github.com/mununki/gqlmerge

Building with source code

$ git clone https://github.com/mununki/gqlmerge

$ cd gqlmerge

$ go install

Use as a go module

Import gqlmerge module

import gql "github.com/mununki/gqlmerge/lib"

func main(){
	// ...

	// "  " is indent for the padding in generating schema
	// in case of using as go module, just " " would be fine
	//
	// paths should be a relative path
	schema := gql.Merge(" ", path1, path2, ...)
}

What for?

If you have a modularized GraphQL schema files, such as *.graphql, there might be a duplicated types among them. In this case, gqlmerge will help you to merge and stitch it into one schema.

Before

# GetMyProfile.graphql

type Query {
  getMyProfile: UserResponse!
}

type UserResponse {
  ok: Boolean!
  error: String
  user: User
}

type User {
  id: ID!
  email: String!
  fullName: String!
  # ...
}

# CheckIfExists.graphql

type Query {
  checkIfExists(userId: ID!): CheckIfExistsResponse!
}

type CheckIfExistsResponse {
  ok: Boolean!
  error: String
  user: [User]!
}

type User {
  id: ID!
  email: String!
  fullName: String!
  # ...
}

Merge & Stitch

$ gqlmerge ./schema schema.graphql

After

type Query {
  getMyProfile: UserResponse!
  checkIfExists(userId: ID!): CheckIfExistsResponse!
}

type UserResponse {
  ok: Boolean!
  error: String
  user: User
}

type CheckIfExistsResponse {
  ok: Boolean!
  error: String
  user: [User]!
}

type User {
  id: ID!
  email: String!
  fullName: String!
  # ...
}

How to use

$ gqlmerge --indent=2s [PATH ...] [OUTPUT]

// PATH : directories with schema
// OUTPUT : output file name

Next to do

  • additional error handling

gqlmerge's People

Contributors

mununki avatar digiz3d avatar kainosnoema 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.