The invention discloses an API (Application Program Interface) construction and
data query method and device, and relates to the technical field of computers, the method comprises the following steps: creating a
JavaScript file taking a GraphQL operation type as a suffix; the method comprises the following steps: receiving structural parameters of a declarative parser in a
JavaScript file, and constructing a parser object; a parser object of the
JavaScript file is imported into the GraphQL
server side, and the parser object is transmitted to a parser
configuration item in the configuration parameters of the GraphQL
server side; analyzing the query character string sent by the
client, converting the query character string into an
executable query document, and obtaining corresponding data from the
data source according to a specified field path in the query document; and analyzing the acquired data through an analyzer, and returning the analyzed data to the
client. According to the method, the development efficiency of the API interface is improved, and the expandability of the
system is also improved.