GithubHelp home page GithubHelp logo

mariospas / gqlgenc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yamashou/gqlgenc

0.0 0.0 0.0 1.4 MB

This is Go library for building GraphQL client with gqlgen

License: MIT License

Go 99.87% Makefile 0.13%

gqlgenc's Introduction

Changes

support many queries and mutations without operation names as we designed the queries from the client side very useful for dgraph

usecase:

  1. run dgraph
  2. create graphql schema for dgraph database (dgraph generates many queries and mutations related to your schema)
  3. create client custom queries and mutations
  4. generate client go graphql code that works with dgraph

Goal:

  • auto generate code needed to do all the database communications

Content from gqlgenc

What is gqlgenc ?

This is Go library for building GraphQL client with gqlgen

Motivation

Now, if you build GraphQL api client for Go, have choice:

These libraries are very simple and easy to handle. However, as I work with gqlgen and graphql-code-generator every day, I find out the beauty of automatic generation. So I want to automatically generate types.

Installation

go get -u github.com/mariospas/gqlgenc

How to use

Client Codes Only

gqlgenc base is gqlgen with plugins. So the setting is yaml in each format. gqlgenc can be configured using a .gqlgenc.yml file

Load a schema from a remote server:

model:
  package: generated
  filename: ./models_gen.go # https://github.com/99designs/gqlgen/tree/master/plugin/modelgen
client:
  package: generated
  filename: ./client.go # Where should any generated client go?
models:
  Int:
    model: github.com/99designs/gqlgen/graphql.Int64
  Date:
    model: github.com/99designs/gqlgen/graphql.Time
endpoint:
  url: https://api.annict.com/graphql # Where do you want to send your request?
  headers: # If you need header for getting introspection query, set it
    Authorization: "Bearer ${ANNICT_KEY}" # support environment variables
query:
  - "./query/*.graphql" # Where are all the query files located?
generate:
  clientV2: true # Generate a Client that provides a new signature
  clientInterfaceName: "GithubGraphQLClient" # Determine the name of the generated client interface

Load a schema from a local file:

model:
  package: generated
  filename: ./models_gen.go # https://github.com/99designs/gqlgen/tree/master/plugin/modelgen
client:
  package: generated
  filename: ./client.go # Where should any generated client go?
models:
  Int:
    model: github.com/99designs/gqlgen/graphql.Int64
  Date:
    model: github.com/99designs/gqlgen/graphql.Time
schema:
  - "schema/**/*.graphql" # Where are all the schema files located?
query:
  - "./query/*.graphql" # Where are all the query files located?
generate:
  clientV2: true # Generate a Client that provides a new signature
  clientInterfaceName: "GithubGraphQLClient" # Determine the name of the generated client interface

Execute the following command on same directory for .gqlgenc.yml

gqlgenc

or if you want to specify a different directory where .gqlgenc.yml file resides (e.g. in this example the directory is schemas):

gqlgenc generate --configdir schemas

With gqlgen

Do this when creating a server and client for Go. You create your own entrypoint for gqlgen. This use case is very useful for testing your server.

package main

import (
	"fmt"
	"os"

	"github.com/mariospas/gqlgenc/clientgen"

	"github.com/99designs/gqlgen/api"
	"github.com/99designs/gqlgen/codegen/config"
)

func main() {
	cfg, err := config.LoadConfigFromDefaultLocations()
	if err != nil {
		fmt.Fprintln(os.Stderr, "failed to load config", err.Error())
		os.Exit(2)
	}
	queries := []string{"client.query", "fragemt.query"}
	clientPackage := config.PackageConfig{
		Filename: "./client.go",
		Package:  "gen",
	}

	clientPlugin := clientgen.New(queries, clientPackage)
	err = api.Generate(cfg,
		api.AddPlugin(clientPlugin),
	)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(3)
	}
}

Documents

Comments

Japanese Comments

These codes have Japanese comments. Replace with English.

Subscription

This client does not support subscription. If you need a subscription, please create an issue or pull request.

Pre-conditions

clientgen is created based on modelgen. So if you don't have a modelgen, it may be a mysterious move.

gqlgenc's People

Contributors

yamashou avatar mariospas avatar dbarrosop avatar sonatard avatar rangzen avatar metalscreame avatar dependabot-preview[bot] avatar crazydadz avatar dependabot[bot] avatar cyberhck avatar zreigz avatar mobiletoly avatar jpgauthier avatar ahobsonsayers avatar jakesylvestre avatar ozbe avatar 110y avatar blukai avatar kounosukexxx 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.