/goaphql

Golang with GraphQL

Primary LanguageGoApache License 2.0Apache-2.0

GoaphQL

Read in | 中文 | English

Command Line

# Installation
go get -u -v github.com/wenerme/goaphql/cmd/goaphql

graphql-java

# Generate
# Package com.github
# Name Github
goaphql generate graphql-java -s github.graphqls -P com.github -N GitHub
# same
goaphql g gj -s github.graphqls -P com.github -N GitHub

# Customization
# Dump templates
goaphql dump -t tmpl/graphql-java --prefix tmpl/graphql-java -d ./tpl
# Modify templats
# Add package-info.java
echo -e 'package {{Config.JavaPackage}};' > './tpl/Java#package-info.java.tmpl'
# Generate using modified templates
goaphql generate graphql-java -t ./tpl -s github.graphqls -P com.github -N GitHub
# Check the new file
cat out/me/wener/package-info.java

Dependencies

Generated depends on wenerme/jraphql .

<dependencies>
  <dependency>
      <groupId>me.wener.jraphql</groupId>
      <artifactId>jraphql-graphql-java-adapter</artifactId>
      <version>0.0.2</version>
  </dependency>
  <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.20</version>
      <scope>provided</scope>
  </dependency>
</dependencies>

Inside

Package Description
gqlp GraphQL Parser
gqll GraphQL Language representation
gqlg GraphQL Code generator
cmd/goaphql Command line tool

GraphQL Language Extension

# 1. extend by name syntax

type MyQuery {
  myUser(id:ID!):MyUser
}

extend Query by MyQuery

# 2. Allowed directives on directive definition, add DIRECTIVE_DEFINITION location

directive @JavaType(type:String) on DIRECTIVE_DEFINITION
directive @Auth(value:String) @JavaType(type:"Auth") on FIELD_DEFINITION;

# 3. Allowed schema has optional name
schema Test {
  query: MyQuery
}

Roadmap

  • Parse comment
  • Extract java runtime to jraphql
  • Implement golang runtime
  • Implement golang codegen
  • Implement graphql codegen