Maven port of the Netflix Gradle code generation plugin for graphql. https://github.com/Netflix/dgs-codegen

Overview

This is port of the netflix codegen plugin for Gradle. Found here.

COPIED FROM NETFLIX DOCUMENTATION.

The DGS Code Generation plugin generates code for basic types and example data fetchers based on the your Domain Graph Service's graphql schema file during the project's build process. The plugin requires the path to schema files and the package name to use to generate the file. If no schema path is specified, it will look under src/resources/schema for any files with .graphqls extension. plugin generates code for basic types and example data fetchers based on the your Domain Graph Service's graphql schema file during the project's build process. The plugin requires the path to schema files and the package name to use to generate the file. If no schema path is specified, it will look under src/resources/schema for any files with .graphqls extension.

Options

Options are configured in the <configuration> element of the dgs-codegen-maven-plugin plugin.

schemaPaths

  • Type: array
  • Required: false
  • Default: ${project.build.resources}/schema

Example

<schemaPaths>
    <param>src/main/resources/schema/schema.graphqls1</param>
    <param>src/main/resources/schema/schema.graphqls2</param>
</schemaPaths>

packageName

  • Type: string
  • Required: true

Example

<packageName>com.acme.se.generated</packageName>

typeMapping

  • Type: map
  • Required: false

Example

<typeMapping>
    <Date>java.time.LocalDateTime</Date>    
</typeMapping>

subPackageNameClient

  • Type: string
  • Required: false
  • Default: client

Example

<subPackageNameClient>client</subPackageNameClient>

subPackageNameDatafetchers

  • Type: string
  • Required: false
  • Default: client

Example

<subPackageNameDatafetchers>datafetchers</subPackageNameDatafetchers>

subPackageNameTypes

  • Type: string
  • Required: false
  • Default: client

Example

<subPackageNameTypes>types</subPackageNameTypes>

generateBoxedTypes

  • Type: boolean
  • Required: false
  • Default: false

Example

<generateBoxedTypes>false</generateBoxedTypes>

generateClient

  • Type: boolean
  • Required: false
  • Default: false

Example

<generateClient>false</generateClient>

generateInterfaces

  • Type: boolean
  • Required: false
  • Default: false

Example

<generateInterfaces>false</generateInterfaces>

outputDir

  • Type: string
  • Required: false
  • Default: ${project.basedir}/target/generated-sources

Example:

<outputDir>${project.build.directory}/generated-sources</outputDir>

exampleOutputDir

  • Type: string
  • Required: false
  • Default: ${project.basedir}/target/generated-examples

Example:

<outputDir>${project.build.directory}/generated-examples</outputDir>

includeQueries

  • Description: Limit generation to specified set of queries. Used in conjunction with generateClient.
  • Type: array
  • Required: false
  • Default: []

Example

<includeQueries>
    <param>QueryFieldName1</param>
    <param>QueryFieldName2</param>
</includeQueries>

includeMutations

  • Description: Limit generation to specified set of mutations. Used in conjunction with generateClient.
  • Type: array
  • Required: false
  • Default: []

Example

<includeMutations>
    <param>MutationFieldName1</param>
    <param>MutationFieldName1</param>
</includeMutations>

skipEntityQueries

  • Type: boolean
  • Required: false
  • Default: false

Example

<skipEntityQueries>false</skipEntityQueries>

shortProjectionNames

  • Type: boolean
  • Required: false
  • Default: false

Example

<shortProjectionNames>false</shortProjectionNames>

generateDataTypes

  • Type: boolean
  • Required: false
  • Default: false

Example

<generateDataTypes>false</generateDataTypes>

maxProjectionDepth

  • Type: int
  • Required: false
  • Default: 10

Example

<maxProjectionDepth>10</maxProjectionDepth>

Usage

Add the following to your pom files build/plugins section.

<plugin>
    <groupId>io.github.deweyjose</groupId>
	<artifactId>graphqlcodegen-maven-plugin</artifactId>
	<version>1.8</version>
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<schemaPaths>
			<param>src/main/resources/schema/schema.graphqls</param>
		</schemaPaths>
		<packageName>com.acme.[your_project].generated</packageName>
	</configuration>
</plugin>

You'll also need to add the generates-sources folder to the classpath:

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>build-helper-maven-plugin</artifactId>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>add-source</goal>
			</goals>
			<configuration>
				<sources>
					<source>${project.build.directory}/generated-sources</source>
				</sources>
			</configuration>
		</execution>
	</executions>
</plugin>

Generated Output

COPIED FROM NETFLIX DOCUMENTATION.

The generated types are available as part of the packageName.types package under build/generated. These are automatically added to your project's sources. The generated example data fetchers are available under build/generated-examples. Note that these are NOT added to your project's sources and serve mainly as a basic boilerplate code requiring further customization.

Comments
  • GenerateClient not generating query builders

    GenerateClient not generating query builders

    When <generateClient>true</generateClient> is added to the configuration it does not generate the client API classes. Plugin definition:

                    <groupId>io.github.deweyjose</groupId>
                    <artifactId>graphqlcodegen-maven-plugin</artifactId>
                    <version>1.8</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <generateClient>true</generateClient>
                        <schemaPaths>
                            <param>src/main/resources/schema/schema.graphqls</param>
                        </schemaPaths>
                        <packageName>${project.base}/generated</packageName>
                    </configuration>
                </plugin>
    
    opened by adjiandov 15
  • Plugin execution not covered by lifecycle configuration

    Plugin execution not covered by lifecycle configuration

    I have a project that won't build in eclipse. I am getting the error

    Plugin execution not covered by lifecycle configuration: io.github.deweyjose:graphqlcodegen-maven-plugin:1.8:generate (execution: default, phase: generate-sources)

    I have the following the section configuration of the pom based on the readme

            <groupId>io.github.deweyjose</groupId>
            <artifactId>graphqlcodegen-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <typeMapping>
                    <PositiveDecimal>java.math.BigDecimal</PositiveDecimal>
                    <PositiveInt>java.lang.Integer</PositiveInt>
                </typeMapping>
                <schemaPaths>
                    <param>src/main/resources/schema/schema.graphqls</param>
                </schemaPaths>
                <packageName>org.example.graphql.generated</packageName>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-sources</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

    Additional Note: I also want to add the the original developer usee Intelj and doesn't seem to run into this issue. However even when I try to build on the maven command line I still get errors above.

    opened by AbstractAlao 8
  • IIEA10527  Made code changes to reflect the netflix changes. May need…

    IIEA10527 Made code changes to reflect the netflix changes. May need…

    As part of Netflix dgs codegen v5.3.0, 3 new configurations have been created. Have added those here to provide maven compatibility.

    Co-authored-by: Lakshmi Vijayachandran [email protected]

    opened by lakshmisunid 7
  • generateClient Fails when Query isn't named Query

    generateClient Fails when Query isn't named Query

    First, thanks for bringing this to Maven, my team and I appreciate it.

    I'm new to graphQL, graphqlcodegen, and DGS in general, so my apologies if this is a stupid question.

    I'm currently using this maven plugin in a project and failing to have client code generated unless I edit the schema. This is my configuration and a sample of the lines involved in the schema:

    <plugin>
    		<groupId>io.github.deweyjose</groupId>
    		<artifactId>graphqlcodegen-maven-plugin</artifactId>
    		<version>1.16</version>
    		<executions>
    			<execution>
    				<goals>
    					<goal>generate</goal>
    				</goals>
    			</execution>
    		</executions>
    		<configuration>
    			<outputDir>${project.build.directory}/generated-sources/gql-sources</outputDir>
    			<exampleOutputDir>${project.build.directory}/generated-examples/gql-examples</exampleOutputDir>
    			<generateClient>true</generateClient>
    			<generateBoxedTypes>true</generateBoxedTypes>
    			<generateDataTypes>true</generateDataTypes>
    			<writeToFiles>true</writeToFiles>
    			<maxProjectionDepth>2</maxProjectionDepth>
    			<typeMapping>
    				<customerEffectiveDate>java.time.LocalDate</customerEffectiveDate>
    				<customerEndDate>java.time.LocalDate</customerEndDate>
    			</typeMapping>
    			<schemaPaths>
    				<param>src/main/resources/schema/graphqlapi.graphqls</param>
    			</schemaPaths>
    			<packageName>org.myapp.generated</packageName>
    		</configuration>
    </plugin>
    
    schema {
      query: QueryRoot
    }
    
    ...
    
    type QueryRoot {
      customers(id: String, emailAlias: String, phoneNumber: String): [Customer]
      bookOfTheDead(bookId: String, bookCode: String): BookOfTheDead
    }
    

    If I refactor "QueryRoot" to "Query" in the schema, the client codegen suddenly notices the queries and generates all the expected Query and Projection classes as expected. Is the Schema I'm using non-standard? Am I missing a feature in the plugin, or is this really a bug?

    opened by jplabadie 7
  • Maintainer

    Maintainer

    @deweyjose Is this possible for me to ask for me to be granted as maintainer (or the right status) to be able to produce new releases, through GitHub, in order to follow dgs-codegen release rythm.

    opened by zorglube 7
  • Exclude generated files from code coverage report

    Exclude generated files from code coverage report

    Hello! Generated code is currently included in code coverage reports which may be undesirable. It would be great to annotate generated classes with some custom @Generated annotation. Jacoco excludes such annotated files automatically. This feature could be configurable to suit different needs.

    opened by bartebor 6
  • Projection classes generate invalid constructors

    Projection classes generate invalid constructors

    The projection classes in my project generated a class using an extra argument that the parent class does not need

    public class Shows_FooProjection extends BaseSubProjectionNode<ShowsProjectionRoot, ShowsProjectionRoot> {
      public Shows_FooProjection(ShowsProjectionRoot parent, ShowsProjectionRoot root) {
        super(parent, root, java.util.Optional.of("Foo"));
      }
    }
    

    This is from the example repository, the optional foo is marked as an error.

    opened by ReyhanPatria 4
  • Multiple executions with different config

    Multiple executions with different config

    I have two different graphql schemas that I want to generate clients for that share some type names.

    If I put them both under one execution as schemaPaths then the types conflict and the generate code will not compile.

    I tried to make 2 executions with different paths, which runs just fine, but the generate-sources ends up only containing the last run execution. generated-examples has an example for both executions.

            <plugins>
                <plugin>
                    <groupId>io.github.deweyjose</groupId>
                    <artifactId>graphqlcodegen-maven-plugin</artifactId>
                    <version>1.11</version>
                    <executions>
                        <execution>
                            <id>a</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <packageName>com.xxx.a.client</packageName>
                                <schemaPaths>
                                    <param>src/main/resources/graphql/a/schema.graphql</param>
                                </schemaPaths>
                            </configuration>
                        </execution>
                        <execution>
                            <id>b</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <packageName>com.xxx.b.client</packageName>
                                <schemaPaths>
                                    <param>src/main/resources/graphql/b/schema.graphql</param>
                                </schemaPaths>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <typeMapping>
                            <ObjectScalar>java.lang.Object</ObjectScalar>
                            <UUID>java.util.UUID</UUID>
                            <Map_String_ObjectScalar >java.util.Map</Map_String_ObjectScalar>
                            <Map_String_StringScalar>java.util.Map</Map_String_StringScalar>
                        </typeMapping>
                    </configuration>
                </plugin>
            </plugins>
    

    If this is as issue with the wrapped gradle generator i'll raise a ticket over there.


    EDIT:

    ...
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] --------------------< com.xxx.ui:xxx >---------------------
    [INFO] Building xxx1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ xxx ---
    [INFO] Deleting C:\Users\xxx\IdeaProjects\xxx\target
    [INFO] 
    [INFO] --- graphqlcodegen-maven-plugin:1.11:generate (a) @ xxx ---
    [INFO] Codegen config:             --output-dir=C:\Users\xxx\IdeaProjects\xxx\target\generated-sources
                --package-name=com.xxx.a.client
                --sub-package-name-client=client
                --sub-package-name-datafetchers=datafetchers
                --sub-package-name-types=types
                
                --write-to-disk
                --language=JAVA
                
                --generate-data-types
                
                
                
                --type-mapping Map_String_ObjectScalar=java.util.Map
    --type-mapping Map_String_StringScalar=java.util.Map
    --type-mapping ObjectScalar=java.lang.Object
    --type-mapping UUID=java.util.UUID           
                
                
    [INFO] 
    [INFO] --- graphqlcodegen-maven-plugin:1.11:generate (b) @ xxx---
    [INFO] Codegen config:             --output-dir=C:\Users\xxx\IdeaProjects\xxx\target\generated-sources
                --package-name=com.xxx.b.client
                --sub-package-name-client=client
                --sub-package-name-datafetchers=datafetchers
                --sub-package-name-types=types
                
                --write-to-disk
                --language=JAVA
                
                --generate-data-types
                
                
                
                --type-mapping Map_String_ObjectScalar=java.util.Map
    --type-mapping Map_String_StringScalar=java.util.Map
    --type-mapping ObjectScalar=java.lang.Object
    --type-mapping UUID=java.util.UUID           
                
                
    [INFO] 
    [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ xxx---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Using 'UTF-8' encoding to copy filtered properties files.
    [INFO] Copying 1 resource
    [INFO] Copying 3 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ xxx---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 1 source file to C:\Users\xxx\IdeaProjects\xxx\target\classes
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  21.142 s
    [INFO] Finished at: 2021-08-01T17:53:45-04:00
    [INFO] ------------------------------------------------------------------------
    
    
    opened by iamlothian 3
  • Is there a way to distinguish explicit null values from missing values?

    Is there a way to distinguish explicit null values from missing values?

    Thanks for the project. I have a question about how to distinguish explicit null values from missing values.

    Let's use the schema in your example. Suppose I have a mutation that accepts a Show object, which has title as null and there's no releaseYear passed in. When the object gets mapped to a JAVA POJO, both title and releaseYear are null. Is there any way that my application could be aware of the difference?

    opened by Yang-Jace-Liu 2
  • Upgraded dgscodegen to 5.0.3

    Upgraded dgscodegen to 5.0.3

    I noticed that the latest version of dgs serializes queries incorrectly with the latest version of the maven codegen plugin. Namely, it doesn't use the graphql type name when generating the query fragment and instead uses the classname. This is because no schemaType is provided in older versions of the generated code.

    Updating to the latest version of the code gen library fixes this when using the gradle plugin, so this is what I've tried to do here for the maven plugin.

    This is my first time making a change to a maven plugin, so I hope it works. I'm not sure the best way of testing it. The best that can be said of this is that it compiles :)

    opened by karhig 2
  • typeMapping does not seem to be working

    typeMapping does not seem to be working

    Hi,

    I'm trying to ignore a type in code generation, and for some reason the plugin (or the dgs codegen) is not ignoring it. Am I configuring it right?

    My schema looks like this:

    type Query {
        corporateInfo(filter: String!): ClientQL
    }
    
    type ClientQL {
        properties: [CustomPropertyQL]
    }
    
    type CustomPropertyQL {
        property1: String
    }
    

    and the plugin configuration looks like this:

    <configuration>
        <packageName>${project.groupId}.${project.artifactId}.graphql</packageName>
        <schemaPaths>
            <path>src/main/resources/schema/schema.graphqls</path>
        </schemaPaths>
        <generateBoxedTypes>true</generateBoxedTypes>
        <outputDir>${project.build.directory}/generated-sources/src/main/java</outputDir>
        <typeMapping>
            <CustomPropertyQL>${project.groupId}.${project.artifactId}.graphql.CustomPropertyQL</CustomPropertyQL>
        </typeMapping>
    </configuration>
    

    Am I doing anythins wrong here? I'm using version 1.8 of the plugin.

    Thanks a lot!

    opened by tigermarques 2
Releases(graphqlcodegen-maven-plugin-1.27)
Owner
null
Spotless-intellij-gradle - An IntelliJ plugin to allow running the Spotless gradle task from within the IDE.

Spotless Intellij Gradle An IntelliJ plugin to allow running the spotless gradle task from within the IDE on the current file selected in the editor.

Ryan Gurney 30 Dec 17, 2022
:package: Gradle/Maven plugin to package Java applications as native Windows, Mac OS X, or GNU/Linux executables and create installers for them.

JavaPackager JavaPackager is a hybrid plugin for Maven and Gradle which provides an easy way to package Java applications in native Windows, Mac OS X

Francisco Vargas Ruiz 665 Jan 8, 2023
Paper-nms-maven-plugin - A maven plugin for using NMS on paper with Mojang mappings.

paper-nms-maven-plugin A maven plugin for using NMS on paper with Mojang mappings. This plugin will both create the mapped paper dependency and instal

null 56 Dec 28, 2022
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

OpenAPI Generator Master (5.4.x): 6.0.x (6.0.x): ⭐ ⭐ ⭐ If you would like to contribute, please refer to guidelines and a list of open tasks. ⭐ ⭐ ⭐ ‼️

OpenAPI Tools 14.8k Dec 30, 2022
React 0.68+ Turbo Module starter using codegen with typescript for Objective-C and Java/Kotlin with C++ shared library. 🚀🚀🚀

React 0.68+ Turbo Module starter using codegen with typescript for Objective-C and Java/Kotlin with C++ shared library. ?? ?? ?? Features React Native

Nagish Inc. 358 Jan 3, 2023
CodeGen - a secure, high efficiency, and offline-able software, it provides several useful functions

CodeGen Efficiency ToolBox Introduce Download References Issues and Suggestions Software Preview Introduce CodeGen is a secure, high efficiency, and o

null 454 Jan 4, 2023
A gradle plugin based on ANTLR to generate UML diagrams from kotlin source code.

A gradle plugin based on ANTLR to generate UML diagrams from kotlin source code.

Alex Porter 15 Oct 26, 2022
cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

cglib Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to g

Code Generation Library 4.5k Jan 8, 2023
*old repository* --> this is now integrated in https://github.com/javaparser/javaparser

JavaSymbolSolver has been integrated in JavaParser: development will continue there! We will work on current issues opened here, but all new issues sh

JavaParser 288 Nov 25, 2022
Eclipse Foundation 3k Dec 31, 2022
DEPRECATED: use https://github.com/jhipster/jhipster-bom instead

JHipster BOM and server-side library - DEPRECATED Full documentation and information is available on our website at https://www.jhipster.tech/ This pr

JHipster 407 Nov 29, 2022
Now redundant weka mirror. Visit https://github.com/Waikato/weka-trunk for the real deal

weka (mirror) Computing and Mathematical Sciences at the University of Waikato now has an official github organization including a read-only git mirro

Benjamin Petersen 313 Dec 16, 2022
Please visit https://github.com/h2oai/h2o-3 for latest H2O

Caution: H2O-3 is now the current H2O! Please visit https://github.com/h2oai/h2o-3 H2O H2O makes Hadoop do math! H2O scales statistics, machine learni

H2O.ai 2.2k Jan 6, 2023
A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin

Spark - a tiny web framework for Java 8 Spark 2.9.3 is out!! Changeset <dependency> <groupId>com.sparkjava</groupId> <artifactId>spark-core</a

Per Wendel 9.4k Dec 29, 2022
Please visit https://github.com/h2oai/h2o-3 for latest H2O

Caution: H2O-3 is now the current H2O! Please visit https://github.com/h2oai/h2o-3 H2O H2O makes Hadoop do math! H2O scales statistics, machine learni

H2O.ai 2.2k Dec 9, 2022
Old and archived; More recent development is in https://github.com/Create-Fabric/Create-Refabricated.

NOW ARCHIVED Go here for the continuation of this project. Old README Create Fabric A Fabric port of Create. Create Discord: https://discord.gg/AjRTh6

null 12 Dec 7, 2022
PS4 Remote PKG Installer GUI for https://github.com/flatz/ps4_remote_pkg_installer

PS4 Remote PKG Installer PS4 Remote PKG Installer GUI for https://github.com/flatz/ps4_remote_pkg_installer Tired of copying PKG files to USB then wal

Benjamin Faal 116 Dec 25, 2022
Repository to keep up with ViaVersion on MCP (Originally from https://github.com/LaVache-FR/ViaMCP)

ViaMCP-Reborn Repository to keep up with ViaVersion on MCP (Originally from https://github.com/LaVache-FR/ViaMCP) 1.7.x Protocols Yes, i know they are

null 109 Dec 28, 2022
图书管理;图书管理系统;图书管理系统后端,该项目采用Springboot整合Mybatis对数据持久化以及Api的封装实现,前台项目地址:https://github.com/Nirunfeng/BookSys-Client

System of Book Management(sbm) 项目说明 图书管理系统后台,该项目采用Springboot整合Mybatis对数据持久化以及Api的封装实现,前台项目地址:BookSys-Client 项目启动 数据库:mysql5.6执行以下脚本,项目下脚本文件--sbm.sql 导

null 61 Dec 30, 2022