Code Monkey home page Code Monkey logo

graphql-codegen's Introduction

graphql-codegen

graphql-codegen generates code given a GraphQL Schema. (Only Java is supported for now)

Build Status

Install:

Clone the repo and build the jar: ./gradlew shadowJar or download the latest jar under the Releases tab.

Usage:

To generate the code for the Star Wars sample:

java -jar graphql-codegen.jar generate java -u http://graphql-swapi.parseapp.com/graphiql --package com.disney.starwars

You can specify a number of options, all described with the help generate java command:

java -jar graphql-codegen.jar help generate java 

outputs:

NAME
        graphql-codegen generate java - Generate code for java

SYNOPSIS
        graphql-codegen generate java
                [(-o <output directory> | --output <output directory>)]
                [--override <imports override>...] [--package <java package>]
                [--password <Basic Auth password>]
                (-u <GraphQL server url> | --url <GraphQL server url>)
                [--username <Basic Auth username>]

OPTIONS
        -o <output directory>, --output <output directory>
            Where to write the generated files (default: .)

        --override <imports override>
            For custom GraphQL scalars of for external libraries such as joda
            you can specify your own import for a given type. The format must be
            type::package Package wildcard is allowed. e.g:
            DateTime::org.joda.time.DateTime or
            MyCustomList::com.my.MyCustomList or e.g: DateTime::org.joda.time.*

        --package <java package>
            Classes output package (default: my.custom.package)

        -u <GraphQL server url>, --url <GraphQL server url>
            Fully qualified GraphQL server url

        --username <Basic Auth username>
            Basic Auth username
            
        --password <Basic Auth password>
            Basic Auth password

License

graphql-codegen is licensed under the MIT License. See LICENSE for details.

Copyright (c) 2016, Antoine Boyer and Contributors

Inspired by graphql-swift-codegen by @tberman

graphql-js License

graphql-codegen's People

Contributors

nagorniyaleksandr avatar tinnou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graphql-codegen's Issues

Enum types generation issue

Hi!
There are some small issue with generating Enum types.

  1. Class name should starts from the Upper letter.
  2. We have to set some value to each line, because we haven't default constructor.
  3. We should have get method for value

Now our generated code is looks like:

public enum jump {

    START, 
    END

    private String value;

    jump (String value) {
    this.value = value;
    }

    @Override
    public String toString() {
        return value;
    }
}

but. the good code would be that:

public enum **J**ump {

    START**("start")**, 
    END**("end");**

    private String value;

    jump (String value) {
    this.value = value;
    }

    **public String getValue() {
        return value;
    }**

    @Override
    public String toString() {
        return value;
    }
}

for example(or for testing), here is part of schema:

{
  "kind": "ENUM",
  "name": "game",
  "description": "Valid field values for game",
  "fields": null,
  "inputFields": null,
  "interfaces": null,
  "enumValues": [
    {
      "name": "start",
      "description": null,
      "isDeprecated": false,
      "deprecationReason": null
    },
    {
      "name": "end",
      "description": null,
      "isDeprecated": false,
      "deprecationReason": null
    }
  ],
  "possibleTypes": null
}

I've already fixed this issue, so I can push code with fixes to some branch if you provide me permissions.

Several interfaces implementing bug

Hi! Thanks a lot for your work. It's great code generator!

In my case some class is implementing several interfaces. Their schema is like:

{
  "kind": "OBJECT",
  "name": "myClass",
  "description": "No description for myClass",
  "fields": [],
  "inputFields": null,
  "interfaces": [
    {
      "kind": "INTERFACE",
      "name": "firstInterface",
      "ofType": null
    },
    {
      "kind": "INTERFACE",
      "name": "secondInterface",
      "ofType": null
    }
  ],
  "enumValues": null,
  "possibleTypes": null
}

, so generated code should looks like:

public class MyClass implements FirstInterface, SecondInterface {
   ....
}

public interface FirstInterface {
   ....
}

public interface SecondInterface {
   ....
}

but the result of generating of the code is:

public class Appy_Deployment implements firstInterface,  implements secondInterface {
   ....
}

public interface FirstInterface {
   ....
}

public interface SecondInterface {
   ....
}

and we have:

  1. duplicated "implements"
  2. chain of interface names witch starts from lower letter (when interface class name starts from Upper letter).
    As a result we have compilation error.

I've already fixed this issue in my local copy, so I can push code with fixes to some branch if you grant me the appropriate permissions.

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.