These days, GraphQL is getting popular and a lot of companies adopt it to build their API
and github.com is one of them. In most case, developer will write their schema code with
their favorite language and then wire in the business logic into the resolvers. Recently
there is a IDL defined by the community; although it is not a standard yet, there are a
lot of big players support it. Our generator can utilize the GraphQL IDL or just scaffold
a project with simple Hello World for developer to extend. Either way, you need to wire in
your business logic after the project is generated.
There are two different ways to generate projects with light-graphql-4j generator.
With IDL - Pass in IDL and you need to wire in your backend logic.
Without IDL - A simple Hello World graphql application runnable as starting point.
NOTE: IDL is not currently part of the formal graphql spec. The implementation in this
library is based off the reference implementation. However plenty of code out there is
based on this IDL syntax and hence you can be fairly confident that you are building on
solid technology ground.
We recommend using IDL. For more information about IDL, please check here
Here is an example of config.json for light-graphql-4j generator.
name is used in generated pom.xml for project name
version is used in generated pom.xml for project vesion
groupId is used in generated pom.xml for project groupId
artifactId is used in generated pom.xml for project artifactId
schemaPackage is the package name for generated schema class
schemaClass is the generated schema class name
overwriteSchemaClass controls if the schema class needs to be generated or not. For new project, it should be true. If you want to upgrade the framework to a new version but don’t want to overwrite the updated schema class, then set it to false and regenerate to the same folder.
httpPort is the http port number the server is listening to if it is enabled.
enableHttp is the flag to control if http is enabled or not.
httpsPort is the https port number the server is listening to if it is enabled.
enableHttps is the flag to control if https is enabled or not.
supportDb to control if db connection pool will be setup in service.yml and db dependencies are included in pom.xml
dbInfo section is the database connection pool configuration info.
supportH2ForTest is a flag to control if H2 code is included in the test server and H2 jar is included in pom.mxl
supportClient is a flag to control if client module is included in the generated project to call other services.
In most of the cases, developers will only update schema class and other depending classes in schema package.
Java Command line
Before using the command line to generate the code, you need to check out the repo and build it.
I am using ~/networknt as workspace but it can be anywhere in your home directory.
git clone [email protected]:networknt/light-codegen.git
mvn clean install -DskipTests
First, let’s generate schema as “Hello World” as a starting point so that developers can update
it to manually code their schema class.
The following command will create a sample GraphQL server project in the /tmp/graphql folder.