Skip to content

Commit

Permalink
chore: deploy docs of project Nop Entropy via GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nop-cao committed May 16, 2024
1 parent 9587de4 commit b0c1d98
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions projects/nop-entropy/docs/dev-guide/graphql/connection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1223,16 +1223,24 @@ <h1 class="Article-title">connection配置</h1>
</header>
<div class="Article-content col-md-9"><p>在Excel模型的外键关键对象上标注ref-connection,这样生成的一对多关联属性上会生成connection标签,并自动生成对应的Connection属性。<br>例如NopAuthResource的site属性上标注ref-connection,则会自动在NopAuthSite对象的resources属性上增加connection标签。</p>
<p><img src="/knosys/project-nop-entropy/dev-guide/graphql/ref-connection.png"></p>
<p>通过元编程机制会在编译期为meta文件增加对应的Connection属性,例如resourcesConnection。在_dump目录下可以看到最后生成的属性定义</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><code class="hljs xml"><br><span class="hljs-tag">&lt;<span class="hljs-name">meta</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;resources&quot;</span> <span class="hljs-attr">displayName</span>=<span class="hljs-string">&quot;资源列表&quot;</span> <span class="hljs-attr">i18n-en:displayName</span>=<span class="hljs-string">&quot;Resources&quot;</span> <span class="hljs-attr">tagSet</span>=<span class="hljs-string">&quot;pub,connection&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">ext:kind</span>=<span class="hljs-string">&quot;to-many&quot;</span> <span class="hljs-attr">internal</span>=<span class="hljs-string">&quot;true&quot;</span> <span class="hljs-attr">ext:joinLeftProp</span>=<span class="hljs-string">&quot;siteId&quot;</span> <span class="hljs-attr">ext:joinRightProp</span>=<span class="hljs-string">&quot;siteId&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">ext:joinRightDisplayProp</span>=<span class="hljs-string">&quot;displayName&quot;</span> <span class="hljs-attr">insertable</span>=<span class="hljs-string">&quot;false&quot;</span> <span class="hljs-attr">updatable</span>=<span class="hljs-string">&quot;false&quot;</span> <span class="hljs-attr">lazy</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">schema</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;io.nop.orm.IOrmEntitySet<span class="hljs-symbol">&amp;lt;</span>io.nop.auth.dao.entity.NopAuthResource<span class="hljs-symbol">&amp;gt;</span>&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">bizObjName</span>=<span class="hljs-string">&quot;NopAuthResource&quot;</span>/&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span><br> <span class="hljs-comment">&lt;!--LOC:[90:22:0:0]/nop/core/xlib/biz-gen.xlib#/_delta/default/nop/auth/model/NopAuthSite/NopAuthSite.xmeta--&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;resourcesConnection&quot;</span> <span class="hljs-attr">displayName</span>=<span class="hljs-string">&quot;资源列表&quot;</span> <span class="hljs-attr">internal</span>=<span class="hljs-string">&quot;true&quot;</span> <span class="hljs-attr">graphql:connectionProp</span>=<span class="hljs-string">&quot;resources&quot;</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">graphql:inputType</span>&gt;</span>io.nop.api.core.beans.graphql.GraphQLConnectionInput<span class="hljs-tag">&lt;/<span class="hljs-name">graphql:inputType</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">schema</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;io.nop.api.core.beans.graphql.GraphQLConnection<span class="hljs-symbol">&amp;lt;</span>io.nop.auth.dao.entity.NopAuthResource<span class="hljs-symbol">&amp;gt;</span>&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">bizObjName</span>=<span class="hljs-string">&quot;NopAuthResource&quot;</span>/&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">meta</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p>通过元编程机制会在编译期为meta文件增加对应的Connection属性,例如resourcesConnection。<code>_dump</code>目录下可以看到最后生成的属性定义</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><code class="hljs xml"><br><span class="hljs-tag">&lt;<span class="hljs-name">meta</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;resources&quot;</span> <span class="hljs-attr">displayName</span>=<span class="hljs-string">&quot;资源列表&quot;</span> <span class="hljs-attr">i18n-en:displayName</span>=<span class="hljs-string">&quot;Resources&quot;</span> <span class="hljs-attr">tagSet</span>=<span class="hljs-string">&quot;pub,connection&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">ext:kind</span>=<span class="hljs-string">&quot;to-many&quot;</span> <span class="hljs-attr">internal</span>=<span class="hljs-string">&quot;true&quot;</span> <span class="hljs-attr">ext:joinLeftProp</span>=<span class="hljs-string">&quot;siteId&quot;</span> <span class="hljs-attr">ext:joinRightProp</span>=<span class="hljs-string">&quot;siteId&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">ext:joinRightDisplayProp</span>=<span class="hljs-string">&quot;displayName&quot;</span> <span class="hljs-attr">insertable</span>=<span class="hljs-string">&quot;false&quot;</span> <span class="hljs-attr">updatable</span>=<span class="hljs-string">&quot;false&quot;</span> <span class="hljs-attr">lazy</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">schema</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;io.nop.orm.IOrmEntitySet<span class="hljs-symbol">&amp;lt;</span>io.nop.auth.dao.entity.NopAuthResource<span class="hljs-symbol">&amp;gt;</span>&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">bizObjName</span>=<span class="hljs-string">&quot;NopAuthResource&quot;</span>/&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span><br> <span class="hljs-comment">&lt;!--LOC:[90:22:0:0]/nop/core/xlib/biz-gen.xlib#/_delta/default/nop/auth/model/NopAuthSite/NopAuthSite.xmeta--&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;resourcesConnection&quot;</span> <span class="hljs-attr">displayName</span>=<span class="hljs-string">&quot;资源列表&quot;</span> <span class="hljs-attr">internal</span>=<span class="hljs-string">&quot;true&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">graphql:connectionProp</span>=<span class="hljs-string">&quot;resources&quot;</span> <span class="hljs-attr">graphql:queryMethod</span>=<span class="hljs-string">&quot;findConnection&quot;</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">schema</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;io.nop.api.core.beans.graphql.GraphQLConnection<span class="hljs-symbol">&amp;lt;</span>io.nop.auth.dao.entity.NopAuthResource<span class="hljs-symbol">&amp;gt;</span>&quot;</span></span><br><span class="hljs-tag"> <span class="hljs-attr">bizObjName</span>=<span class="hljs-string">&quot;NopAuthResource&quot;</span>/&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">meta</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>生成的resourcesConnection节点上通过graphql:connectionProp属性引用实体上的一个一对多关联属性,会自动使用这个关联属性对应的关联条件进行过滤。</p>
<p>具体测试用例可以参见 TestConnectionProp</p>
<p>resourcesConnection可以接收的参数为GraphQLConnectionInput类型</p>
<figure class="highlight java"><table><tr><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">GraphQLConnectionInput</span> &#123;<br> <span class="hljs-comment">/**</span><br><span class="hljs-comment"> * first表示从afterCursor开始向后取n条数据</span><br><span class="hljs-comment"> */</span><br> <span class="hljs-type">int</span> first;<br> <span class="hljs-type">int</span> last;<br> String after;<br> String before;<br><br> <span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 如果没有设置cursor,则也可以使用offset/limit机制进行分页</span><br><span class="hljs-comment"> */</span><br> <span class="hljs-type">long</span> offset;<br> TreeBean filter;<br> List&lt;OrderFieldBean&gt; orderBy;<br>&#125; <br></code></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">GraphQLConnectionInput</span> &#123;<br> <span class="hljs-comment">/**</span><br><span class="hljs-comment"> * first表示从afterCursor开始向后取n条数据</span><br><span class="hljs-comment"> */</span><br> <span class="hljs-type">int</span> first;<br> <span class="hljs-type">int</span> last;<br> String after;<br> String before;<br><br> <span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 如果没有设置cursor,则也可以使用offset/limit机制进行分页</span><br><span class="hljs-comment"> */</span><br> <span class="hljs-type">long</span> offset;<br> TreeBean filter;<br> List&lt;OrderFieldBean&gt; orderBy;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>返回的结果类型为GraphQLConnection类型</p>
<figure class="highlight java"><table><tr><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">class</span> <span class="hljs-title class_">GraphQLConnection</span>&lt;T&gt; &#123;<br><br> <span class="hljs-type">long</span> total;<br> List&lt;GraphQLEdgeBean&gt; edges;<br><br> List&lt;T&gt; items;<br><br> GraphQLPageInfo pageInfo;<br>&#125;<br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">GraphQLPageInfo</span> &#123;<br> String startCursor;<br> String endCursor;<br> Boolean hasNextPage;<br> Boolean hasPreviousPage;<br>&#125;<br></code></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">class</span> <span class="hljs-title class_">GraphQLConnection</span>&lt;T&gt; &#123;<br><br> <span class="hljs-type">long</span> total;<br> List&lt;GraphQLEdgeBean&gt; edges;<br><br> List&lt;T&gt; items;<br><br> GraphQLPageInfo pageInfo;<br>&#125;<br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">GraphQLPageInfo</span> &#123;<br> String startCursor;<br> String endCursor;<br> Boolean hasNextPage;<br> Boolean hasPreviousPage;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="对同一个子表应用不同的查询条件返回多个子集合"><a href="#对同一个子表应用不同的查询条件返回多个子集合" class="headerlink" title="对同一个子表应用不同的查询条件返回多个子集合"></a>对同一个子表应用不同的查询条件返回多个子集合</h2><figure class="highlight plaintext"><table><tr><td class="code"><pre><code class="hljs graphql">query($filter1:Map, $filter2:Map)&#123;<br> MyObject__get(id:3)&#123;<br> activeRecords: mySubObjectConnection(filter:$filter1,limit:5)&#123;<br> total<br> items&#123;<br> id<br> &#125;<br> &#125;,<br><br> inactiveRecords: mySubObjectConnection(filter:$filter2, limit:5)&#123;<br> total<br> items&#123;<br> id<br> &#125;<br> &#125;<br> &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>这里的filter1和filter2是两个不同的查询条件,可以在前端传入不同的查询条件,都是查询同一个子表对象<code>mySubObject</code>,但是返回的结果是不同的。</p>
<h2 id="REST请求时通过-subArgs简化传参方式"><a href="#REST请求时通过-subArgs简化传参方式" class="headerlink" title="REST请求时通过_subArgs简化传参方式"></a>REST请求时通过<code>_subArgs</code>简化传参方式</h2><figure class="highlight plaintext"><table><tr><td class="code"><pre><code class="hljs plaintext">/r/MyObject__get?id=3&amp;@selection=activeRecords:mySubObjectConnection,inactiveRecords:mySubObjectConnection<br><br>&#123;<br> &quot;_subArgs.activeRecords.limit&quot;: 5,<br> &quot;_subArgs.activeRecords.filter_status&quot;: 1,<br> &quot;_subArgs.inactiveRecords.limit&quot;: 5,<br> &quot;_subArgs.inactiveRecords.filter_status&quot;: 0<br>&#125;<br></code></pre></td></tr></table></figure>

<p>后台GraphQLWebService接收到<code>_subArgs.</code>为前缀的参数之后会把它们转换为针对子属性的函数参数,并识别<code>filter_</code>前缀,将特殊前缀的变量收集在一起,转换为FilterBean对象。</p>

</div>
<footer class="Article-footer col-md-3">

Expand Down

0 comments on commit b0c1d98

Please sign in to comment.