Migrating from REST to GraphQL; api response is always a 1 - Is my query format wrong? PLEASE HELP!

Hi,
I am starting to migrate my Shoppify app from REST to graphgl.
I have followed the documentation and tried many variations on this code, but I always get back ‘1’

I am using php code with a raw CURL call.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $baseUrl,
CURLOPT_POSTFIELDS => $postFields,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => TRUE,
CURLOPT_HTTPHEADER => array(
‘Content-Type: application/json’,
‘X-Shopify-Access-Token:’ . $apiKey,
),
));

        $response = curl_exec($curl);

where the base url is

https://my-store.myshopify.com/admin/api/2025-01/graphgl.json

$postfields is;
$query = <<<QUERY
query GetProducts {products(first: 10) {nodes{id title}}}
QUERY;
then;
$postFields = array(
‘query’ => $query
);
I have tried this as string, with new lines, json encoded, not encoded etc etc.

Has anyone any Idea whats going on here?
If I use a made up url, I get not found error. So it is connecting.
The $apiKey (The token) appears to be valid as again if I put random data in it errors.
I am using POST as that is what the documentation says to use, even though this is only a GET.

I have been reading other posts, no one is getting this issue but I am thinking is my query wrong ?

So I have tried this one from another post;
$query = <<<QUERY
query { customers(first:1, query: “country:canada”) { edges { node { id displayName firstName lastName } } }}
QUERY;

still get a 1 as the response.

I have found another example of getting the first teo products, slightly different query;
$query = <<<QUERY
query {products(first:10) {edges {nodes {id title}}}}
QUERY;

But again, returns a 1

Hi Jason,

If you try the query in isolation on the GraphiQL app, is it working as expected? That would help you identify if it’s an issue with the query or the context that the query is contained within.

Thanks Liam, I have installed that and the query works !
Yet still I get a 1 back when I run it via a php curl call.

I found the problem, it was a typo all along.
I have the URL ending in
graphgl.json

when it is graphql.json

argghh !!! 5 hours of madness.

No problem Jason - just glad it’s working for you now.

You can keep using the GraphiQL app to test and also the .dev AI assistant in the docs which is trained for helping with migration to GraphQL.