Related reading:

Facebook/GraphQL, APIJSON full contrast parsing (a)- Basic features

Facebook/GraphQL, APIJSON full contrast parsing (ii)- Permissions control


APIJSON has been compared to Facebook’s GraphQL since its release.

Quite a few people even claim to have “blown up” APIJSON.

But the opposite is true, and this series of blogs will prove it with plenty of factual evidence,

APIJSON “complete explosion” GraphQL!


APIJSON’s number is:

Back-end interface and document automation, front-end (client) customization returns JSON data and structure!

APIJSON:

APIJSON is a JSON network transport protocol developed for APIS. For simple add, delete, change, search, complex query, simple transaction operations to provide a fully automated API. Can greatly reduce the development and communication costs, simplify the development process, shorten the development cycle. Suitable for small and medium-sized projects with separated front and back ends, especially Internet entrepreneurship projects and enterprise self-use projects.

With automated apis, the front end can customize any data, any structure! Most HTTP request backends don’t write interfaces anymore, let alone documents! The front end no longer has to communicate with the back end about interface or documentation issues! No more documentation errors pit! The back end no longer has to write new versions of interfaces and documentation to accommodate older interfaces! Won’t be the front end at any time anywhere endless bored!

Characteristics of the function

Online analytical

  • Automatically generates documents that are legible and always up to date
  • Automatically generates request code for Android and iOS
  • Automatic generation of JavaBean files, one click download
  • Automatic management and test interface use cases, one-click sharing
  • Automatic validation and formatting of JSON, support highlighting and expansion

For the front

  • No need to push the interface back end, document
  • The data and structure are completely customized, and you can have anything you want
  • You know what you ask, you get what you ask
  • Any data, any structure, can be retrieved at once
  • It can remove duplicate data, save traffic and improve speed

For the back-end

  • Provides a common interface, most of the API no longer need to write
  • Automatic generation of documents, no need to write and maintain
  • Automatic permission verification, automatic version management
  • Open apis do not require versioning and are always compatible
  • Support to add, delete, change, fuzzy search, regular matching, remote functions

Video demonstration: i.youku.com/apijson



[The following Gif looks like a bit of a crunch, but the App actually runs smoothly on the phone]



Project homepage: github.com/TommyLemon/…



Facebook/GraphQL, APIJSON comprehensive comparison analysis (three)- table associated query


Db-engines released its June 2018 database rankings:



And their development over the years:



Obviously, Oracle, MySQL and Microsoft SQL Server are the top three,

Moreover, the Score of these three databases is above 1000.

PostgreSQL has risen steadily in recent years to no. 4.

The top four most popular databases all have one thing in common – they are all relational databases.


APIJSON and GraphQL, as generic open source projects related to the HTTP API, must support relational databases.

Then they all support it, but APIJSON “blew up” GraphQL!

Implementing table associative query with GraphQL is complicated and tedious, while using APIJSON is very simple and convenient!


Relational databases are called relational because they support table associative queries well.

For example, query [all information] of the current user and [names] of the top 5 friends of the TA.

GraphQL looks like this:

{
  user(id: 82001) {
    id
    sex
    name
    tag
    head
    contactIdList
    pictureList
    friends(first: 5) {
      name
    }
  }
}Copy the code

The return result is

{
    "data": {"user": {"id":82001."sex":0."name":"Test name change"."tag":"APIJSON User"."head":"https://static.oschina.net/uploads/user/19/39085_50.jpg"."contactIdList": [38710.82002.82006.82030.82025.82003.93793]."pictureList": ["http://common.cnblogs.com/images/icon_weibo_24.png"]."friends":[
                {
                    "name":"TommyLemon"
                },
                {
                    "name":"Happy~"
                },
                {
                    "name":"Wechat"
                },
                {
                    "name":"Meria"
                },
                {
                    "name":"Tommy"}]}}}Copy the code

GraphQL How does the back end know that user is of type user and friends is of type user array?

Because the back end uses a lot of code in advance to write out the data structure and parsing methods, namely Type and Schema:

// Declare the GraphQLObjectType, including the fields and resolver function
var UserType = new GraphQLObjectType({
  name: 'User'.fields: (a)= > ({
    name: { type: GraphQLString },
    friends: {
      args: {
        first: { type: GraphQLInt }
      },
      type: new GraphQLList(UserType), // Declare friends as an array of users
      resolve: (user, { first }) = > { // Check the function for friends
         var ids = user.contactIdList == null ? [] : user.contactIdList.join();
         return ctx.db.findAll(
           'SELECT name FROM User WHERE id IN(' + ids + ') LIMIT ' + first
         ).then(rows= > rows.map(row= >getUserFromRow(row))); }}})});Copy the code
// Declare the structure Schema, including the Query structure Query
export const UserSchema = new GraphQLSchema({
  query: {
    user: {
      type: UserType // Declare the type of me to be User
      fields: (a)= > ({
        id: { type: new GraphQLNonNull(GraphQLID) },
        sex: { type: GraphQLInt },
        name: { type: GraphQLString },
        tag: { type: GraphQLString },
        head: { type: GraphQLString },
        contactIdList: { type: new GraphQLList(GraphQLID) },
        pictureList: { type: new GraphQLList(GraphQLString) }
      }),
      args: {        
        id: { type: new GraphQLNonNull(GraphQLID) }
      },      
      resolve: ({ id }) = > { // Query User's parse function
        return ctx.db.findOne(
          'SELECT * FROM User WHERE id = ' + id
        ).then(row= >getUserFromRow(row)); }}}});Copy the code

The above code is according to the official code

https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsSchema.js

https://github.com/facebook/dataloader

And Apijson.org provides test database tables to achieve this.

GraphQL is so complicated with JavaScript, using Java, C# and other statically typed languages would be several times more difficult!


APIJSON looks like this:

{
  "User": {
    "id": 82001.// Query condition: ID = 82001
    "User[]": { // Get the User of each item in the array
      "count": 5.// LIMIT 0, 5
      "User": {
        "id{}@": "User/contactIdList".// IN the friend ID list: id IN contactIdList
        "@column": "name" Name: SELECT name}}}}Copy the code

Or put the User array outside to reduce the nesting level.

{
  "User": {
    "id": 82001    
  },
  "User[]": {
    "count": 5."User": {
      "id{}@": "User/contactIdList"."@column": "name"}}}Copy the code

There’s only one field in each object in the User array, name, and if you want to get rid of that extra layer of wrapping,

APIJSON can [extract fields] (not provided by GraphQL)

{
  "User": {
    "id": 82001    
  },
  "User-name[]": { // Fetch name from each User in the array
    "count": 5."User": {
      "id{}@": "User/contactIdList"."@column": "name"}}}Copy the code

The preceding information fully describes tables, fields, query conditions, and table association modes.


Without writing any code on the APIJSON back end,

It automatically parses the above request JSON into SQL statements

SELECT * FROM User WHERE id = 82001Copy the code

SELECT name FROM User WHERE id IN ${contactIdList} ContactIdList is retrieved from the User aboveCopy the code

Then [autoexecute] and return the JSON result of the corresponding structure!








Click the left [‘/”] button to convert the array symbol [] to the word List (formatted with jsonResponse.format)



Note: All of the above APIJSON requests can be tested on the apijson.org online tool


Late notice:

Facebook/GraphQL, APIJSON full comparison analysis

Data structure flexibility, interface security, interface tools, community ecology, statically typed/strongly typed languages…




conclusion

Implementing table associative query with GraphQL is complicated and tedious. It requires a lot of code to write at the back end, which is prone to error and troublesome to expand!

Using APIJSON is very simple and convenient, the back end does not write any code, fully automatic parsing, no maintenance costs!


APIJSON, let backend interface and document automation, front-end (client) custom return JSON data and structure!



Creation is not easy, click Star in the upper right corner to support it, thank you so much

Github.com/TommyLemon/… (Java Server, Anroid, iOS, JavaScript)

Github.com/liaozb/APIJ… (C# .NET Core Server)