Ich stelle die folgende Curl-Anfrage an GraphQL. Es funktioniert gut, ist aber in der Produktion shell_exex
nicht erlaubt. Wie kann ich diesen Curl-Beitrag in gültigem PHP umschreiben?
$curl_string = 'curl -g -X POST -H "Content-Type: application/json" -H "Authorization: Bearer "' . AIRTABLE_API_KEY; $curl_second_string = ' -d \'{"query": "{fullCapaReview (id: \"' . $id . '\") {proposedRuleName submissionDate agencyContactName statusLawDept}}"}\' https://api.baseql.com/airtable/graphql/appXXXzzzzzzzzzz'; $curl_complete_string = "$curl_string $curl_second_string"; $result = shell_exec($curl_complete_string);
Bearbeiten: Entschuldigung, ich habe die falsche Suchanfrage eingegeben. Die Frage, die mir in den Sinn kommt, ist:
' -d '{"query": "{dMsAggency (agencyAcronym: "' . $_agency . '") {agencyAcronym fullCapaReview { id }}}"}'
Ich habe zwei ?hnliche Anrufe get?tigt. Ich lasse das Original dabei, da jemand entsprechend antwortet.
Das habe ich bisher:
$curl = curl_init($url); $query = 'query dMsAgencies($agencyAcronym: String) {agencyAcronym fullCapaReview { id }} '; $variables = ["agencyAcronym" => $id ]; curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(['query' => $query, 'variables' => $variables])); curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json','Authorization: Bearer ' . AIRTABLE_API_KEY]); $response = curl_exec($curl); curl_close($curl); console_log("Response : " . $response);
Dies ist die Fehlermeldung, die ich erhalten habe. Ich m?chte nur sehen, ob meine Syntax den Anforderungen entspricht.
Response : {"errors":[{"message":"Cannot query field \"agencyAcronym\" on type \"Query\".","locations":[{"line":1,"column":44}],"stack":["GraphQLError: Cannot query field \"agencyAcronym\" on type \"Query\"."," at Object.Field (/var/app/current/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:46:31)"," at Object.enter (/var/app/current/node_modules/graphql/language/visitor.js:323:29)"," at Object.enter (/var/app/current/node_modules/graphql/utilities/TypeInfo.js:370:25)"," at visit (/var/app/current/node_modules/graphql/language/visitor.js:243:26)"," at validate (/var/app/current/node_modules/graphql/validation/validate.js:69:24)"," at graphqlMiddleware (/var/app/current/node_modules/express-graphql/index.js:133:32)"," at processTicksAndRejections (internal/process/task_queues.js:95:5)"]},{"message":"Variable \"$agencyAcronym\" is never used in operation \"dMsAgencies\".","locations":[{"line":1,"column":19}],"stack":["GraphQLError: Variable \"$agencyAcronym\" is never used in operation \"dMsAgencies\"."," at Object.leave (/var/app/current/node_modules/graphql/validation/rules/NoUnusedVariablesRule.js:38:33)"," at Object.leave (/var/app/current/node_modules/graphql/language/visitor.js:344:29)"," at Object.leave (/var/app/current/node_modules/graphql/utilities/TypeInfo.js:390:21)"," at visit (/var/app/current/node_modules/graphql/language/visitor.js:243:26)"," at validate (/var/app/current/node_modules/graphql/validation/validate.js:69:24)"," at graphqlMiddleware (/var/app/current/node_modules/express-graphql/index.js:133:32)"," at processTicksAndRejections (internal/process/task_queues.js:95:5)"]}]}
message":"無法在類型"Query"
Suchen Sie im Feld ?AgenturAkronym“
{"message":"變量 "$agencyAcronym" 從未在操作 "dMsAggency" 中使用。","locations":[{"line":1,"column":19}]
查詢并不相同,但假設(shè)您知道,您的 PHP 示例也存在語法問題。
query dMsAgencies($agencyAcronym: String) { agencyAcronym fullCapaReview { id } }
如果將此與 docs 中的示例(使用變量時)進行比較,您會發(fā)現(xiàn)可以看到您當(dāng)前沒有在任何地方使用 $agencyAcronym
變量(并且您的架構(gòu)中可能沒有名為 agencyAcronym
的查詢)。這是一個示例(使用第一個代碼片段中的查詢):
query dMsAgencies($agencyAcronym: String) { fullCapaReview (id: $agencyAcronym) { proposedRuleName submissionDate agencyContactName statusLawDept } }