Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
What is theGQL
GQL is Graph Query Language, which is a Graph Query Language. GraphQL is a specification designed to simplify communication between the front end and back end. It mainly consists of schema language on the server side and query language on the client side.
GraphQL is a Query Language that is particularly advantageous for querying Graph data. It shares the QL suffix with SQL, just as “Chinese” and “English” share the suffix, but they are essentially different languages. GraphQL is not necessarily associated with the NoSQL used for storage, although the actual storage behind GraphQL can be a NoSQL type database, it can also be an SQL type database, or any other storage method (such as text files, in-memory, etc.).
Details visible # | the nuggets GraphQL Chinese website translation project
The paper
GraphQL is primarily for data interfaces, such as front-end and back-end interactions. Is to give the client filter free access to the server predefined data, improve the flexibility of the interactive interface. These data are from MySQL, NoSQL database check, this is the relationship. GraphQL itself isn’t a database (if you know the difference), doesn’t seem to aggregate computed data (I’m not sure), and doesn’t manipulate databases directly.
For A simple example, after using GraphQL on the backend, the database can find four fields A,B,C, and D. When the client needs data, you can use any combination of these four fields, just A, C, or JUST A, C, and D, and so on. There is no need to communicate with the server.
The core of MySQL, NoSQL and so on is to store data. This is the main difference from GraphQL.
After simplification, GraphQL can be understood as a flexible Ajax interface, and mysql can be understood as a file to store data. The essential difference.
External chain reference:
- GraphQL Introduction
- GraphQL: A data query language
- Interview from InfoQ: Facebook’s open source data query language GraphQL
- GraphQL: Designing a Data Language
Learn to try
The installation
npm install graphql
Copy the code
Since GQL supports javascript, use Node to run it
var { graphql, buildSchema } = require('graphql');
var schema = buildSchema(`
type Query {
hello: String
}
`);
var root = { hello: () => 'Hello world!' };
graphql(schema, '{ hello }', root).then((response) => {
console.log(response);
});
Copy the code