AlinsRan commented on code in PR #13840:
URL: https://github.com/apache/apisix/pull/13840#discussion_r3819307379


##########
apisix/control/v1.lua:
##########
@@ -19,7 +19,8 @@ local core = require("apisix.core")
 local plugin = require("apisix.plugin")
 local get_routes = require("apisix.router").http_routes
 local get_stream_routes = require("apisix.router").stream_routes
-local get_services = require("apisix.http.service").services
+local get_service_mod = require("apisix.http.service")
+local get_services = get_service_mod.services

Review Comment:
   Not reachable, so I have left the lookup alone. A decoration's runtime 
`value.id` is not its own id: `config_etcd` overwrites it with the key relative 
to the prefix, so it reads `aaa-owner/graphql_cost_decorations/hc-svc` -- 
verified by instrumenting the loop. A Service id cannot contain a slash 
(`id_schema` is `^[a-zA-Z0-9-_.]+$`), so no decoration can ever match one here.
   
   I did add the filter first, then reverted it: a guard against something that 
cannot happen, carrying a comment saying it can, is worse than none. There is a 
regression pinning the invariant instead, since it rests on how `config_etcd` 
derives the id rather than on anything local to this function.



##########
apisix/plugins/graphql-limit-count/introspection.lua:
##########
@@ -0,0 +1,409 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+--
+-- Upstream GraphQL schema introspection.
+--
+-- Cost decorations are addressed by GraphQL type name, while a query AST only
+-- carries field names, so the schema is required to tell `Person.name` from
+-- `Vehicle.name`. The schema is fetched lazily on the first request that 
needs it
+-- and then kept for the lifetime of the worker; there is no knob for the TTL, 
so a
+-- schema change on a live upstream needs a reload.
+--
+local core        = require("apisix.core")
+local http        = require("resty.http")
+local resty_lock  = require("resty.lock")
+local upstream    = require("apisix.upstream")
+local service_fetch = require("apisix.http.service").get
+
+local ipairs   = ipairs
+local pairs    = pairs
+local type     = type
+local str_find = string.find
+local tab_sort = table.sort
+local tostring = tostring
+local ngx_now  = ngx.now
+
+local LOCK_SHDICT_NAME = "lrucache-lock"
+
+-- milliseconds; see the comment in fetch_schema
+local INTROSPECTION_CONNECT_TIMEOUT = 2000
+local INTROSPECTION_SEND_TIMEOUT    = 2000
+local INTROSPECTION_READ_TIMEOUT    = 5000
+-- seconds a failed introspection is remembered, so an upstream that answers
+-- nothing does not get one request per client request
+local INTROSPECTION_FAILURE_TTL     = 10
+
+-- Trimmed to what the cost engine consumes: the root type names 
(`field_path`'s
+-- first segment is matched against them), each type's fields and their result
+-- types, and the argument default values used by `resolve_variables`.
+local INTROSPECTION_QUERY = [[
+fragment TypeAttr on __Type {
+    kind
+    name
+}
+
+fragment WrappedTypeRef on __Type {
+    ...TypeAttr
+    ofType { ...TypeAttr
+      ofType { ...TypeAttr
+        ofType { ...TypeAttr
+          ofType { ...TypeAttr } } } }
+}
+
+query {
+    __schema {
+        queryType { name }
+        mutationType { name }

Review Comment:
   Not reachable with the current parser. The `graphql` 0.0.2 grammar has no 
`subscription` production, so such a document fails `parse` and the plugin 
answers 400 before the cost engine is entered -- the parse gaps are listed in 
the description. Adding `subscriptionType` to the index and selecting it in 
`root_type` would be dead code until the parser gains it, so I would rather add 
both together.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to