根据GraphQL Schema
生成Java
代码及DgraphSchema
最新版本为 1.6.0-SNAPSHOT
<dependency>
<groupId>io.github.wangyuheng</groupId>
<artifactId>arc-generator</artifactId>
<version>1.6.0-SNAPSHOT</version>
</dependency>
新建文件 test/resources/graphql/schema.graphqls
Example
scalar DateTime
schema{
query: Query,
mutation: Mutation
}
type Query{
project(
id: String
): Project
}
type Mutation{
createProject(
payload: ProjectInput
): Project
}
type Project{
id: String!
name: String!
description: String!
createTime: DateTime!
milestone(
id: String
): Milestone
milestones: [Milestone]
}
type Milestone{
id: String!
name: String!
description: String!
version: String!
createTime: DateTime!
endTime: DateTime
}
input ProjectInput{
name: String!
description: String!
dsl: String!
vendorBranches: [String!]!
}
新建配置文件, 默认路径为 resources:arc-generator.json
可以通过plugin配置修改
{
"basePackage": "io.github.wangyuheng.arcgeneratorexample",
"dropAll": false,
"genStrategies": [
{
"codeGenOperation": "SKIP",
"codeGenType": "REPO"
},
{
"codeGenOperation": "OVERRIDE",
"codeGenType": "API"
}
],
"ignoreJavaFileNames": [
"User"
],
"dgraphPath": "dgraph/schema.dgraph"
}
mvn arc:generate
可以通过参数-Dtarget
决定生成java or dgraph schema 如
mvn arc:generate -Dtarget=java
运行后会在根据配置在指定目录生成相关业务代码
- directive @Action on FIELD_DEFINITION 区分field是字段还是方法