+

CN117172214A - API file conversion method, system and computer storage medium - Google Patents

API file conversion method, system and computer storage medium Download PDF

Info

Publication number
CN117172214A
CN117172214A CN202311444334.3A CN202311444334A CN117172214A CN 117172214 A CN117172214 A CN 117172214A CN 202311444334 A CN202311444334 A CN 202311444334A CN 117172214 A CN117172214 A CN 117172214A
Authority
CN
China
Prior art keywords
file
graphql
query language
image query
interface
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.)
Withdrawn
Application number
CN202311444334.3A
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.)
Qichacha Technology Co ltd
Original Assignee
Qichacha 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 Qichacha Technology Co ltd filed Critical Qichacha Technology Co ltd
Priority to CN202311444334.3A priority Critical patent/CN117172214A/en
Publication of CN117172214A publication Critical patent/CN117172214A/en
Withdrawn 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

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses an API file conversion method, an API file conversion system and a computer storage medium, wherein the file conversion method comprises the following steps: acquiring initial response data of a request for accessing a target resource; based on the language specification of the image query language GraphQL, carrying out data conversion on the initial response data to generate an image query language mode GraphQL Schema file; and analyzing and generating an image query language interface GraphQL API file by adopting a code generation method according to the image query language mode GraphQL Schema file. The method converts the initial response data based on the language specification of the image query language GraphQL to generate normalized data types and data operation methods, is convenient for quickly and accurately completing the conversion of the target resource interface data, and ensures that the styles of subsequently generated interface files are uniform; the whole process does not need to be manually participated, so that the development cost and the error rate are reduced, and the development efficiency and the automation degree of file conversion are improved.

Description

API file conversion method, system and computer storage medium
Technical Field
The present invention relates to the field of internet technologies, and in particular, to an API file conversion method, system, and computer storage medium.
Background
With the continuous updating and development of internet technology, the requirements of users on networks are continuously improved, in order to meet the increasingly changing demands of users and improve the experience effect of users, technicians are inevitably required to carry out optimization and upgrading on old service systems and service codes, and especially important system interfaces facing users are required to carry out comprehensive evaluation on existing systems by the technicians, and it is clear which modules or functions in the systems are seriously disjointed with the demands of current users, and interface file conversion is required to be completed in a preferential mode, so that the compatibility and stability of interface file conversion in new and old systems are required to be ensured.
The existing interface file conversion method can finish file conversion and system upgrading by manually modifying the code file by a technician or convert the old system file by using a code generation tool. The problems of missing code file modification, non-uniform code style, high error probability of newly-added files and repeatedly-modified files, poor compatibility and the like are very easy to occur in the methods, so that seamless conversion of the existing service is difficult to meet, the time cost and the labor cost of project development are greatly increased, and hidden danger is buried for later operation and maintenance; in addition, the existing method has higher requirements on professional knowledge and business knowledge of technicians, and the user experience effect is poor.
Disclosure of Invention
The invention aims to provide an API file conversion method, which solves the technical problems of non-uniform code style, high error rate, high development cost and low development efficiency in the prior art that the conversion of target resource interface data is completed manually.
It is an object of the present invention to provide an API file conversion system.
It is an object of the present invention to provide a computer storage medium.
In order to achieve one of the above objects, the present invention provides an API file conversion method comprising: acquiring initial response data of a request for accessing a target resource; based on the language specification of the image query language GraphQL, carrying out data conversion on the initial response data to generate an image query language mode GraphQL Schema file; the image query language mode GraphQL Schema file is used for defining the data structure type and the data operation method of an image query language interface GraphQL API; and analyzing and generating an image query language interface GraphQL API file by adopting a code generation method according to the image query language mode GraphQL Schema file.
As a further improvement of an embodiment of the invention, the image query language interface GraphQL API file at least comprises an image query language parser GraphQL resolution file and an image query language Service GraphQL Service file; the image query language analyzer GraphQL resolution file is used for defining an analysis method of each data field in the image query language mode GraphQL Schema file so as to acquire target resource data; the image query language Service GraphQL Service file is used for defining Service files required by the operation of an image query language interface GraphQL API so as to realize that the Service logic of the analysis method is called by the image query language analyzer GraphQL resolution file.
As a further improvement of an embodiment of the present invention, the "obtaining initial response data for requesting access to the target resource" specifically includes: acquiring an interface address and a request parameter for requesting to access the target resource; and requesting access to the target resource by adopting an interface data acquisition method according to the interface address and the request parameter, and obtaining initial response data corresponding to the request parameter.
As a further improvement of an embodiment of the present invention, the interface data acquisition method includes at least one of a presentation layer state transition Restful API data acquisition method, a Web Service data acquisition method, and a remote communication processor RCP data acquisition method; the data format of the initial response data comprises at least one of Json format, XML format and HTML format; the transcoding method includes at least one of a transcoding tool and an automated reconstruction tool.
As a further improvement of an embodiment of the present invention, the "obtaining the interface address and the request parameter for requesting to access the target resource" specifically includes: inquiring log service according to the interface address of the target resource, and at least obtaining a request parameter corresponding to the interface address; the "according to the interface address and the request parameter, the method for obtaining the initial response data corresponding to the access parameter by adopting the interface data obtaining method to request to access the target resource" specifically includes: constructing and sending an HTTP request according to the interface address and the request parameter; and receiving and analyzing response data corresponding to the HTTP request to obtain the initial response data.
As a further improvement of an embodiment of the present invention, the "generating the image query language mode GraphQL Schema file based on the language specification of the image query language GraphQL" specifically includes: analyzing the initial response data to obtain a plurality of field information and a plurality of field type information; based on the language specification of the image query language GraphQL, generating a plurality of image query language mode GraphQL Schema files by adopting a code conversion tool according to the data field information and the field type information; the code conversion tool comprises at least one of JSON2GraphQL and XSD2 GraphQL.
As a further improvement of an embodiment of the present invention, after the "generating several image query language modes GraphQL Schema files", the method further includes: constructing index files corresponding to the image query language mode GraphQL Schema files; the file names corresponding to the image query language mode GraphQL Schema files are all written into and updated to the index file; the step of analyzing and generating the image query language interface GraphQL API file by adopting a code generation method according to the image query language mode GraphQL Schema file specifically comprises the following steps: the index file is acquired and analyzed, and a plurality of image query language mode GraphQL Schema files are obtained through traversal and extraction; and generating the image query language interface GraphQL API file by adopting a code generation method according to each image query language mode GraphQL Schema file.
As a further improvement of an embodiment of the present invention, the "parsing and generating the image query language interface graphQL API file by using the code generation method according to the image query language mode graphQL Schema file" specifically includes: traversing and analyzing the image query language mode GraphQL Schema file to obtain a plurality of mode Schema objects; extracting corresponding data type information according to each mode Schema object; the data type information comprises a type name, a field list and a field type corresponding to the mode Schema object; and respectively generating a corresponding image query language interface GraphQL API file by adopting a code generation method according to each data type information and a corresponding preset template.
As a further improvement of an embodiment of the present invention, the image query language interface graphQL API file includes an image query language parser graphQL resolution file; the method for generating the corresponding image query language interface GraphQL API file by adopting the code generation method according to each data type information and the corresponding preset template specifically comprises the following steps: based on a preset parser resolution template, respectively generating corresponding image query language parser GraphQL resolution files by adopting a code generation method according to each data type information.
As a further improvement of an embodiment of the invention, the image query language interface GraphQL API file comprises an image query language Service GraphQL Service file; the step of generating the corresponding image query language interface GraphQL API file by adopting a code generation method according to the data type information and the corresponding preset template comprises the following steps: based on a preset Service interface template, respectively generating corresponding Service interface files by adopting a code generation method according to each data type information; based on a preset Service realization template, respectively generating corresponding Service realization files by adopting a code generation method according to each data type information; combining the Service interface file and the Service realization file to obtain the image query language Service GraphQL Service file; the Service interface file is used for defining an interface and comprises at least one of an interface name, an interface parameter and an interface return type; the Service realization file is used for realizing the business logic of each interface in the Service interface file.
To achieve one of the above objects, the present invention further provides an API file conversion system comprising: a client and a server; the server side is used for receiving and analyzing the query request sent by the client side; the initial response data is used for acquiring the target resource according to the query request; the method comprises the steps of executing data conversion operation according to initial response data to obtain an image query language mode GraphQL Schema file; the method is used for generating an image query language interface GraphQL API file according to the image query language mode GraphQL Schema file, and obtaining response data by calling service logic in the image query language interface GraphQL API file and sending the response data to the client.
As a further improvement of an embodiment of the invention, the client constructs a request file for executing access operation on the target resource according to the link address and the request access parameter of the target resource, and sends a request to the server by taking the request file as a medium.
In order to achieve one of the above objects, the present invention further provides a computer storage medium including a memory and a processor, wherein the memory stores a computer program, and the computer program, when executed by the processor, causes the processor to execute the steps of the above API file conversion method.
Compared with the prior art, the embodiment of the invention has at least one of the following beneficial effects:
the method adopts an API file conversion method, and can ensure the accuracy of the subsequent data conversion by directly acquiring the initial response data of the request access target resource; based on the language specification of the image query language GraphQL, converting the initial response data to generate normalized data types and data operation methods, so that the conversion of the target resource interface data can be conveniently and accurately completed, and the styles of subsequently generated interface files are unified; the whole process does not need to be manually participated, so that the development cost and the error rate are reduced, and the development efficiency and the automation degree of file conversion are improved.
Drawings
FIG. 1 is a schematic diagram illustrating steps of an API file conversion method according to an embodiment of the present invention.
Fig. 2 is a schematic diagram illustrating a refinement step of step S1 of the API file conversion method according to an embodiment of the present invention.
Fig. 3 is a schematic diagram illustrating a part of steps of an API file conversion method according to a first embodiment of the present invention.
Fig. 4 is a schematic diagram illustrating a part of steps of an API file conversion method according to a second embodiment of the present invention.
Fig. 5 is a schematic diagram illustrating a refinement step of step S3 of the API file conversion method according to an embodiment of the present invention.
Fig. 6 is a schematic diagram illustrating a refinement step of step S33 of the API file conversion method according to an embodiment of the present invention.
Detailed Description
The present invention will be described in detail below with reference to specific embodiments shown in the drawings. These embodiments are not intended to limit the invention and structural, methodological, or functional modifications of these embodiments that may be made by one of ordinary skill in the art are included within the scope of the invention.
It should be noted that the term "comprises," "comprising," or any other variation thereof is intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Furthermore, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
In order to meet the continuous changing requirement of users, the service system needs to upgrade the system without affecting the use of the users, and the conversion of new and old codes needs to meet compatibility, so that the users who use client access have no sense of upgrading the system, and therefore, the service system has important practical significance in order to ensure that the system can stably and effectively complete the upgrading operation and complete the conversion of various interface files.
Based on this, the present invention provides an API file conversion method, as shown in fig. 1, which specifically includes the following steps:
step S1, initial response data of a request for accessing a target resource is obtained;
step S2, carrying out data conversion on the initial response data based on the language specification of the image query language GraphQL to generate an image query language mode GraphQL Schema file;
and S3, analyzing and generating an image query language interface GraphQL API file by adopting a code generation method according to the image query language mode GraphQL Schema file.
In this way, response data of the target resource are directly obtained, and based on the language specification of the image query language graphQL, the response data are converted to generate normalized data types and data operation methods, so that the styles of subsequently generated interface files are unified; the whole process does not need to be manually participated, so that the development cost and the error rate are reduced, and the development efficiency and the automation degree of file conversion are improved.
The API (Application Programming Interface ) refers to a set of methods for interaction between two different software applications, and may be a predefined function, so as to provide an application program and developer with the ability to access a target resource based on a certain software or hardware, where the process does not need to access source code, or understand details of an internal working mechanism. The functionality and data sets of a particular application may thus be packaged together so that they can be easily used by other applications. The API may be divided into a web API, an operating system API and an application API, which is described by taking the web API as an example, and a developer may use the web API to obtain third party data or share data in other applications, which is not limited to the web API.
Optionally, in an embodiment, the image query language interface GraphQL API file may include an image query language parser GraphQL resolution file and an image query language Service GraphQL Service file; in a preferred embodiment, the image query language interface GraphQL API file may include a request file in addition to the two interface files, so as to call an entry file for providing access to the image query language GraphQL service for other application programs, similar to the HTTP request of a common interface. In this way, compatibility of the system or interface may be improved.
Specifically, the image query language mode GraphQL is a diagrammatical query language, can be used for defining query grammar and data specification of an API, has no limitation on data types of front end and back end, has no limitation on programming language, and can select a proper development language according to actual requirements, so that the practicability is high. The image query language interface GraphQL API file is an API interface file generated or converted based on an image query language mode GraphQL Schema, and accords with the language and grammar specification of the image query language GraphQL, so that the styles of the code files are unified.
In addition, the image query language mode GraphQL Schema file may be used to define a data structure type and a data operation method of the image query language interface GraphQL API. The image query language parser GraphQL resolution file can be used for defining a parsing method of each data field in the image query language mode GraphQL Schema file so as to obtain target resource data. The image query language Service GraphQL Service file can be used for defining Service files required by the operation of an image query language interface GraphQL API so as to provide a unified data interface for the call of the image query language parser GraphQL server file.
In other words, the image query language mode GraphQL Schema may provide API interface definitions; the image query language parser GraphQL Resolver can call API interface definition to control flow; the image query language Service GraphQL Service can realize specific business logic corresponding to the API interface, and the image query language GraphQL Service is formed by the cooperation of the image query language Service GraphQL Service and the API interface. Therefore, the required interface file is automatically generated, the risk of missing the generated interface file is avoided, and the development efficiency is improved.
It should be noted that, before generating the image query language interface GraphQL API file based on the image query language GraphQL, initial response data of the target resource needs to be acquired. In one embodiment, the response data may be obtained using an old interface API access method, which may ensure the accuracy and reliability of the data source. Based on this, as shown in fig. 2, the following steps may be specifically included for step S1:
step S11, obtaining an interface address and a request parameter for requesting to access the target resource;
and step S12, requesting to access the target resource by adopting an interface data acquisition method according to the interface address and the request parameter, and obtaining initial response data corresponding to the access parameter.
Therefore, the request address and the request parameter of the target resource are acquired, the target resource can be rapidly and accurately positioned, the response data can be timely and accurately returned, and the timeliness and the accuracy are high.
Wherein, in one embodiment, the interface data acquisition method may include a presentation layer state transition Restful API data acquisition method; in one embodiment, the interface data acquisition method may include a Web Service data acquisition method; in one embodiment, the interface data acquisition method may include a remote communication processor RCP data acquisition method. Any one of the above three embodiments may be freely selected according to practical situations, or any two or three embodiments may be used in combination, and of course, the present invention does not exclude other interface data acquisition methods.
In addition, the data format of the initial response data may include JSON format, XML format, and HTML format. In a preferred embodiment, any two or three of the above formats may be used in combination, and may be freely selected according to practical situations. Of course, the present invention is not limited to the above three data formats. Furthermore, the transcoding method may comprise at least one of a transcoding tool and an automated reconstruction tool.
In particular, the Restful API (Representational State Transfer)), i.e., restful Web services or Rest APIs, is an architectural style for designing Web applications that uses HTTP requests for data transfer and interaction. Specifically, the target resources (such as users, orders and products) are used as unique identifiers on the Web, and operations (such as acquisition, creation, update and deletion) on the resources are provided through the HTTP protocol, each resource has a unique uniform resource identifier, and the operations can be performed by using methods such as GET, POST, PUT, DELETE of HTTP.
The Web Service is a cross-language and cross-system remote call technology, and XML standards can be used to describe, publish, coordinate and configure the interface data of the Web Service application. The remote communication processor RCP (Remote Procedure Call) is a process or function that can request services from a remote computer program over a network without having to know the protocols of the underlying network technology, allowing the program to call another address space (such as the access address of a target resource) without having to display details encoding the remote call. Therefore, the acquisition of the interface data is realized on the premise of not grasping the code logic, and the method is simple and direct.
In one embodiment of the present invention, the method for obtaining the representational layer state transfer Restful API data will be described in detail. Further, as shown in fig. 1 and fig. 3, in the first embodiment, the API file conversion method may further specifically include the following steps:
step S11', inquiring log service according to the interface address of the target resource, and at least obtaining request parameters corresponding to the interface address;
based on this, step S12 may specifically include the following steps:
step S121, constructing and sending an HTTP request according to the interface address and the request parameter;
step S122, receiving and analyzing the response data corresponding to the HTTP request, to obtain the initial response data.
Therefore, the request parameters of the access target resource can be quickly obtained by inquiring the log information accessed by the user, the request is more real and effective, the response result can be obtained without knowing the request details of the interface, and the method is simple and convenient.
The request parameters may include an HTTP request method (such as a GET method and a POST method) for accessing the target resource, list information of the request parameters and corresponding type information (such as an account ID and a user Name for accessing certain employee information), a response data format definition (such as a Json format), and the like. Of course, the invention is not limited to the above parameter information, and the corresponding parameter field can be obtained by analyzing the log information according to the actual requirement.
As shown in fig. 1 and fig. 4, in a second embodiment, the API file conversion method may further specifically include the following steps:
s21, analyzing the initial response data to obtain a plurality of field information and a plurality of field type information;
step S22, based on the language specification of the image query language GraphQL, a code conversion tool is adopted to generate a plurality of image query language mode GraphQL Schema files according to the data field information and the field type information.
Wherein, in one embodiment, the transcoding tool may employ JSON2GraphQL; in another embodiment, the transcoding tool may employ XSD2GraphQL. Therefore, the image query language mode GraphQL Schema file can be automatically generated, the manual writing of error and/or inaccurate image query language mode GraphQL Schema definition is avoided, the quality of the generated mode Schema is ensured, the structural definition of the image query language mode interface GraphQL API data is accurately described, and the development efficiency is improved.
The language specification of the image query language GraphQL is a specification for defining and describing the data structure of the image query language GraphQL, and describes how to write valid codes, including correct grammar structures, lexical rules, and the like. The image query language mode GraphQL Schema is a specification for defining and describing an access interface data structure, and defines different data structures or data models, wherein association relations can exist between the data structures or the data models; each data structure or data model may contain a plurality of fields and a corresponding plurality of field types.
In addition, the JSON2GraphQL can automatically generate GraphQL Schema definition from one or more JSON format response data files, and can process a plurality of JSON files at one time, and each file correspondingly generates an independent Schema file; the XSD2GraphQL can automatically generate GraphQL Schema definition from response data in an XML format, so that development of the image query language GraphQL file can be greatly simplified and standardized through a code conversion tool.
Further, in order to improve the access efficiency of the code file and the subsequent maintenance of the code file, a plurality of automatically generated GraphQL Schema definition files may be uniformly written into one index file, based on which, with continued reference to fig. 4, the API file conversion method may further include:
step S23, constructing index files corresponding to the image query language mode GraphQL Schema files;
step S24, the file names corresponding to the image query language mode GraphQL Schema files are all written into and updated in the index file;
step S311, the index file is acquired and analyzed, and a plurality of image query language mode GraphQL Schema files are obtained through traversal and extraction;
Step S312, generating the image query language interface GraphQL API file by adopting a code generation method according to each image query language mode GraphQL Schema file.
Therefore, by constructing the index file, the index file can be directly imported without importing each file under the folder one by one, so that the convenience of importing the code file is improved; and the code files are unified in one file, so that the subsequent code file maintenance is also facilitated.
The index file can serve as an entry file of an image query language mode GraphQL Schema catalog, other modules or files can conveniently quote or use the Schema object, and the structure and the content of the Schema object can be more conveniently managed and maintained by uniformly creating or exporting the index file.
In addition, after constructing and generating a plurality of corresponding image query language mode GraphQL Schema files according to the initial response data, analyzing and generating a corresponding image query language interface GraphQL API file according to each mode Schema object in the files, so as to conveniently execute the operation method defined in the image query language mode GraphQL Schema files and realize data access to target resources. Step S23 may be provided before step S22.
Based on this, as shown in fig. 5, in one embodiment, the following steps may be specifically included for step S3:
step S321, traversing and analyzing the image query language mode GraphQL Schema file to obtain a plurality of mode Schema objects;
step S322, extracting corresponding data type information according to each mode Schema object;
step S323, respectively generating a corresponding image query language interface GraphQL API file by adopting a code generation method according to each data type information and a corresponding preset template.
Therefore, the development of the GraphQL API can be greatly simplified, the interface file can be automatically generated through the mode Schema definition, the manual code writing is not needed, the development efficiency is improved, the repeated labor is reduced, and the generated image query language mode GraphQL Schema file and the image query language interface GraphQL API file can be kept consistent in file style.
Understandably, the automatic generation method is more efficient when frequent modifications of the image query language mode GraphQL Schema file are required or system upgrades occur. In addition, the data type information may include a type name definition, a field list, and a field type corresponding to the Schema object.
Specifically, the Schema object may be understood as a custom object of the image query language interface GraphQL API pair, which is a data structure or a data model, and may be defined as different types according to requirements, for example, an object type, an interface type, an enumeration type, etc., and meanwhile, association relationships (such as inheritance) may also exist between different types, which may be defined by itself according to actual requirements.
In one embodiment, the image query language mode GraphQL Schema file may include a plurality of mode Schema objects, and of course, only one mode Schema object may be defined, and each mode Schema object may include a plurality of fields, where the fields may return a specific type of data. For example, in the process of querying the user information, the Type of the Schema Object may be defined as an Object Type (i.e. Object Type), where the Schema Object may specifically include field information such as a user ID, a user Name, and the like, where each field information has a corresponding field Type (such as integer Type and String Type). In addition, the Schema object further includes a data obtaining manner, that is, an operation method for obtaining the target resource, such as a query, a new addition, a deletion, etc., and of course, the present invention does not exclude other operation methods.
The preset template can be regarded as a code template for generating the image query language interface GraphQL API file, and the template defines the basic code structure and format of the interface, and can include function names, parameter names, return values and the like. When traversing to a mode Schema object, filling the occupying variable in the template with the corresponding data type information to generate the final image query language interface GraphQL API code. In addition, the name of the image query language interface GraphQL API file can be defined and generated, so that the uniformity of file name formats can be ensured. Of course, the preset template is not limited to the above, and template information can be automatically added or adjusted according to actual requirements.
In order to parse each mode Schema object, a corresponding parser needs to be automatically generated according to the image query language mode GraphQL Schema file, based on which, when the image query language interface GraphQL API file includes an image query language parser GraphQL Resolver file, step S323 may specifically include:
step S323', based on the preset parser resolution template, respectively generating corresponding image query language parser GraphQL resolution files by adopting a code generation method according to each data type information.
Thus, according to the image query language mode GraphQL Schema file, the workload of manually writing and maintaining an image query language analyzer GraphQL resolution can be reduced by using a code generation method, and the development efficiency and the code writing accuracy are improved; meanwhile, the generated image query language parser GraphQL resolution file is consistent with the image query language mode GraphQL Schema file in style, potential errors caused by manual writing are reduced, and the method is easy to understand and maintain.
The image query language analyzer GraphQL resolution file and the image query language mode GraphQL Schema file can be mutually related, when target resource operation is queried through an image query language interface GraphQL API, the image query language analyzer GraphQL resolution file can be called and is responsible for processing each field of query, the image query language analyzer GraphQL resolution file comprises a plurality of resolution functions, and related data can be searched, transformed and assembled in a target data source according to type information defined in the image query language mode GraphQL Schema file and returned to a client.
In other words, the image query language Schema GraphQL Schema file defines a number of data structures or data models, and the image query language parser GraphQL Resolver file contains a plurality of Resolver function statements for defining and determining how to implement the data structures or data models. That is, each data structure or field in the data model may be processed by a corresponding parser resolution function that may supplement and implement the definition of the image query language Schema GraphQL Schema file such that data operations interface with the target data source to provide access for subsequent specific data query, conversion and assembly logic. The generated image query language mode GraphQL resolution file is combined with the image query language mode GraphQL Schema file, so that sufficient decoupling can be realized, and code management and maintainability are improved.
Further, in order to implement the business logic of the plurality of resolvers in the image query language parser GraphQL resolvers file, an image query language Service file may be generated. Based on this, when the image query language interface GraphQL API file includes an image query language Service GraphQL Service file, as shown in fig. 6, in one embodiment, the following steps may be specifically included for step S323:
step S3231, based on the preset Service interface template, respectively generating corresponding Service interface files by adopting a code generation method according to each data type information;
step S3232, based on the preset Service realization template, respectively generating corresponding Service realization files by adopting a code generation method according to each data type information;
and step S3233, combining the Service interface file and the Service realization file to obtain the image query language Service GraphQL Service file.
In addition, the uniformity and maintainability of the generated Service file code structure and style can be kept through a preset interface template and an implementation template.
Wherein, the Service interface file can be used for defining and realizing the file of Service logic, and can comprise at least one of interface name, interface parameter and interface return type; the Service realization file is used for realizing the business logic of each interface in the Service interface file. The preset Service interface template and the preset Service realization template are used for unifying and standardizing the definition and realization process of the Service, and can be flexibly adjusted according to actual requirements.
Specifically, in the present invention, the Service document of the image query language Service may provide a corresponding parsing logic for each field according to the structure defined in the image query language Schema GraphQL Schema document, which is a specific implementation process corresponding to the resolution function declaration. The image query language Service file may also include interactive logic with the back end target data source, and may acquire data by calling a database, an API interface, etc., so when the image query language parser GraphQL server file is called, it may also call the image query language Service file and execute specific Service logic therein, and the data obtained by the query is assembled and returned to the client.
In addition, the preset Resolver template, the preset Service interface template, and the preset Service interface template may refer to the description of the preset template, which is not specifically expanded herein. Step S323' and steps S3231 to S3233 are derivative steps of step S323. Step S3231 step S3232 can be defined and implemented simultaneously.
The invention also provides an API file conversion system, which comprises: a client and a server; the server side is used for receiving and analyzing the query request sent by the client side; the server side is used for acquiring initial response data of the target resource according to the query request; the server side is used for executing data conversion operation according to the initial response data to obtain an image query language mode GraphQL Schema file; the server side is used for generating an image query language interface GraphQL API file according to the image query language mode GraphQL Schema file, and obtaining response data by calling service logic in the image query language interface GraphQL API file and sending the response data to the client side.
Therefore, conversion from other API format files to the image query language GraphQL format can be automatically realized, repeated labor is reduced, development efficiency is improved, front and rear end separation is optimized, and a query method required by a client can be automatically generated without deep knowledge of the image query language GraphQL.
Optionally, in a preferred embodiment, in order to achieve compatibility of different clients, improve access speed and meet actual requirements of different users, the clients may write access parameters actually required by the users into a file before requesting access, so as to facilitate subsequent access to the target resource according to the file request.
Specifically, the client builds a request file for executing access operation on the target resource according to the link address and the request access parameter of the target resource, and sends a request to the server by taking the request file as a medium. Therefore, different clients can acquire the data required by themselves only by modifying the request file without modifying the logic code of the target resource accessed by the back end, the compatibility is higher, the direct operation of the client on the target resource can be shielded, the error probability is reduced, and the flexibility is strong.
The request file is a file capable of describing the data structure and fields required by the client, and can be used for sending an image query language GraphQL query request to the server, executing corresponding request logic on the server, acquiring corresponding data according to request parameters and service requirements in the request file by the server, and returning the data to the client.
It should be noted that, the request file may be written at the client, or may be generated and provided for the client in other manners, where writing at the client may make it easier for the developer to understand and organize the required query structure, and provide a better development experience. And the request file provided to the client may be generated through an API document or code generation tool so that the client can conveniently use and maintain the request file.
The present invention also provides a computer storage medium comprising a memory and a processor, wherein the memory stores a computer program, and the computer program when executed by the processor causes the processor to execute the steps of the API file conversion method according to any one of the foregoing technical solutions.
In summary, the method and the device for generating the image query language mode GraphQL Schema file keep consistent with the specification by converting the initial response data. The consistency is helpful for development members to understand and use the image query language GraphQL, so as to reduce ambiguity and misunderstanding in the development process; the data structure type and the data operation method of the image query language interface can be automatically defined through the image query language mode GraphQL Schema file, so that a developer does not need to manually write and maintain the mode Schema file, human errors are avoided, and development efficiency is improved; the image query language interface GraphQL API file is automatically generated based on the image query language mode GraphQL Schema file, so that the generated interface file can be ensured to keep consistent in style, and is easy to understand and maintain.
In addition, the generated image query language interface GraphQL API files are automatically generated based on the image query language mode GraphQL Schema files, the file directory structure is clear and clear, the problem of inconsistent file naming of the same functions of different levels cannot occur, the probability of error of file reference problems among targets at all levels is low, and the problem of low development efficiency caused by missing and changing the reference files is not easy to occur.
It should be understood that although the present disclosure describes embodiments, not every embodiment is provided with a separate embodiment, and that this description is for clarity only, and that the skilled artisan should recognize that the embodiments may be combined as appropriate to form other embodiments that will be understood by those skilled in the art.
The above list of detailed descriptions is only specific to practical embodiments of the present invention, and they are not intended to limit the scope of the present invention, and all equivalent embodiments or modifications that do not depart from the spirit of the present invention should be included in the scope of the present invention.

Claims (13)

1. An API file conversion method, comprising:
Acquiring initial response data of a request for accessing a target resource;
based on the language specification of the image query language GraphQL, carrying out data conversion on the initial response data to generate an image query language mode GraphQL Schema file; the image query language mode GraphQL Schema file is used for defining the data structure type and the data operation method of an image query language interface GraphQL API;
and analyzing and generating an image query language interface GraphQL API file by adopting a code generation method according to the image query language mode GraphQL Schema file.
2. The API file conversion method as recited in claim 1, wherein said image query language interface GraphQL API file includes at least an image query language parser GraphQL server file and an image query language Service GraphQL Service file; the image query language analyzer GraphQL resolution file is used for defining an analysis method of each data field in the image query language mode GraphQL Schema file so as to acquire target resource data; the image query language Service GraphQL Service file is used for defining Service files required by the operation of an image query language interface GraphQL API so as to realize that the Service logic of the analysis method is called by the image query language analyzer GraphQL resolution file.
3. The API file conversion method as recited in claim 1, wherein said obtaining initial response data for requesting access to the target resource comprises:
acquiring an interface address and a request parameter for requesting to access the target resource;
and requesting access to the target resource by adopting an interface data acquisition method according to the interface address and the request parameter, and obtaining initial response data corresponding to the request parameter.
4. The API file conversion method as recited in claim 3, wherein said interface data acquisition method includes at least one of a presentation layer state transition Restful API data acquisition method, a Web Service data acquisition method, and a remote communication processor RCP data acquisition method; the data format of the initial response data comprises at least one of Json format, XML format and HTML format; the transcoding method includes at least one of a transcoding tool and an automated reconstruction tool.
5. The API file conversion method as recited in claim 3, wherein said "obtaining an interface address and request parameters for requesting access to said target resource" specifically comprises:
inquiring log service according to the interface address of the target resource, and at least obtaining a request parameter corresponding to the interface address;
The "according to the interface address and the request parameter, the method for obtaining the initial response data corresponding to the access parameter by adopting the interface data obtaining method to request to access the target resource" specifically includes:
constructing and sending an HTTP request according to the interface address and the request parameter;
and receiving and analyzing response data corresponding to the HTTP request to obtain the initial response data.
6. The API file conversion method as recited in claim 1, wherein the generating the image query language mode GraphQL Schema file by performing data conversion on the initial response data based on the language specification of the image query language GraphQL specifically includes:
analyzing the initial response data to obtain a plurality of field information and a plurality of field type information;
based on the language specification of the image query language GraphQL, generating a plurality of image query language mode GraphQL Schema files by adopting a code conversion tool according to the data field information and the field type information; the code conversion tool comprises at least one of JSON2GraphQL and XSD2 GraphQL.
7. The API file conversion method as recited in claim 6, further comprising, after said generating a number of image query language Schema GraphQL Schema files:
Constructing index files corresponding to the image query language mode GraphQL Schema files;
the file names corresponding to the image query language mode GraphQL Schema files are all written into and updated to the index file;
the step of analyzing and generating the image query language interface GraphQL API file by adopting a code generation method according to the image query language mode GraphQL Schema file specifically comprises the following steps:
the index file is acquired and analyzed, and a plurality of image query language mode GraphQL Schema files are obtained through traversal and extraction;
and generating the image query language interface GraphQL API file by adopting a code generation method according to each image query language mode GraphQL Schema file.
8. The API file conversion method as recited in claim 1, wherein said parsing and generating an image query language interface GraphQL API file using a code generation method according to the image query language mode GraphQL Schema file specifically includes:
traversing and analyzing the image query language mode GraphQL Schema file to obtain a plurality of mode Schema objects;
extracting corresponding data type information according to each mode Schema object; the data type information comprises a type name, a field list and a field type corresponding to the mode Schema object;
And respectively generating a corresponding image query language interface GraphQL API file by adopting a code generation method according to each data type information and a corresponding preset template.
9. The API file conversion method as recited in claim 8, wherein said image query language interface GraphQL API file includes an image query language parser GraphQL resolution file; the method for generating the corresponding image query language interface GraphQL API file by adopting the code generation method according to each data type information and the corresponding preset template specifically comprises the following steps:
based on a preset parser resolution template, respectively generating corresponding image query language parser GraphQL resolution files by adopting a code generation method according to each data type information.
10. The API file conversion method as recited in claim 8, wherein said image query language interface GraphQL API file includes an image query language Service GraphQL Service file; the step of generating the corresponding image query language interface GraphQL API file by adopting a code generation method according to the data type information and the corresponding preset template comprises the following steps:
based on a preset Service interface template, respectively generating corresponding Service interface files by adopting a code generation method according to each data type information;
Based on a preset Service realization template, respectively generating corresponding Service realization files by adopting a code generation method according to each data type information;
combining the Service interface file and the Service realization file to obtain the image query language Service GraphQL Service file;
the Service interface file is used for defining an interface and comprises at least one of an interface name, an interface parameter and an interface return type; the Service realization file is used for realizing the business logic of each interface in the Service interface file.
11. An API file conversion system comprising: a client and a server; the server side is used for receiving and analyzing the query request sent by the client side; the initial response data is used for acquiring the target resource according to the query request; the method comprises the steps of executing data conversion operation according to initial response data to obtain an image query language mode GraphQL Schema file; the method is used for generating an image query language interface GraphQL API file according to the image query language mode GraphQL Schema file, and obtaining response data by calling service logic in the image query language interface GraphQL API file and sending the response data to the client.
12. The API file conversion system of claim 11, wherein said client builds a request file for performing an access operation on a target resource based on a link address of the target resource and a request access parameter, and transmits a request to a server side with said request file as a medium.
13. A computer storage medium comprising a memory and a processor, the memory having stored therein a computer program which, when executed by the processor, causes the processor to perform the steps of the API file conversion method of any of claims 1-10.
CN202311444334.3A 2023-11-02 2023-11-02 API file conversion method, system and computer storage medium Withdrawn CN117172214A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311444334.3A CN117172214A (en) 2023-11-02 2023-11-02 API file conversion method, system and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311444334.3A CN117172214A (en) 2023-11-02 2023-11-02 API file conversion method, system and computer storage medium

Publications (1)

Publication Number Publication Date
CN117172214A true CN117172214A (en) 2023-12-05

Family

ID=88932107

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311444334.3A Withdrawn CN117172214A (en) 2023-11-02 2023-11-02 API file conversion method, system and computer storage medium

Country Status (1)

Country Link
CN (1) CN117172214A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117369784A (en) * 2023-12-06 2024-01-09 之江实验室 Processing system and method of service interface
CN117725122A (en) * 2023-12-25 2024-03-19 北京全网数商科技股份有限公司 An order synchronization method for business management platform
CN119065645A (en) * 2024-11-05 2024-12-03 北京长亭科技有限公司 A method and device for building an API interface and querying data

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112130830A (en) * 2020-08-25 2020-12-25 汉海信息技术(上海)有限公司 Interface generation method and device and electronic equipment
CN113220755A (en) * 2020-12-28 2021-08-06 浙大网新科技股份有限公司 Method for flexibly generating GraphQL interface based on multi-source data
CN114116866A (en) * 2021-11-22 2022-03-01 广州新科佳都科技有限公司 Data acquisition method and device, terminal equipment and storage medium
CN114610317A (en) * 2022-03-16 2022-06-10 北京字节跳动网络技术有限公司 Code conversion method, device, equipment and storage medium
WO2023115738A1 (en) * 2021-12-23 2023-06-29 北京来也网络科技有限公司 Service interface configuration method and device combining rpa and ai

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112130830A (en) * 2020-08-25 2020-12-25 汉海信息技术(上海)有限公司 Interface generation method and device and electronic equipment
CN113220755A (en) * 2020-12-28 2021-08-06 浙大网新科技股份有限公司 Method for flexibly generating GraphQL interface based on multi-source data
CN114116866A (en) * 2021-11-22 2022-03-01 广州新科佳都科技有限公司 Data acquisition method and device, terminal equipment and storage medium
WO2023115738A1 (en) * 2021-12-23 2023-06-29 北京来也网络科技有限公司 Service interface configuration method and device combining rpa and ai
CN114610317A (en) * 2022-03-16 2022-06-10 北京字节跳动网络技术有限公司 Code conversion method, device, equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
汪雁;: "监控管理系统Web前端设计与实现探究", 信息记录材料, no. 08 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117369784A (en) * 2023-12-06 2024-01-09 之江实验室 Processing system and method of service interface
CN117369784B (en) * 2023-12-06 2024-03-05 之江实验室 A service interface processing system and method
CN117725122A (en) * 2023-12-25 2024-03-19 北京全网数商科技股份有限公司 An order synchronization method for business management platform
CN119065645A (en) * 2024-11-05 2024-12-03 北京长亭科技有限公司 A method and device for building an API interface and querying data
CN119065645B (en) * 2024-11-05 2025-01-28 北京长亭科技有限公司 Construction and data query method and device of API (application program interface)

Similar Documents

Publication Publication Date Title
US11269694B2 (en) Automated API code generation
US11669503B2 (en) Building and managing data-processing attributes for modeled data sources
CN117172214A (en) API file conversion method, system and computer storage medium
JP5349581B2 (en) Query processing visualizing system, method for visualizing query processing, and computer program
US9251222B2 (en) Abstracted dynamic report definition generation for use within information technology infrastructure
CN101354696A (en) Data Integration and Application Service System Based on Shared Information Model in Telecom Field
US10402380B1 (en) Interactive user interface for schema transformation
US20190347341A1 (en) Method and system for schema transformation
US11232105B2 (en) Unified metrics computation platform
CN115113854A (en) Interface document generation method, device, equipment and computer readable storage medium
CN116467274A (en) Data sharing method and device for multi-source heterogeneous data, storage medium and terminal
Schlegel et al. MLflow2PROV: extracting provenance from machine learning experiments
CN113886485A (en) Data processing method, apparatus, electronic device, system and storage medium
WO2023164294A1 (en) Query splitter for an inverted index datastore
US20200356570A1 (en) Interactive user interface having transform operators for schema transformation
US20190205436A1 (en) System and method for executing database operations on a database
CN114153438A (en) API automatic generation system
EP4154129A1 (en) Database management methods and associated apparatus
CN114547404B (en) Big data platform system
CN118170853B (en) Agricultural big data management method, device, electronic device and storage medium
CN114138310B (en) Software system updating method, device and computer storage medium
CN114969868B (en) Modelica model lightweight display method based on development life cycle collaboration service
CN110442629A (en) Big data multicenter isomery daynamic transformation method
Simonov Domain Specific Langauge Support for Kieker and OpenTelemetry Interoperability
US12124890B2 (en) Event provisioning for high-level programing language platform

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
WW01 Invention patent application withdrawn after publication

Application publication date: 20231205

WW01 Invention patent application withdrawn after publication
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载