Giter VIP home page Giter VIP logo

graphqlcodegen's Introduction

graphqlcodegen-maven-plugin

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

Contributing

GitHub Issue

Feel free to simply create a GitHub issue for requests to integrate with newer releases of the core DGS Codegen library.

PRs

PRS are welcome as well. The level of difficulty across DGS Codgen updates varies. Typically we add new plugin options and update the CodeGenConfig constructor - when new options are added to the Codegen core library.

Please make sure you run step 2 below to ensure your PR builds correctly. You may need to analyze the CodeGenConfig ctor parameters and add support for new options. Make sure to document any new options to the Options section below.

Process:

  1. bump the version in pom.xml
  2. run mvn install locally to ensure the project still builds
  3. Adjust CodeGen to support new options if needed.

Overview

The DGS Code Generation plugin generates code for basic types and example data fetchers based on your Domain Graph Service's graphql schema file during the project's build process. The plugin requires the designated packageName for file generation. If no schemaPath is specified, it will look in the src/main/resources/schema folder for any files with .graphqls extension.

Example Repo

https://github.com/deweyjose/graphqlcodegen-example

Options

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

onlyGenerateChanged

This options enables the plugin to limit code generation to only schema files that have changed. Today this only works with schemaPaths.

This only works for <schemaPaths>. A subsequent release for schema compilation via dependencies will be release soon.

  • Type: boolean
  • Required: false
  • Default: true
<onlyGenerateChanged>true</onlyGenerateChanged>

subPackageNameDocs

  • Type: string
  • Required: false
  • Default: docs

Example

<subPackageNameDocs>docs</subPackageNameDocs>

generateDocs

  • Type: string
  • Required: false
  • Default: docs

Example

<generateDocs>true</generateDocs>

generatedDocsFolder

  • Type: string
  • Required: false
  • Default: ./generated-docs

Example

<generatedDocsFolder>true</generatedDocsFolder>

addGeneratedAnnotation

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

Example

<addGeneratedAnnotation>true</addGeneratedAnnotation>

skip

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

Example

<dgs.codegen.skip>true</dgs.codegen.skip>

Or

# mvn ... -Ddgs.codegen.skip=true

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>

schemaJarFilesFromDependencies

Example

<schemaJarFilesFromDependencies>
    <param>com.netflix.graphql.dgs:some-dependency:1.0.0</param>
    <param>com.netflix.graphql.dgs:some-dependency:X.X.X</param>
</schemaJarFilesFromDependencies>

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>

typeMappingPropertiesFiles

Provide typeMapping as properties file(s) that is accessible as a compile-time-classpath resource Key-Value pairs in the properties file will be added to typeMapping Map when it is not already present in it

When a same GraphQL type is present in both typeMapping and also in typeMappingPropertiesFiles, value in typeMapping will be used (and the value from typeMappingPropertiesFiles will be ignored)

  • Type: Array
  • Required: false

Example

<typeMappingPropertiesFiles>
    <typeMappingPropertiesFile>commontypes-typeMapping.properties</typeMappingPropertiesFile>
    <typeMappingPropertiesFile>someother-commontypes-typeMapping.properties</typeMappingPropertiesFile>
</typeMappingPropertiesFiles>

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>

generateClientApi

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

Example

<generateClientApi>false</generateClientApi>

generateClientApiV2

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

Example

<generateClientApiV2>false</generateClientApiV2>

generateInterfaces

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

Example

<generateInterfaces>false</generateInterfaces>

generateKotlinNullableClasses

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

Example

<generateKotlinNullableClasses>false</generateKotlinNullableClasses>

generateKotlinClosureProjections

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

Example

<generateKotlinClosureProjections>false</generateKotlinClosureProjections>

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>

language

  • Type: String
  • Required: false
  • Default: java

Example

<language>kotlin</language>

omitNullInputFields

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

Example

<omitNullInputFields>false</omitNullInputFields>

kotlinAllFieldsOptional

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

Example

<kotlinAllFieldsOptional>false</kotlinAllFieldsOptional>

snakeCaseConstantNames

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

Example

<snakeCaseConstantNames>false</snakeCaseConstantNames>

writeToFiles

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

Example

<writeToFiles>false</writeToFiles>

includeSubscriptions

  • Type: array
  • Required: false
  • Default: []

Example

<includeSubscriptions>
    <param>Subscriptions1</param>
    <param>Subscriptions2</param>
</includeSubscriptions>

generateInterfaceSetters

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

Example

<generateInterfaceSetters>false</generateInterfaceSetters>

generateInterfaceMethodsForInterfaceFields

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

Example

<generateInterfaceMethodsForInterfaceFields>false</generateInterfaceMethodsForInterfaceFields>

javaGenerateAllConstructor

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

Example

<javaGenerateAllConstructor>false</javaGenerateAllConstructor>

implementSerializable

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

Example

<implementSerializable>false</implementSerializable>

generateCustomAnnotations

  • Type: boolean
  • Required: false
  • Default: false
<generateCustomAnnotations>false</generateCustomAnnotations>

addDeprecatedAnnotation

  • Type: boolean
  • Required: false
  • Default: false
<addDeprecatedAnnotation>false</addDeprecatedAnnotation>

includeImports

  • Type: map<string, string>
  • Required: false
<includeImports>
    <validator>com.test.validator</validator>
</includeImports>

includeEnumImports

  • Type: map<string,<string,string>>
  • Required: false
<includeEnumImports>
    <foo>
        <properties>
            <bar>bla</bar>
        </properties>
    </foo>
    <bar>
        <properties>
            <zoo>bar.bar</zoo>
            <zing>bla.bla</zing>
        </properties>
    </bar>
</includeEnumImports>

includeClassImports

Maps the custom annotation and class names to the class packages. Only used when generateCustomAnnotations is enabled.

  • Type
  • Required: false
<includeClassImports>
    <foo>
        <properties>
            <bar>bla</bar>
        </properties>
    </foo>
    <bar>
        <properties>
            <zoo>bar.bar</zoo>

            <zing>bla.bla</zing>
        </properties>
    </bar>
</includeClassImports>

generateIsGetterForPrimitiveBooleanFields

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

Example

<generateIsGetterForPrimitiveBooleanFields>false</generateIsGetterForPrimitiveBooleanFields>

Usage

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

<plugin>
    <groupId>io.github.deweyjose</groupId>
    <artifactId>graphqlcodegen-maven-plugin</artifactId>
    <version>1.24</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>
        <addGeneratedAnnotation>true</addGeneratedAnnotation>
    </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.

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.