未验证 提交 b1c8b6cd 编写于 作者: B Bogdan Kobylynskyi 提交者: GitHub

Support code generation based on introspection query response #165 (#297)

* Support code generation based on introspection query response #165

* 165 introspection query (#298)

* add sbt plugin

* rm log to file

* update

* update readme

* update readme

* update readme

* update client example

* update client example

* update log

* update client example

* add scalaiform

* add scalaiform and publish

* support schemaFinderConfig and parentInterfacesConfig

* update readme license, convert GraphQLCodegen to Def

* update readme

* Create scala.yml

* update scala ci

* update scala ci

* rm scala ci

* rm scala ci

* use publishLocal

* ci support ivy cache

* ci support ivy cache

* fix support ivy cache

* change example project level

* change example project level

* fix path for ci

* fix workflows

* move generate code to src_managed_graphql

* change generate code location to src_managed_graphql

* add sbt-test for plugin

* fix workflows

* fix workflows

* change generate code location to src_managed_graphql

* add watch resource, refactor plugins

* add developer for publish

* add key apiAsyncReturnType and apiAsyncReturnListType,
refactor code, update sbt-test with two options

* add resolvers

* add resolvers for ci

* add resolvers for ci

* add resolvers for ci

* Remove redundant dependencies

* fix support ivy local

* Update github.yml

* fix support ivy local

* update ci

* fix compile failed when generate code  not found in classpath. test in the standard way

* Update github.yml

* 1. update default option code
2. update client example
3. update version to 2.3.0

* update version to 2.3.0

* Merge branch 'master' of github.com:jxnu-liguobin/graphql-java-codegen

* pre release  2.4.0

* next dev 2.4.1-SNAPSHOT
fix example support with v2.4.0 add typename

* add use case with proxy

* add comment

* add Support code

* update README

* add scope on conf key

* add release plugin

* add release plugin

* Setting version to 2.4.2

* Setting version to 2.4.3-SNAPSHOT

* add release plugin (not release)

* upgrade sbt version, update example Deprecated api

* refactor sbt plugin

* refactor sbt plugin

*  Changes for upcoming release 3.0.0 (#276)

* Setting version to 3.0.0

* fix conflict, release3.0.0

* append migration

* append migration

* fix default value, cannot assign a int value to Long(boxing type)

* fix default value, cannot assign a int value to Long(boxing type)

* use new file

* use conversion instead of reflect

* throw exception msg

* add option graphqlQueryIntrospectionResultPath

* Fixes parsing schema and introspection result #296
Co-authored-by: 梦境迷离's avatar梦境迷离 <dreamylost@outlook.com>
上级 f1c189db
......@@ -4,6 +4,7 @@
| :---------------------------------------------: | :----------------------------------------------------------------: | :-------------------------------------------: | ----------- |
| `graphqlSchemaPaths` | List(String) | (falls back to `graphqlSchemas`) | GraphQL schema locations. You can supply multiple paths to GraphQL schemas. To include many schemas from a folder hierarchy, use the `graphqlSchemas` block instead. |
| `graphqlSchemas` | *See [graphqlSchemas](#option-graphqlschemas)* | All `.graphqls`/`.graphql` files in resources | Block to define the input GraphQL schemas, when exact paths are too cumbersome. See table below for a list of options. *See [graphqlSchemas](#option-graphqlschemas)* |
| `graphqlQueryIntrospectionResultPath` | String | None | Path to GraphQL Introspection Query result in json format (with root object `__schema` or `data.__schema`). Sample: [sample-introspection-query-result.json](../src/test/resources/introspection-result/sample-introspection-query-result.json)|
| `outputDir` | String | None | The output target directory into which code will be generated. |
| `jsonConfigurationFile` | String | Empty | Path to an external mapping configuration. |
| `packageName` | String | Empty | Java package for generated classes. |
......
......@@ -41,6 +41,7 @@ import java.util.Set;
public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCodegenConfiguration {
private List<String> graphqlSchemaPaths;
private String graphqlQueryIntrospectionResultPath;
private final SchemaFinderConfig graphqlSchemas = new SchemaFinderConfig();
private File outputDir;
......@@ -134,7 +135,7 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
mappingConfig.setMutationResolverParentInterface(getMutationResolverParentInterface());
mappingConfig.setSubscriptionResolverParentInterface(getSubscriptionResolverParentInterface());
new GraphQLCodegen(getActualSchemaPaths(), outputDir, mappingConfig, buildJsonSupplier()).generate();
new GraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, buildJsonSupplier()).generate();
}
// This is only public so that it can be part of the inputs.
......@@ -192,6 +193,16 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
this.graphqlSchemaPaths = graphqlSchemaPaths;
}
@InputFile
@Optional
public String getGraphqlQueryIntrospectionResultPath() {
return graphqlQueryIntrospectionResultPath;
}
public void setGraphqlQueryIntrospectionResultPath(String graphqlQueryIntrospectionResultPath) {
this.graphqlQueryIntrospectionResultPath = graphqlQueryIntrospectionResultPath;
}
@Nested
@Optional
public SchemaFinderConfig getGraphqlSchemas() {
......
......@@ -37,6 +37,9 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
@Parameter
private String[] graphqlSchemaPaths;
@Parameter
private String graphqlQueryIntrospectionResultPath;
@Parameter
private SchemaFinderConfig graphqlSchemas = new SchemaFinderConfig();
......@@ -212,7 +215,7 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
MappingConfigSupplier mappingConfigSupplier = buildJsonSupplier(jsonConfigurationFile);
try {
new GraphQLCodegen(getSchemas(), outputDir, mappingConfig, mappingConfigSupplier).generate();
new GraphQLCodegen(getSchemas(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, mappingConfigSupplier).generate();
} catch (Exception e) {
getLog().error(e);
throw new MojoExecutionException("Code generation failed. See above for the full exception.");
......@@ -265,6 +268,14 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
this.graphqlSchemaPaths = graphqlSchemaPaths;
}
public String getGraphqlQueryIntrospectionResultPath() {
return graphqlQueryIntrospectionResultPath;
}
public void setGraphqlQueryIntrospectionResultPath(String graphqlQueryIntrospectionResultPath) {
this.graphqlQueryIntrospectionResultPath = graphqlQueryIntrospectionResultPath;
}
public SchemaFinderConfig getGraphqlSchemas() {
return graphqlSchemas;
}
......
......@@ -104,6 +104,8 @@ trait GraphQLCodegenKeys {
val useOptionalForNullableReturnTypes = settingKey[Boolean]("useOptionalForNullableReturnTypes")
val graphqlQueryIntrospectionResultPath = settingKey[Option[String]]("graphqlQueryIntrospectionResultPath")
//for version
val javaxValidationApiVersion = settingKey[Option[String]]("javax-validation-api version")
val graphqlJavaCodegenVersion = settingKey[Option[String]]("graphql java codegen version")
......
......@@ -58,6 +58,7 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
//With the implementation of some other plugins, initialization is not necessary,
//but maybe should be related to the dependency of key. For convenience, this is a conservative operation
override lazy val globalSettings: Seq[Def.Setting[_]] = Seq(
graphqlQueryIntrospectionResultPath := None,
graphqlSchemas := schemaFinderConfig,
jsonConfigurationFile := None,
graphqlSchemaPaths := Seq.empty,
......@@ -192,14 +193,18 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
val mappingConfigSupplier: JsonMappingConfigSupplier = buildJsonSupplier((jsonConfigurationFile in GraphQLCodegenConfig).value.orNull)
var result: Seq[File] = Seq.empty
try {
result = new GraphQLCodegen(getSchemas, (outputDir in GraphQLCodegenConfig).value, getMappingConfig().value, mappingConfigSupplier).generate.asScala
result = new GraphQLCodegen(
getSchemas,
(graphqlQueryIntrospectionResultPath in GraphQLCodegenConfig).value.orNull,
(outputDir in GraphQLCodegenConfig).value,
getMappingConfig().value,
mappingConfigSupplier).generate.asScala
for (file result) {
sLog.value.success(s"${file.getName}")
}
} catch {
case e: Exception
sLog.value.debug(s"${e.getStackTrace}")
throw new Exception("Code generation failed. See above for the full exception.")
throw new Exception(s"${e.getLocalizedMessage}")
}
def getSchemas: util.List[String] = {
......
......@@ -52,30 +52,45 @@ import static java.util.stream.Collectors.toList;
public class GraphQLCodegen {
private final List<String> schemas;
private final String introspectionResult;
private final File outputDir;
private final MappingConfig mappingConfig;
private final GeneratedInformation generatedInformation;
// used in tests
public GraphQLCodegen(List<String> schemas,
File outputDir,
MappingConfig mappingConfig,
GeneratedInformation generatedInformation) {
this(schemas, outputDir, mappingConfig, null, generatedInformation);
this(schemas, null, outputDir, mappingConfig, null, generatedInformation);
}
// used in tests
public GraphQLCodegen(String introspectionResult,
File outputDir,
MappingConfig mappingConfig,
GeneratedInformation generatedInformation) {
this(null, introspectionResult, outputDir, mappingConfig, null, generatedInformation);
}
// used in plugins
public GraphQLCodegen(List<String> schemas,
String introspectionResult,
File outputDir,
MappingConfig mappingConfig,
MappingConfigSupplier externalMappingConfigSupplier) {
this(schemas, outputDir, mappingConfig, externalMappingConfigSupplier, new GeneratedInformation());
this(schemas, introspectionResult, outputDir, mappingConfig, externalMappingConfigSupplier, new GeneratedInformation());
}
// used by other constructors
public GraphQLCodegen(List<String> schemas,
String introspectionResult,
File outputDir,
MappingConfig mappingConfig,
MappingConfigSupplier externalMappingConfigSupplier,
GeneratedInformation generatedInformation) {
this.schemas = schemas;
this.introspectionResult = introspectionResult;
this.outputDir = outputDir;
this.mappingConfig = mappingConfig;
this.mappingConfig.combine(externalMappingConfigSupplier != null ? externalMappingConfigSupplier.get() : null);
......@@ -155,7 +170,12 @@ public class GraphQLCodegen {
}
}
private static void validateConfigs(MappingConfig mappingConfig) {
private void validateConfigs(MappingConfig mappingConfig) {
if (!Utils.isEmpty(schemas) && introspectionResult != null ||
(Utils.isEmpty(schemas) && introspectionResult == null)) {
// either schemas or introspection result should be provided
throw new IllegalArgumentException("Either graphql schema path or introspection result path should be supplied");
}
if (mappingConfig.getApiRootInterfaceStrategy() == ApiRootInterfaceStrategy.INTERFACE_PER_SCHEMA &&
mappingConfig.getApiNamePrefixStrategy() == ApiNamePrefixStrategy.CONSTANT) {
// we will have a conflict in case there is "type Query" in multiple graphql schema files
......@@ -205,13 +225,20 @@ public class GraphQLCodegen {
GraphQLCodegenFileCreator.prepareOutputDir(outputDir);
long startTime = System.currentTimeMillis();
List<File> generatedFiles = Collections.emptyList();
if (!schemas.isEmpty()) {
ExtendedDocument document = GraphQLDocumentParser.getDocument(mappingConfig, schemas);
if (!Utils.isEmpty(schemas)) {
ExtendedDocument document = GraphQLDocumentParser.getDocumentFromSchemas(mappingConfig, schemas);
initCustomTypeMappings(document.getScalarDefinitions());
generatedFiles = processDefinitions(document);
System.out.println(String.format("Finished processing %d schema(s) in %d ms", schemas.size(),
System.currentTimeMillis() - startTime));
} else if (introspectionResult != null) {
ExtendedDocument document = GraphQLDocumentParser.getDocumentFromIntrospectionResult(mappingConfig, introspectionResult);
initCustomTypeMappings(document.getScalarDefinitions());
generatedFiles = processDefinitions(document);
System.out.println(String.format("Finished processing introspection result in %d ms",
System.currentTimeMillis() - startTime));
}
long elapsed = System.currentTimeMillis() - startTime;
System.out.println(String.format("Finished processing %d schema(s) in %d ms", schemas.size(), elapsed));
return generatedFiles;
}
......
package com.kobylynskyi.graphql.codegen;
import com.fasterxml.jackson.core.type.TypeReference;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedDefinition;
import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedDocument;
......@@ -10,6 +11,7 @@ import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedObjectTypeDefin
import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedScalarTypeDefinition;
import com.kobylynskyi.graphql.codegen.model.definitions.ExtendedUnionTypeDefinition;
import com.kobylynskyi.graphql.codegen.utils.Utils;
import graphql.introspection.IntrospectionResultToSchema;
import graphql.language.Definition;
import graphql.language.Document;
import graphql.language.EnumTypeDefinition;
......@@ -41,7 +43,7 @@ class GraphQLDocumentParser {
private GraphQLDocumentParser() {
}
static ExtendedDocument getDocument(MappingConfig mappingConfig, List<String> schemaPaths) throws IOException {
static ExtendedDocument getDocumentFromSchemas(MappingConfig mappingConfig, List<String> schemaPaths) throws IOException {
Document document = readDocument(schemaPaths);
ExtendedDocumentBuilder extendedDocumentBuilder = new ExtendedDocumentBuilder();
......@@ -52,6 +54,25 @@ class GraphQLDocumentParser {
return extendedDocumentBuilder.build();
}
static ExtendedDocument getDocumentFromIntrospectionResult(MappingConfig mappingConfig, String introspectionResult) throws IOException {
String introspectionResultContent = Utils.getFileContent(introspectionResult);
Map<String, Object> introspectionResultMap = Utils.OBJECT_MAPPER.readValue(introspectionResultContent,
new TypeReference<Map<String, Object>>() {
});
// unwrapping "data" (in case such GraphQL response supplied)
if (introspectionResultMap.containsKey("data")) {
introspectionResultMap = (Map<String, Object>) introspectionResultMap.get("data");
}
Document document = new IntrospectionResultToSchema().createSchemaDefinition(introspectionResultMap);
ExtendedDocumentBuilder extendedDocumentBuilder = new ExtendedDocumentBuilder();
for (Definition<?> definition : document.getDefinitions()) {
processDefinition(mappingConfig, extendedDocumentBuilder, definition);
}
return extendedDocumentBuilder.build();
}
private static void processDefinition(MappingConfig mappingConfig, ExtendedDocumentBuilder extendedDocumentBuilder, Definition<?> definition) {
if (!(definition instanceof NamedNode)) {
// the only definition that does not have a name is SchemaDefinition, so skipping it
......
package com.kobylynskyi.graphql.codegen.model.definitions;
import graphql.language.Node;
import graphql.language.ObjectTypeDefinition;
import graphql.language.ObjectTypeExtensionDefinition;
......@@ -45,16 +46,26 @@ public class ExtendedObjectTypeDefinition extends ExtendedImplementingTypeDefini
private Map<String, ExtendedObjectTypeDefinition> groupBySourceLocation(Function<File, String> fileStringFunction) {
Map<String, ExtendedObjectTypeDefinition> definitionMap = new HashMap<>();
if (definition != null) {
File file = new File(definition.getSourceLocation().getSourceName());
File file = new File(getSourceLocationName(definition));
definitionMap.computeIfAbsent(fileStringFunction.apply(file), d -> new ExtendedObjectTypeDefinition())
.setDefinition(definition);
}
for (ObjectTypeExtensionDefinition extension : extensions) {
File file = new File(extension.getSourceLocation().getSourceName());
File file = new File(getSourceLocationName(extension));
definitionMap.computeIfAbsent(fileStringFunction.apply(file), d -> new ExtendedObjectTypeDefinition())
.getExtensions().add(extension);
}
return definitionMap;
}
/**
* Get source location of the node.
* In some cases Node does not have a source location defined, so returning "unknown"
*
* @return source location if present or "unknown" otherwise
*/
private static String getSourceLocationName(Node<?> node) {
return node.getSourceLocation() != null ? node.getSourceLocation().getSourceName() : "unknown";
}
}
package com.kobylynskyi.graphql.codegen.supplier;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.utils.Utils;
import java.io.File;
import java.io.IOException;
......@@ -13,8 +13,6 @@ import java.io.IOException;
*/
public class JsonMappingConfigSupplier implements MappingConfigSupplier {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private final String jsonConfigFile;
/**
......@@ -30,7 +28,7 @@ public class JsonMappingConfigSupplier implements MappingConfigSupplier {
public MappingConfig get() {
if (jsonConfigFile != null && !jsonConfigFile.isEmpty()) {
try {
return OBJECT_MAPPER.readValue(new File(jsonConfigFile), MappingConfig.class);
return Utils.OBJECT_MAPPER.readValue(new File(jsonConfigFile), MappingConfig.class);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
......
package com.kobylynskyi.graphql.codegen.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kobylynskyi.graphql.codegen.model.exception.UnableToCreateDirectoryException;
import com.kobylynskyi.graphql.codegen.model.exception.UnableToDeleteDirectoryException;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation;
......@@ -18,6 +19,8 @@ import java.util.Objects;
*/
public final class Utils {
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private Utils() {
}
......
package com.kobylynskyi.graphql.codegen;
import com.kobylynskyi.graphql.codegen.model.ApiNamePrefixStrategy;
import com.kobylynskyi.graphql.codegen.model.ApiRootInterfaceStrategy;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.utils.Utils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import static com.kobylynskyi.graphql.codegen.TestUtils.assertSameTrimmedContent;
import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
class GraphQLCodegenIntrospectionResultTest {
private final File outputBuildDir = new File("build/generated");
private final File outputJavaClassesDir = new File("build/generated/com/kobylynskyi/graphql/test1");
private MappingConfig mappingConfig;
@BeforeEach
void init() {
mappingConfig = new MappingConfig();
mappingConfig.setPackageName("com.kobylynskyi.graphql.test1");
mappingConfig.setGenerateClient(true);
}
@AfterEach
void cleanup() {
Utils.deleteDir(outputBuildDir);
}
@Test
void generateClientFromIntrospectionResult() throws Exception {
new GraphQLCodegen("src/test/resources/introspection-result/sample-introspection-query-result.json",
outputBuildDir, mappingConfig, TestUtils.getStaticGeneratedInfo()).generate();
checkGeneratedFiles();
}
@Test
void generateClientFromIntrospectionResultWrappedInData() throws Exception {
new GraphQLCodegen("src/test/resources/introspection-result/sample-introspection-query-result-wrapped.json",
outputBuildDir, mappingConfig, TestUtils.getStaticGeneratedInfo()).generate();
checkGeneratedFiles();
}
@Test
void generateClientFromIntrospectionResult_SetApiStrategies() throws Exception {
mappingConfig.setApiRootInterfaceStrategy(ApiRootInterfaceStrategy.INTERFACE_PER_SCHEMA);
mappingConfig.setApiNamePrefixStrategy(ApiNamePrefixStrategy.FOLDER_NAME_AS_PREFIX);
new GraphQLCodegen("src/test/resources/introspection-result/sample-introspection-query-result.json",
outputBuildDir, mappingConfig, TestUtils.getStaticGeneratedInfo()).generate();
checkGeneratedFiles();
}
private void checkGeneratedFiles() throws IOException {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
List<String> generatedFileNames = Arrays.stream(files).map(File::getName).sorted().collect(toList());
assertEquals(Arrays.asList("CreateMutationRequest.java", "CreateMutationResolver.java",
"CreateMutationResponse.java", "MutationResolver.java", "Product.java", "ProductByIdQueryRequest.java",
"ProductByIdQueryResolver.java", "ProductByIdQueryResponse.java", "ProductInput.java",
"ProductResponseProjection.java", "ProductsByIdsQueryRequest.java", "ProductsByIdsQueryResolver.java",
"ProductsByIdsQueryResponse.java", "ProductsQueryRequest.java", "ProductsQueryResolver.java",
"ProductsQueryResponse.java", "QueryResolver.java", "StockStatus.java"), generatedFileNames);
for (File file : files) {
File expected = new File(String.format("src/test/resources/expected-classes/from-introspection-result/%s.txt", file.getName()));
assertSameTrimmedContent(expected, file);
}
}
}
package com.kobylynskyi.graphql.codegen;
import com.kobylynskyi.graphql.codegen.model.GeneratedInformation;
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
import com.kobylynskyi.graphql.codegen.utils.Utils;
import org.hamcrest.core.StringContains;
......@@ -225,12 +226,11 @@ class GraphQLCodegenTest {
}
@Test
void generate_NoSchemas() throws Exception {
new GraphQLCodegen(emptyList(),
outputBuildDir, mappingConfig, TestUtils.getStaticGeneratedInfo()).generate();
File[] files = Objects.requireNonNull(outputBuildDir.listFiles());
assertEquals(0, files.length);
void generate_NoSchemas() {
GeneratedInformation staticGeneratedInfo = TestUtils.getStaticGeneratedInfo();
List<String> schemas = emptyList();
assertThrows(IllegalArgumentException.class, () ->
new GraphQLCodegen(schemas, outputBuildDir, mappingConfig, staticGeneratedInfo));
}
@Test
......@@ -239,6 +239,8 @@ class GraphQLCodegenTest {
outputBuildDir, mappingConfig, TestUtils.getStaticGeneratedInfo());
assertThrows(NoSuchFileException.class, graphQLCodegen::generate);
assertEquals(0, Objects.requireNonNull(outputBuildDir.listFiles()).length);
}
@Test
......
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class CreateMutationRequest implements GraphQLOperationRequest {
private static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.MUTATION;
private static final String OPERATION_NAME = "create";
private Map<String, Object> input = new LinkedHashMap<>();
public CreateMutationRequest() {
}
public void setProductInput(ProductInput productInput) {
this.input.put("productInput", productInput);
}
@Override
public GraphQLOperation getOperationType() {
return OPERATION_TYPE;
}
@Override
public String getOperationName() {
return OPERATION_NAME;
}
@Override
public Map<String, Object> getInput() {
return input;
}
@Override
public String toString() {
return Objects.toString(input);
}
public static class Builder {
private ProductInput productInput;
public Builder() {
}
public Builder setProductInput(ProductInput productInput) {
this.productInput = productInput;
return this;
}
public CreateMutationRequest build() {
CreateMutationRequest obj = new CreateMutationRequest();
obj.setProductInput(productInput);
return obj;
}
}
}
package com.kobylynskyi.graphql.test1;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public interface CreateMutationResolver {
Product create(ProductInput productInput) throws Exception;
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult;
import java.util.Map;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class CreateMutationResponse extends GraphQLResult<Map<String, Product>> {
private static final String OPERATION_NAME = "create";
public CreateMutationResponse() {
}
public Product create() {
Map<String, Product> data = getData();
return data != null ? data.get(OPERATION_NAME) : null;
}
}
package com.kobylynskyi.graphql.test1;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public interface MutationResolver {
Product create(ProductInput productInput) throws Exception;
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer;
import java.util.StringJoiner;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class Product implements java.io.Serializable {
@javax.validation.constraints.NotNull
private String id;
@javax.validation.constraints.NotNull
private String title;
private String description;
@javax.validation.constraints.NotNull
private String price;
@javax.validation.constraints.NotNull
private String sku;
private StockStatus stockStatus;
@javax.validation.constraints.NotNull
private String addedDateTime;
public Product() {
}
public Product(String id, String title, String description, String price, String sku, StockStatus stockStatus, String addedDateTime) {
this.id = id;
this.title = title;
this.description = description;
this.price = price;
this.sku = sku;
this.stockStatus = stockStatus;
this.addedDateTime = addedDateTime;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public StockStatus getStockStatus() {
return stockStatus;
}
public void setStockStatus(StockStatus stockStatus) {
this.stockStatus = stockStatus;
}
public String getAddedDateTime() {
return addedDateTime;
}
public void setAddedDateTime(String addedDateTime) {
this.addedDateTime = addedDateTime;
}
@Override
public String toString() {
StringJoiner joiner = new StringJoiner(", ", "{ ", " }");
if (id != null) {
joiner.add("id: " + GraphQLRequestSerializer.getEntry(id));
}
if (title != null) {
joiner.add("title: " + GraphQLRequestSerializer.getEntry(title));
}
if (description != null) {
joiner.add("description: " + GraphQLRequestSerializer.getEntry(description));
}
if (price != null) {
joiner.add("price: " + GraphQLRequestSerializer.getEntry(price));
}
if (sku != null) {
joiner.add("sku: " + GraphQLRequestSerializer.getEntry(sku));
}
if (stockStatus != null) {
joiner.add("stockStatus: " + GraphQLRequestSerializer.getEntry(stockStatus));
}
if (addedDateTime != null) {
joiner.add("addedDateTime: " + GraphQLRequestSerializer.getEntry(addedDateTime));
}
return joiner.toString();
}
public static Product.Builder builder() {
return new Product.Builder();
}
public static class Builder {
private String id;
private String title;
private String description;
private String price;
private String sku;
private StockStatus stockStatus;
private String addedDateTime;
public Builder() {
}
public Builder setId(String id) {
this.id = id;
return this;
}
public Builder setTitle(String title) {
this.title = title;
return this;
}
public Builder setDescription(String description) {
this.description = description;
return this;
}
public Builder setPrice(String price) {
this.price = price;
return this;
}
public Builder setSku(String sku) {
this.sku = sku;
return this;
}
public Builder setStockStatus(StockStatus stockStatus) {
this.stockStatus = stockStatus;
return this;
}
public Builder setAddedDateTime(String addedDateTime) {
this.addedDateTime = addedDateTime;
return this;
}
public Product build() {
return new Product(id, title, description, price, sku, stockStatus, addedDateTime);
}
}
}
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductByIdQueryRequest implements GraphQLOperationRequest {
private static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.QUERY;
private static final String OPERATION_NAME = "productById";
private Map<String, Object> input = new LinkedHashMap<>();
public ProductByIdQueryRequest() {
}
public void setId(String id) {
this.input.put("id", id);
}
@Override
public GraphQLOperation getOperationType() {
return OPERATION_TYPE;
}
@Override
public String getOperationName() {
return OPERATION_NAME;
}
@Override
public Map<String, Object> getInput() {
return input;
}
@Override
public String toString() {
return Objects.toString(input);
}
public static class Builder {
private String id;
public Builder() {
}
public Builder setId(String id) {
this.id = id;
return this;
}
public ProductByIdQueryRequest build() {
ProductByIdQueryRequest obj = new ProductByIdQueryRequest();
obj.setId(id);
return obj;
}
}
}
package com.kobylynskyi.graphql.test1;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public interface ProductByIdQueryResolver {
Product productById(String id) throws Exception;
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult;
import java.util.Map;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductByIdQueryResponse extends GraphQLResult<Map<String, Product>> {
private static final String OPERATION_NAME = "productById";
public ProductByIdQueryResponse() {
}
public Product productById() {
Map<String, Product> data = getData();
return data != null ? data.get(OPERATION_NAME) : null;
}
}
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer;
import java.util.StringJoiner;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductInput implements java.io.Serializable {
@javax.validation.constraints.NotNull
private String title;
private String description;
@javax.validation.constraints.NotNull
private String price;
@javax.validation.constraints.NotNull
private String sku;
private StockStatus stockStatus;
public ProductInput() {
}
public ProductInput(String title, String description, String price, String sku, StockStatus stockStatus) {
this.title = title;
this.description = description;
this.price = price;
this.sku = sku;
this.stockStatus = stockStatus;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public StockStatus getStockStatus() {
return stockStatus;
}
public void setStockStatus(StockStatus stockStatus) {
this.stockStatus = stockStatus;
}
@Override
public String toString() {
StringJoiner joiner = new StringJoiner(", ", "{ ", " }");
if (title != null) {
joiner.add("title: " + GraphQLRequestSerializer.getEntry(title));
}
if (description != null) {
joiner.add("description: " + GraphQLRequestSerializer.getEntry(description));
}
if (price != null) {
joiner.add("price: " + GraphQLRequestSerializer.getEntry(price));
}
if (sku != null) {
joiner.add("sku: " + GraphQLRequestSerializer.getEntry(sku));
}
if (stockStatus != null) {
joiner.add("stockStatus: " + GraphQLRequestSerializer.getEntry(stockStatus));
}
return joiner.toString();
}
public static ProductInput.Builder builder() {
return new ProductInput.Builder();
}
public static class Builder {
private String title;
private String description;
private String price;
private String sku;
private StockStatus stockStatus;
public Builder() {
}
public Builder setTitle(String title) {
this.title = title;
return this;
}
public Builder setDescription(String description) {
this.description = description;
return this;
}
public Builder setPrice(String price) {
this.price = price;
return this;
}
public Builder setSku(String sku) {
this.sku = sku;
return this;
}
public Builder setStockStatus(StockStatus stockStatus) {
this.stockStatus = stockStatus;
return this;
}
public ProductInput build() {
return new ProductInput(title, description, price, sku, stockStatus);
}
}
}
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseField;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection;
/**
* Response projection for Product
*/
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductResponseProjection extends GraphQLResponseProjection {
public ProductResponseProjection() {
}
public ProductResponseProjection id() {
return id(null);
}
public ProductResponseProjection id(String alias) {
fields.add(new GraphQLResponseField("id").alias(alias));
return this;
}
public ProductResponseProjection title() {
return title(null);
}
public ProductResponseProjection title(String alias) {
fields.add(new GraphQLResponseField("title").alias(alias));
return this;
}
public ProductResponseProjection description() {
return description(null);
}
public ProductResponseProjection description(String alias) {
fields.add(new GraphQLResponseField("description").alias(alias));
return this;
}
public ProductResponseProjection price() {
return price(null);
}
public ProductResponseProjection price(String alias) {
fields.add(new GraphQLResponseField("price").alias(alias));
return this;
}
public ProductResponseProjection sku() {
return sku(null);
}
public ProductResponseProjection sku(String alias) {
fields.add(new GraphQLResponseField("sku").alias(alias));
return this;
}
public ProductResponseProjection stockStatus() {
return stockStatus(null);
}
public ProductResponseProjection stockStatus(String alias) {
fields.add(new GraphQLResponseField("stockStatus").alias(alias));
return this;
}
public ProductResponseProjection addedDateTime() {
return addedDateTime(null);
}
public ProductResponseProjection addedDateTime(String alias) {
fields.add(new GraphQLResponseField("addedDateTime").alias(alias));
return this;
}
public ProductResponseProjection typename() {
return typename(null);
}
public ProductResponseProjection typename(String alias) {
fields.add(new GraphQLResponseField("__typename").alias(alias));
return this;
}
}
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductsByIdsQueryRequest implements GraphQLOperationRequest {
private static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.QUERY;
private static final String OPERATION_NAME = "productsByIds";
private Map<String, Object> input = new LinkedHashMap<>();
public ProductsByIdsQueryRequest() {
}
public void setIds(java.util.List<String> ids) {
this.input.put("ids", ids);
}
@Override
public GraphQLOperation getOperationType() {
return OPERATION_TYPE;
}
@Override
public String getOperationName() {
return OPERATION_NAME;
}
@Override
public Map<String, Object> getInput() {
return input;
}
@Override
public String toString() {
return Objects.toString(input);
}
public static class Builder {
private java.util.List<String> ids;
public Builder() {
}
public Builder setIds(java.util.List<String> ids) {
this.ids = ids;
return this;
}
public ProductsByIdsQueryRequest build() {
ProductsByIdsQueryRequest obj = new ProductsByIdsQueryRequest();
obj.setIds(ids);
return obj;
}
}
}
package com.kobylynskyi.graphql.test1;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public interface ProductsByIdsQueryResolver {
java.util.List<Product> productsByIds(java.util.List<String> ids) throws Exception;
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult;
import java.util.Map;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductsByIdsQueryResponse extends GraphQLResult<Map<String, java.util.List<Product>>> {
private static final String OPERATION_NAME = "productsByIds";
public ProductsByIdsQueryResponse() {
}
public java.util.List<Product> productsByIds() {
Map<String, java.util.List<Product>> data = getData();
return data != null ? data.get(OPERATION_NAME) : null;
}
}
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductsQueryRequest implements GraphQLOperationRequest {
private static final GraphQLOperation OPERATION_TYPE = GraphQLOperation.QUERY;
private static final String OPERATION_NAME = "products";
private Map<String, Object> input = new LinkedHashMap<>();
public ProductsQueryRequest() {
}
@Override
public GraphQLOperation getOperationType() {
return OPERATION_TYPE;
}
@Override
public String getOperationName() {
return OPERATION_NAME;
}
@Override
public Map<String, Object> getInput() {
return input;
}
@Override
public String toString() {
return Objects.toString(input);
}
public static class Builder {
public Builder() {
}
public ProductsQueryRequest build() {
ProductsQueryRequest obj = new ProductsQueryRequest();
return obj;
}
}
}
package com.kobylynskyi.graphql.test1;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public interface ProductsQueryResolver {
java.util.List<Product> products() throws Exception;
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult;
import java.util.Map;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class ProductsQueryResponse extends GraphQLResult<Map<String, java.util.List<Product>>> {
private static final String OPERATION_NAME = "products";
public ProductsQueryResponse() {
}
public java.util.List<Product> products() {
Map<String, java.util.List<Product>> data = getData();
return data != null ? data.get(OPERATION_NAME) : null;
}
}
package com.kobylynskyi.graphql.test1;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public interface QueryResolver {
java.util.List<Product> products() throws Exception;
Product productById(String id) throws Exception;
java.util.List<Product> productsByIds(java.util.List<String> ids) throws Exception;
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public enum StockStatus {
IN_STOCK("IN_STOCK"),
SPECIAL_ORDER("SPECIAL_ORDER"),
BACK_ORDERED("BACK_ORDERED"),
COMING_SOON("COMING_SOON"),
SOLD_OUT("SOLD_OUT"),
DISCONTINUED("DISCONTINUED");
private final String graphqlName;
private StockStatus(String graphqlName) {
this.graphqlName = graphqlName;
}
@Override
public String toString() {
return this.graphqlName;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册