The relationship between modules is called the component layer. This relationship can be represented by the server-side associative array (array of key=> attribute). Each module specifies the name as the key attribute, and the internal module is under the \
The data in the PHP array can also be directly used for clients encoded as JSON objects. The component hierarchy is as follows:$ Componenthierarchy =[
‘module-level0’= >[
\
‘module-level1’= >[
\
‘module-level11’= >[
\
],
‘module-level12’= >[
\
‘module-level121’= >[
\
]The
]The
]The
]The
],
‘module-level2’= >[
\
‘module-level21’= >[
\
]The
]The
]The
]The
]The
]The
The relationship between modules is strictly defined in a top-down manner. Modules will crawl other modules and know who they are, but they don’t know which module will crawl themselves and don’t care. The
For example, we know that in the above component layer, \
$componenthierarchydata =[
\
‘module-level0’= >[
\
,
\
‘module-level1’= >[
\
,
\
‘module-level11’= >[
And Children
],
‘module-level12’= >[
\
,
\
‘module-level121’= >[
And Children
]The
]The
]The
]The
],
‘module-level2’= >[
\
,
\
‘module-level21’= >[
And Children
]The
]The
]The
]The
]The
],
\
‘module-level0’= >[
\
,
\
‘module-level1’= >[
\
,
\
‘module-level11’= >[
And Children
],
‘module-level12’= >[
\
,
\
‘module-level121’= >[
And Children
]The
]The
]The
]The
],
‘module-level2’= >[
\
,
\
‘module-level21’= >[
And Children
]The
]The
]The
]The
]The
]The
]The
Next, the database object data is added to the component hierarchy. This information is not placed under each module, but under a shared section called databases to prevent duplication of information when two or more other modules import the same object from the database. The
In addition, the library represents database object data as relational to prevent duplicate information when two or more different database objects are related to common objects (for example, two posts with the same author). This means that the database object data will be normalized. The structure is first a dictionary composed of each object type, and then an object ID to obtain object attributes$ Componenthierarchydata =[
And
\
\
\
\
And
],
And
],
And
]The
]The
For example, the following object contains a component hierarchy of two modules: \
Each module knows the attribute dbobjectids (for blog posts, the objects queried in ID 4 and 9). Each module knows the object type of the query object in the dbkeys attribute (the data of each post is under \
\
‘page’= >[
\
‘post feed’= >[
\
]The
]The
]The
],
\
‘page’= >[
\
Schedule, $props,’showmore’, false);
$this->appendprop ($module, $props,’class’,’text Center’);
Break;
}The
Parent:: initmodelprops ($module, $props);
}The
\/\/And
}The
Creating reusable components is accomplished by creating an abstract module processor class, which defines the placeholder functions that some instantiated classes must implement. Male abstract class postwidgetlayoutabstractmoduleprocessor extends abstractmoduleprocessor
The{
Function getsubmodules ($module): array
The{
$ret =[
$this->getcontentmodule ($module),
];
If ($thumbnail_module = $this->getthumbnailmodule ($module))
The{
$ret[] = $thumbnail_module;
}The
If ($aftercontent_modules = $this->getaftercontentmodules ($module))
The{
$ret = array_merge(
$ret,
$aftercontent_modules
);
}The
Return $return;
}The
Abstract protected function getcontentmodule ($module): array;
Protected function getthumbnailmodule ($module):? Array
The{
\/\/Default value (overridable)
Return [self:: class, self:: thumbnail\u layout];
}The
Protected function getaftercontentmodules ($module): array
The{
Return [];
}The
Function getimmutableconfiguration ($module, &$props): array
The{
Return[
‘description’= > $this->getdescription(),
];
}The
Protected function getdescription ($module): String
The{
Return ”;
}The
}The
Then, the user-defined module processor class can expand the abstract class and define unique attributes. Class postlayoutmoduleprocessor extends abstractpostlayoutmoduleprocessor{
Const post\u content =’post content’
Const post_exact =’post exact’
Const post\u thumbnail\u large =’post thumbnail large’
Const post\u thumbnail\u medium =’post thumbnail medium’
Const post_share =’post Share’
Function getsubmodulestoprocess(){
Return[
Self:: post\u content,
Self:: post\u export,
Self:: post\u thumbnail\u large,
Self:: post\u thumbnail\u medium,
Self:: post\u share,
];
}The
}The
Class postwidgetlayoutmoduleprocessor extensions abstractpostwidgetlayoutmoduleprocessor
The{
Protected function getcontentm
Module ($module):? Array
The{
Switch ($module[1])
The{
Case self:: post\u widget\u homepage\u large:
Return[
Postlayoutmoduleprocessor:: class,
Postlayoutmoduleprocessor:: post\u content
];
Case self:: post\u widget\u homepage\u medium:
Case self:: post\u widget\u homepage\u small:
Return[
Postlayoutmoduleprocessor:: class,
Postlayoutmoduleprocessor:: post\u export
];
}The
Return parent:: getcontentmodule ($module);
}The
Protected function getthumbnailmodule ($module):? Array
The{
Switch ($module[1])
The{
Case self:: post\u widget\u homepage\u large:
Return[
Postlayoutmoduleprocessor:: class,
Postlayoutmoduleprocessor:: post\u thumbnail\u large
];
Case self:: post\u widget\u homepage\u medium:
Return[
Postlayoutmoduleprocessor:: class,
Postlayoutmoduleprocessor:: post\u thumbnail\u medium
];
}The
Return parent:: getthumbnailmodule ($module);
}The
Protected function getaftercontentmodules ($module): array
The{
$ret = [];
Switch ($module[1])
The{
Case self:: post\u widget\u homepage\u large:
$ret[] =[
Postlayoutmoduleprocessor:: class,
Postlayoutmoduleprocessor:: post\u share
];
Break
}The
Return $return;
}The
Protected function getdescription ($module): String
The{
Return \u (‘these are my blog posts’,’My domain’);
}The
}The
4. the component is naturally suitable for graphql. The component model can naturally map tree graphql queries. It is an ideal architecture for implementing graphql server. Graphql by pop transforms graphql queries into its component hierarchy, and implements the module processor classes required by the pop data loading engine. This is why and how the solution works. Map client components to graphql queries. Graphql queries can use the component hierarchy of pop to represent all object types to represent components, and all relationship fields from object types to other object types to represent components that package other components. Let’s use an example to see how this works. Suppose you want to build the following recommended director widget: Use the recommended supervision component Vue or react (or other component-based libraries) to identify components first. In this case, the external component male (red),
Processed with the field actors ID of the high film type. The type is processed in the repetition, but if more data needs to be loaded from the type after the type is processed, it is a new repetition of the type. For example, if you add the relational field preferreddirector to the author type, the director type is added to the queue again. Note that the caching mechanism can be used here for repetition of repetition type. In the second iteration of the director type, the object with ID 2 will not be searched again because the object has been searched in the first iteration for import from the cache. Now that all the object data has been imported, you must mirror the graphql query to generate the shape of the expected response. The data is organized in the same way as the relational database, as shown in the current figure. Type director Korean table: malemale male ID name National Avatar Movie male male 2 male George Lucas US male George Lucas. Jpg androg [3,8] androg androg androg androg androg type film Korean table: androg androg ID Title ambiguous nail enhancement actors androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg androg gags -1. Jpg androg [4,6] androg androg androg androg 8 androg androg clonal attack androg androg androg androg gags-2. Jpg androg [6,7] androgandrogandrog actor type table: androgandrogandrog ID name Huaxin androgandrogandrogandrogandrog 4 androgandrogandrog evanmcgregor androg McGregor. Jpg androg androg androg androg androg androg 6 androg androg natal report only androg androg report. Jpg androgandrogandrogandrogandrog 7 androgandrogandrog Hayden Christensen androg Christensen. At the JPG stage, pop consists of all types (i.e. how are all tables related to each other to form data and OK? Refer to the film field through the director, and the actor field and actors of the film). Then repeat the component hierarchy in the root directory, browse the relationship, search for objects in the relationship table, and pop generates tree shapes in the graphql query. The tree response finally prints data as output, which will generate a response with the same shape as the graphql query. The{
Data:{
Featureddirector:{
Name: \
Country: \
Avatar: \
Films:[
The{
Title: \
Thumbnail: \
Actors:[
The{
Name: \
Avatar: \
},
The{
Name: \
Avatar: \
}The
]The
},
The{
Title: \
Thumbnail: \
Actors:[
The{
Name: \
Avatar: \
},
The{
Name: \
Avatar: \
}The
]The
}The
]The
}The
}The
}The
5. analyze the performance of graphql query using components. Analyze the big O marking method of data loading algorithm to understand how the number of queries executed on the database increases with the increase of the number of inputs, so as to determine whether the performance of the solution is good.
The data loading engine in the pop loads data repeatedly for each type. At the beginning of the repetition, all the ID lists of all the objects to be imported already exist, so you can execute a single query to import all the data of the object. Then, the number of queries in the database will increase linearly according to the number of types related to the query. That is, the time complexity is O (n). Where n is the number of types of the query (but if the type repeats two or more times, you must add n times). The performance of this solution is significantly better than the geometric complexity expected when working with graphics or the algebraic complexity expected when working with trees. Conclusion graphql server does not need to use graph to represent data. In this article, we explored the architecture implemented by graphql for a pop that is described by pop, component-based, and repeatedly loads data by type. This approach allows the server to resolve graphql queries with linear time complexity. This is better than the exponential or log time complexity expected when using graphs or trees.