Rumah > Soal Jawab > teks badan
Saya membuat permintaan curl berikut kepada GraphQL. Ia berfungsi dengan baik, tetapi dalam pengeluaran shell_exex
tidak dibenarkan. Bagaimanakah saya boleh menulis semula siaran curl ini dalam PHP yang sah?
$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);
Sunting: Maaf, saya salah memasukkan pertanyaan. Pertanyaan yang terlintas di fikiran ialah:
' -d '{"query": "{dMsAggency (agencyAcronym: "' . $_agency . '") {agencyAcronym fullCapaReview { id }}}"}'
Saya membuat dua panggilan yang serupa. Saya akan meninggalkan yang asal di sana kerana seseorang menjawab dengan sewajarnya.
Ini yang saya ada setakat ini:
$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);
Ini ialah mesej ralat yang saya terima. Saya hanya mahu melihat sama ada sintaks saya sudah habis.
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"
Cari medan "Akronim agensi"
{"message":"变量 "$agencyAcronym" 从未在操作 "dMsAggency" 中使用。","locations":[{"line":1,"column":19}]
P粉8055354342024-01-11 11:00:12
Pertanyaan tidak sama, tetapi andaikan anda tahu, contoh PHP anda juga mempunyai isu sintaks.
query dMsAgencies($agencyAcronym: String) { agencyAcronym fullCapaReview { id } }
Jika anda membandingkan ini dengan contoh dalam docs (apabila menggunakan pembolehubah) anda akan mendapati bahawa anda boleh melihat bahawa anda sedang tidak menggunakan $agencyAcronym
变量(并且您的架构中可能没有名为 agencyAcronym
di mana-mana dalam pertanyaan). Berikut ialah contoh (menggunakan pertanyaan daripada coretan pertama):
query dMsAgencies($agencyAcronym: String) { fullCapaReview (id: $agencyAcronym) { proposedRuleName submissionDate agencyContactName statusLawDept } }