Heim > Fragen und Antworten > Hauptteil
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}]
P粉8055354342024-01-11 11:00:12
查询并不相同,但假设您知道,您的 PHP 示例也存在语法问题。
query dMsAgencies($agencyAcronym: String) { agencyAcronym fullCapaReview { id } }
如果将此与 docs 中的示例(使用变量时)进行比较,您会发现可以看到您当前没有在任何地方使用 $agencyAcronym
变量(并且您的架构中可能没有名为 agencyAcronym
的查询)。这是一个示例(使用第一个代码片段中的查询):
query dMsAgencies($agencyAcronym: String) { fullCapaReview (id: $agencyAcronym) { proposedRuleName submissionDate agencyContactName statusLawDept } }