CN117493610A - GraphQL parameter generation method and system based on java implementation - Google Patents

GraphQL parameter generation method and system based on java implementation Download PDF

Info

Publication number
CN117493610A
CN117493610A CN202311553034.9A CN202311553034A CN117493610A CN 117493610 A CN117493610 A CN 117493610A CN 202311553034 A CN202311553034 A CN 202311553034A CN 117493610 A CN117493610 A CN 117493610A
Authority
CN
China
Prior art keywords
parameter
graphql
java
entity class
class
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311553034.9A
Other languages
Chinese (zh)
Inventor
李翱成
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Lan You Technology Co Ltd
Original Assignee
Shenzhen Lan You Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Lan You Technology Co Ltd filed Critical Shenzhen Lan You Technology Co Ltd
Priority to CN202311553034.9A priority Critical patent/CN117493610A/en
Publication of CN117493610A publication Critical patent/CN117493610A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a graph QL parameter generation method based on java implementation, which comprises the following steps: selecting java entity class to be converted and corresponding parameter type mapping configuration; based on the selected parameter type mapping configuration, converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle; and printing and outputting the GraphQL parameter body. The invention is based on the java reflection principle, does not need to pay attention to a specific class or object, obtains all attribute field names and types through the packet names of the java entity class transmitted by a user in the process of program operation, converts all attribute types by using the configured types through the streaming processing of java, and finally splices the attribute types into a designated graphQL parameter format for printing and outputting; therefore, when a developer needs to maintain a plurality of sets of parameter bodies in the development process and the graphQL format is needed to be used in project engineering, the method can be used for directly generating the graphQL parameters from java entity classes, so that the development cost is reduced, and the development efficiency is improved.

Description

GraphQL parameter generation method and system based on java implementation
Technical Field
The invention relates to the technical field of computers, in particular to a graph QL parameter generation method and system based on java implementation.
Background
In some JAVA projects, the API application program interface parameters are not DTO (JAVA data transfer object) of the main stream, but GraphQL (graphical data query language) is used for parameter transfer. The result set returned by the API is returned by way of java entity class, which results in that the developer needs to maintain two sets of different parameter bodies of the input parameter and the output parameter in the development process of the API. This greatly increases unnecessary development costs, especially in the case of relatively large parameters and more or less in-out fields.
Based on this, a new solution is needed.
Disclosure of Invention
The invention mainly aims to solve the problems that in the prior art, when new API development is carried out, two sets of parameter bodies of a graph QL input parameter body and a java entity type output parameter body are required to be manually maintained, so that a developer has large workload and high cost which are irrelevant to service function development, and two sets of parameter bodies are required to be maintained during modification, omission is easy and flexibility is not enough, and provides a graph QL parameter generation method and a graph QL parameter generation system based on java implementation.
In order to achieve the above purpose, the present invention provides a GraphQL parameter generating method based on java implementation, which includes the following steps:
selecting java entity class to be converted and corresponding parameter type mapping configuration;
based on the selected parameter type mapping configuration, converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle; and
and printing and outputting the GraphQL parameter body.
In the graph ql parameter generation method based on java implementation provided by the invention, the step of converting the selected java entity class into the graph ql parameter body by using the java reflection principle based on the selected parameter type mapping configuration comprises the following steps:
obtaining class names of the java entity class and field names of a plurality of attributes through reflection;
converting the field types of the attributes of the java entity class into corresponding GraphQL parameter field types by using the selected parameter type mapping configuration and the field names of the attributes;
and splicing the class names of the java entity class, the field names of the plurality of attributes and the mapped field types according to a GraphQL parameter format to obtain the GraphQL parameter body.
In the graph QL parameter generation method based on java implementation provided by the invention, before the step of selecting the java entity class to be converted and the required parameter type mapping configuration, the method further comprises the following steps:
setting a plurality of parameter type mapping configurations between the java entity class and the graphQL parameter body.
The graphQL parameter generation method based on java implementation provided by the invention further comprises the following steps:
in the step of printing and outputting the GraphQL parameter body, the GraphQL parameter body is output through a console printing or a file-to-disk mode generated through IO.
In addition, in order to achieve the above purpose, the present invention also provides a GraphQL parameter generating system based on java implementation, including:
the selection module is used for selecting java entity class to be converted and corresponding parameter type mapping configuration;
the conversion module is used for converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle based on the selected parameter type mapping configuration; and
and the output module is used for printing and outputting the GraphQL parameter body.
In the GraphQL parameter generating system based on java implementation provided by the invention, the conversion module comprises:
the obtaining unit is used for obtaining the class name of the java entity class and the field names and field types of a plurality of attributes through reflection;
the mapping unit is used for converting the field types of the plurality of attributes of the java entity class into corresponding GraphQL parameter field types by using the selected parameter type mapping configuration and the field names of the plurality of attributes;
the splicing unit is used for splicing the obtained class names of the java entity class, the field names of the plurality of attributes and the mapped field types according to a GraphQL parameter format to obtain the GraphQL parameter body.
The graphQL parameter generation system based on java implementation provided by the invention further comprises:
the setting module is used for setting a plurality of parameter type mapping configurations between the java entity class and the graphQL parameter body.
In the graphQL parameter generation system based on java implementation, the output module outputs the graphQL parameter body through a control console printing or through an IO file generation mode to a disk.
The invention also provides a graph QL parameter generating device based on java, which comprises a processor and a memory, wherein the memory stores a computer program, and the computer program realizes the steps of the graph QL parameter generating method based on java when being executed by the processor.
The present invention also provides a storage medium storing one or more programs executable by one or more processors to implement the steps of the java-based GraphQL parameter generating method as described above.
The graphQL parameter generation system and method based on java implementation provided by the invention have the following beneficial effects: the invention is based on the java reflection principle, does not need to pay attention to a specific class or object, obtains all attribute field names and types through the packet names of the java entity class transmitted by a user in the process of program operation, converts all attribute types by using the configured types through the streaming processing of java, and finally splices the attribute types into a designated graphQL parameter format for printing and outputting; therefore, when a developer needs to maintain a plurality of sets of parameter bodies in the development process and the graphQL format is needed to be used in project engineering, the method can be used for directly generating the graphQL parameters from java entity classes, so that the development cost is reduced, and the development efficiency is improved.
Drawings
For a clearer description of an embodiment of the invention or of a technical solution in the prior art, the drawings that are needed in the description of the embodiment or of the prior art will be briefly described, it being obvious that the drawings in the description below are only embodiments of the invention, and that other drawings can be obtained, without inventive effort, by a person skilled in the art from the drawings provided:
fig. 1 is a flowchart of a graph ql parameter generating method based on java implementation according to an embodiment of the present invention.
Detailed Description
In order that the invention may be readily understood, a more complete description of the invention will be rendered by reference to the appended drawings. Exemplary embodiments of the present invention are illustrated in the accompanying drawings. This invention may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
The invention has the following general ideas: aiming at the problems that two sets of parameter bodies of a graph QL input parameter and a java entity type output parameter are required to be manually maintained each time when new API development is carried out in the prior art, so that the workload of developers irrelevant to service function development is large, the cost is high, and two sets of parameter bodies are required to be maintained when modification is involved, omission is easy and the flexibility is not enough; therefore, when a developer needs to maintain a plurality of sets of parameter bodies in the development process and the graphQL format is needed to be used in project engineering, the method can be used for directly generating the graphQL parameters from java entity classes, so that the development cost is reduced, and the development efficiency is improved.
In order to better understand the above technical solutions, the following detailed description will be made with reference to the accompanying drawings and specific embodiments, and it should be understood that specific features in the embodiments and examples of the present invention are detailed descriptions of the technical solutions of the present application, and not limit the technical solutions of the present application, and the technical features in the embodiments and examples of the present invention may be combined with each other without conflict.
Fig. 1 is a flowchart of a graph ql parameter generating method based on java implementation according to an embodiment of the present invention. As shown in fig. 1, the GraphQL parameter generating method based on java implementation includes the following steps:
s1, selecting java entity class to be converted and corresponding parameter type mapping configuration;
specifically, in an embodiment of the present invention, because it is easy to miss and not flexible enough to maintain graph ql entry and java entity class exit in a system at the same time, firstly, a parameter type mapping relationship is established between the java entity class and the graph ql parameter, and the java entity class is converted to the corresponding graph ql parameter through different parameter type mapping configurations. Opening a configuration editor, selecting entity classes required to be converted in engineering, then enabling a user to configure the mapping between the java entity classes and the graphQL parameter types, and enabling the mapping relation configured before to be directly selected for subsequent use after the mapping relation is stored. For example, the java entity class parameter type "Integer" configuration is corresponding to the GraphQL parameter type "Int"; the java entity class parameter type 'long' configuration is corresponding to the GraphQL parameter type 'Int'; the java entity class parameter type "Date" configuration is corresponding to the GraphQL parameter type "LocalDateTime". By configuring different mapping relations, various mapping relations can be established between the java entity class and the graphQL parameter class, and the mapping relations can be selected according to user requirements when the mapping relation is used. The mapping configuration by parameter type can help simplify the maintenance of code and ensure the correct conversion of data between Java entity class and GraphQL parameters. By establishing a flexible mapping relation between Java entity classes and GraphQL parameters, maintenance and development work of the system are simplified. Meanwhile, the system has expansibility and adaptability, and can better cope with future demand changes.
S2, based on the selected parameter type mapping configuration, converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle;
specifically, in one embodiment of the present invention, java reflection refers to dynamically acquiring information of a class (such as class name, field, method, constructor, etc.) at runtime, and using this information to manipulate classes and objects. The reflection mechanism of Java provides a capability to examine and manipulate classes, interfaces, fields, and methods at runtime, which allows programs to obtain metadata information for code at runtime, and to instantiate objects, invoke methods, access or modify fields, etc. accordingly, the Java reflection mechanism provides a capability to examine and manipulate classes, interfaces, fields, and methods at runtime. The java reflection does not pay attention to a specific class or object, all attribute field names and types are obtained through the packet names of the classes transmitted by the user in the process of program operation, all attribute types are converted through the java streaming process, and finally the attribute types are spliced into a designated graphQL parameter format to be printed and output. Thus, step S2 comprises:
s21, obtaining a class name of the java entity class and field names and field types of a plurality of attributes through reflection;
s22, converting the field types of the attributes of the java entity class into corresponding GraphQL parameter field types by using the selected parameter type mapping configuration and the field names of the attributes;
and S23, splicing the obtained class names of the java entity class, the field names of the plurality of attributes and the mapped field types according to a GraphQL parameter format to obtain the GraphQL parameter body.
Specifically, in an embodiment of the present invention, a Class (a reflection Class after compiling an entity) of a java entity Class is input at an entry of an parsing method, and a Class name corresponding to the java entity Class is obtained by a getSimpleName () method in the Class; and obtaining all fields of the class declaration through a getDeclarked fields () method, finally obtaining the names and types of the fields through fields.
Step S3, printing and outputting the GraphQL parameter body;
specifically, in an embodiment of the present invention, the GraphQL parameter body is output by printing through a console or by generating a file to a disk through IO. If the generated GraphQL parameter needs to be simply and quickly debugged and checked, a console printing mode can be selected, and the constructed GraphQL parameter body is output to the console by using a system. If long-term preservation of the parameter body is required, the manner of IO generating the file to the disk can be selected, by creating a file object and writing the parameter into the file, and then the file is saved to the disk. The following is a part of the code printed out by the console:
type SrmBaseSupplyList{
supplyName:String,
estDate:LocalDateTime,
linkPhone:String,
isEnsure:string,
bizLicense:String,
remark:String,
delFlag:String,
linkMan:String,
serialVersionUID:Int,
password:Strinq.
correspondingly, the invention also provides a graphQL parameter generation system based on java implementation, which comprises the following steps:
the setting module is used for setting a plurality of parameter type mapping configurations between the java entity class and the graphQL parameter body;
the selection module is used for selecting java entity class to be converted and corresponding parameter type mapping configuration;
the conversion module is used for converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle based on the selected parameter type mapping configuration; and
the output module is used for printing and outputting the GraphQL parameter body, and outputting the GraphQL parameter body in a mode of printing by a control console or generating a file to a disk by IO.
Specifically, in an embodiment of the present invention, the conversion module includes:
the obtaining unit is used for obtaining the class name of the java entity class and the field names and field types of a plurality of attributes through reflection;
the mapping unit is used for converting the field types of the plurality of attributes of the java entity class into corresponding GraphQL parameter field types by using the selected parameter type mapping configuration and the field names of the plurality of attributes;
the splicing unit is used for splicing the obtained class names of the java entity class, the field names of the plurality of attributes and the mapped field types according to a GraphQL parameter format to obtain the GraphQL parameter body.
The embodiment of the invention also provides a graphQL parameter generating device based on java implementation, which can comprise:
a memory for storing a computer program;
the processor, when executing the computer program stored in the memory, can implement the following steps:
selecting java entity class to be converted and corresponding parameter type mapping configuration; based on the selected parameter type mapping configuration, converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle; and printing and outputting the GraphQL parameter body.
The embodiment of the invention also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program can realize the following steps when being executed by a processor;
selecting java entity class to be converted and corresponding parameter type mapping configuration; based on the selected parameter type mapping configuration, converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle; and printing and outputting the GraphQL parameter body.
The computer readable storage medium may include: u disk, mobile hard disk, ROM (Read-Only Memory) > RAM (Random Access Memory, RAM), magnetic disk or optical disk, etc.
In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be construed as reflecting the intention that: i.e., the claimed invention requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the apparatus of the embodiments may be adaptively changed and disposed in one or more apparatuses different from the embodiments. The modules or units or components of the embodiments may be combined into one module or unit or component and, furthermore, they may be divided into a plurality of sub-modules or sub-units or sub-components. Any combination of all features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or units of any method or apparatus so disclosed, may be used in combination, except insofar as at least some of such features and/or processes or units are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings), may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments herein include some features but not others included in other embodiments, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments can be used in any combination.
Various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that some or all of the functions of some or all of the components in accordance with embodiments of the present invention may be implemented in practice using a microprocessor or Digital Signal Processor (DSP). The present invention can also be implemented as an apparatus or device program (e.g., a computer program and a computer program product) for performing a portion or all of the methods described herein. Such a program embodying the present invention may be stored on a computer readable medium, or may have the form of one or more signals. Such signals may be downloaded from an internet website, provided on a carrier signal, or provided in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The use of the words first, second, third, etc. do not denote any order. These words may be interpreted as names.

Claims (10)

1. The graphQL parameter generation method based on java implementation is characterized by comprising the following steps of:
selecting java entity class to be converted and corresponding parameter type mapping configuration;
based on the selected parameter type mapping configuration, converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle; and
and printing and outputting the GraphQL parameter body.
2. The method for generating GraphQL parameters based on java implementation as claimed in claim 1, wherein the step of converting the selected java entity class into GraphQL parameter body by using java reflection principle based on the selected parameter type mapping configuration comprises:
obtaining class names of the java entity class and field names of a plurality of attributes through reflection;
converting the field types of the attributes of the java entity class into corresponding GraphQL parameter field types by using the selected parameter type mapping configuration and the field names of the attributes;
and splicing the class names of the java entity class, the field names of the plurality of attributes and the mapped GraphQL parameter field types according to a GraphQL parameter format to obtain the GraphQL parameter body.
3. The method for generating GraphQL parameters based on java implementation as claimed in claim 1, further comprising, before the step of selecting the java entity class to be converted and the required parameter type mapping configuration:
setting a plurality of parameter type mapping configurations between the java entity class and the graphQL parameter body.
4. The java-based GraphQL parameter generating method according to claim 1, wherein in the step of printing out the GraphQL parameter body, the GraphQL parameter body is output by means of console printing or file to disk generation by IO.
5. The GraphQL parameter generation system based on java implementation is characterized by comprising:
the selection module is used for selecting java entity class to be converted and corresponding parameter type mapping configuration;
the conversion module is used for converting the selected java entity class into a GraphQL parameter body by utilizing a java reflection principle based on the selected parameter type mapping configuration; and
and the output module is used for printing and outputting the GraphQL parameter body.
6. The java based GraphQL parameter generation system according to claim 5, wherein the conversion module comprises:
the obtaining unit is used for obtaining the class name of the java entity class and the field names and field types of a plurality of attributes through reflection;
the mapping unit is used for converting the field types of the plurality of attributes of the java entity class into corresponding GraphQL parameter field types by using the selected parameter type mapping configuration and the field names of the plurality of attributes;
the splicing unit is used for splicing the class names of the java entity class, the field names of the plurality of attributes and the mapped GraphQL parameter field types according to a GraphQL parameter format to obtain the GraphQL parameter body.
7. The java based GraphQL parameter generating system according to claim 5, further comprising:
the setting module is used for setting a plurality of parameter type mapping configurations between the java entity class and the graphQL parameter body.
8. The java-based GraphQL parameter generating system according to claim 5, wherein the output module outputs the GraphQL parameter body by printing through a console or generating a file to a disk through IO.
9. A java-based GraphQL parameter generating apparatus, comprising a processor and a memory, the memory storing a computer program which, when executed by the processor, implements the steps of the java-based GraphQL parameter generating method according to any one of claims 1 to 4.
10. A storage medium storing one or more programs executable by one or more processors to implement the java-based GraphQL parameter generation method of any one of claims 1 to 4.
CN202311553034.9A 2023-11-20 2023-11-20 GraphQL parameter generation method and system based on java implementation Pending CN117493610A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311553034.9A CN117493610A (en) 2023-11-20 2023-11-20 GraphQL parameter generation method and system based on java implementation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311553034.9A CN117493610A (en) 2023-11-20 2023-11-20 GraphQL parameter generation method and system based on java implementation

Publications (1)

Publication Number Publication Date
CN117493610A true CN117493610A (en) 2024-02-02

Family

ID=89682730

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311553034.9A Pending CN117493610A (en) 2023-11-20 2023-11-20 GraphQL parameter generation method and system based on java implementation

Country Status (1)

Country Link
CN (1) CN117493610A (en)

Similar Documents

Publication Publication Date Title
CN110096338B (en) Intelligent contract execution method, device, equipment and medium
US7010796B1 (en) Methods and apparatus providing remote operation of an application programming interface
EP0709773B1 (en) System and method for generating target language code utilizing an object oriented code generator
JP4489483B2 (en) How to transform an initial type initial object into a final type final object
US8745584B2 (en) Dependency injection by static code generation
US8245191B2 (en) Policy application rules for automated configuration of software components
US9235495B2 (en) Method and system that provides an interactive debugging session
US10817284B2 (en) Melding of mediation flow service component architecture (SCA) components
CN108920496B (en) Rendering method and device
US7512938B2 (en) Typed intermediate representation for object-oriented languages
US20090328016A1 (en) Generalized expression trees
JP5811088B2 (en) Data processing system and data processing method
CN113900704A (en) Method and device for issuing application program installation package, readable medium and electronic equipment
US8918767B2 (en) Pattern-based compilation of asynchronous consumption
CN117493610A (en) GraphQL parameter generation method and system based on java implementation
JPH09179738A (en) Object-oriented language processing method and processor
US9015728B2 (en) Methods, apparatus, and systems to access runtime values of object instances
US9658838B2 (en) Optimized JavaServer Pages lifecycle model
CN117608708A (en) Back-end interface calling method, device, computing equipment and storage medium
GB2536402A (en) Workflow integration
JP5521616B2 (en) Transfer program generation device, transfer program generation method and program
CN115421700A (en) Method and device for converting fields, computer equipment and storage medium
CN115826945A (en) Service logic code implementation method and device
KR100772869B1 (en) Apparatus and method for automatically converting to component from library files of legacy module
Serrano et al. SERENITY aware system development process

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination